testserver/Spigot-Server-Patches/0345-Mob-Spawner-API-Enhanc...

141 lines
6.7 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2019-04-19 17:41:38 +00:00
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Fri, 19 Apr 2019 12:41:13 -0500
Subject: [PATCH] Mob Spawner API Enhancements
diff --git a/src/main/java/net/minecraft/world/level/MobSpawnerAbstract.java b/src/main/java/net/minecraft/world/level/MobSpawnerAbstract.java
2021-03-16 15:50:45 +00:00
index 34bcee4ff55ba118ba393e94b3c25ee2b84feaa2..5538404456dfee42257fad9040fcc0fefdfc5fab 100644
--- a/src/main/java/net/minecraft/world/level/MobSpawnerAbstract.java
+++ b/src/main/java/net/minecraft/world/level/MobSpawnerAbstract.java
2021-03-16 15:50:45 +00:00
@@ -65,6 +65,7 @@ public abstract class MobSpawnerAbstract {
2019-04-19 17:41:38 +00:00
this.mobs.clear(); // CraftBukkit - SPIGOT-3496, MC-92282
}
+ public boolean isActivated() { return h(); } // Paper - OBFHELPER
private boolean h() {
BlockPosition blockposition = this.b();
2021-03-16 15:50:45 +00:00
@@ -221,6 +222,7 @@ public abstract class MobSpawnerAbstract {
2019-04-19 17:41:38 +00:00
}
}
+ public void resetTimer() { i(); } // Paper - OBFHELPER
private void i() {
if (this.maxSpawnDelay <= this.minSpawnDelay) {
this.spawnDelay = this.minSpawnDelay;
2021-03-16 15:50:45 +00:00
@@ -238,7 +240,13 @@ public abstract class MobSpawnerAbstract {
2019-04-19 17:41:38 +00:00
}
public void a(NBTTagCompound nbttagcompound) {
+ // Paper start - use larger int if set
+ if (nbttagcompound.hasKey("Paper.Delay")) {
+ this.spawnDelay = nbttagcompound.getInt("Paper.Delay");
+ } else {
this.spawnDelay = nbttagcompound.getShort("Delay");
+ }
+ // Paper end
2019-04-19 17:41:38 +00:00
this.mobs.clear();
if (nbttagcompound.hasKeyOfType("SpawnPotentials", 9)) {
NBTTagList nbttaglist = nbttagcompound.getList("SpawnPotentials", 10);
2021-03-16 15:50:45 +00:00
@@ -253,10 +261,15 @@ public abstract class MobSpawnerAbstract {
} else if (!this.mobs.isEmpty()) {
2019-05-14 02:20:58 +00:00
this.setSpawnData((MobSpawnerData) WeightedRandom.a(this.a().random, this.mobs));
2019-04-19 17:41:38 +00:00
}
-
+ // Paper start - use ints if set
+ if (nbttagcompound.hasKeyOfType("Paper.MinSpawnDelay", 99)) {
+ this.minSpawnDelay = nbttagcompound.getInt("Paper.MinSpawnDelay");
+ this.maxSpawnDelay = nbttagcompound.getInt("Paper.MaxSpawnDelay");
+ this.spawnCount = nbttagcompound.getShort("SpawnCount");
+ } else // Paper end
2019-04-19 17:41:38 +00:00
if (nbttagcompound.hasKeyOfType("MinSpawnDelay", 99)) {
- this.minSpawnDelay = nbttagcompound.getShort("MinSpawnDelay");
- this.maxSpawnDelay = nbttagcompound.getShort("MaxSpawnDelay");
+ this.minSpawnDelay = nbttagcompound.getInt("MinSpawnDelay");
+ this.maxSpawnDelay = nbttagcompound.getInt("MaxSpawnDelay");
2019-04-19 17:41:38 +00:00
this.spawnCount = nbttagcompound.getShort("SpawnCount");
}
2021-03-16 15:50:45 +00:00
@@ -281,9 +294,20 @@ public abstract class MobSpawnerAbstract {
2019-04-19 17:41:38 +00:00
if (minecraftkey == null) {
return nbttagcompound;
} else {
- nbttagcompound.setShort("Delay", (short) this.spawnDelay);
- nbttagcompound.setShort("MinSpawnDelay", (short) this.minSpawnDelay);
- nbttagcompound.setShort("MaxSpawnDelay", (short) this.maxSpawnDelay);
+ // Paper start
+ if (spawnDelay > Short.MAX_VALUE) {
+ nbttagcompound.setInt("Paper.Delay", this.spawnDelay);
+ }
2019-04-19 17:41:38 +00:00
+ nbttagcompound.setShort("Delay", (short) Math.min(Short.MAX_VALUE, this.spawnDelay));
+
+ if (minSpawnDelay > Short.MAX_VALUE || maxSpawnDelay > Short.MAX_VALUE) {
+ nbttagcompound.setInt("Paper.MinSpawnDelay", this.minSpawnDelay);
+ nbttagcompound.setInt("Paper.MaxSpawnDelay", this.maxSpawnDelay);
+ }
+
2019-04-19 17:41:38 +00:00
+ nbttagcompound.setShort("MinSpawnDelay", (short) Math.min(Short.MAX_VALUE, this.minSpawnDelay));
+ nbttagcompound.setShort("MaxSpawnDelay", (short) Math.min(Short.MAX_VALUE, this.maxSpawnDelay));
+ // Paper end
nbttagcompound.setShort("SpawnCount", (short) this.spawnCount);
nbttagcompound.setShort("MaxNearbyEntities", (short) this.maxNearbyEntities);
nbttagcompound.setShort("RequiredPlayerRange", (short) this.requiredPlayerRange);
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java b/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
2021-03-16 13:04:28 +00:00
index 28295ebd338806a35cbef164cb014abfe7dae769..3d29be926e36b9a5a981eea1f2a1ec54a4c43393 100644
2019-04-19 17:41:38 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
2021-03-16 13:04:28 +00:00
@@ -1,13 +1,21 @@
package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
+import net.minecraft.core.IRegistry;
+import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.world.entity.EntityTypes;
+import net.minecraft.world.level.MobSpawnerData;
import net.minecraft.world.level.block.entity.TileEntityMobSpawner;
import org.bukkit.Material;
2020-11-14 18:11:20 +00:00
import org.bukkit.block.Block;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.entity.EntityType;
+// Paper start
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
+import org.bukkit.inventory.ItemStack;
+// Paper end
public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpawner> implements CreatureSpawner {
@@ -121,4 +129,30 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
2019-04-19 17:41:38 +00:00
public void setSpawnRange(int spawnRange) {
this.getSnapshot().getSpawner().spawnRange = spawnRange;
}
+
+ // Paper start
+ @Override
+ public boolean isActivated() {
+ return this.getSnapshot().getSpawner().isActivated();
+ }
+
+ @Override
+ public void resetTimer() {
+ this.getSnapshot().getSpawner().resetTimer();
+ }
2020-11-14 18:11:20 +00:00
+
+ @Override
+ public void setSpawnedItem(ItemStack itemStack) {
+ Preconditions.checkArgument(itemStack != null && !itemStack.getType().isAir(), "spawners cannot spawn air");
2021-03-16 13:04:28 +00:00
+ net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(itemStack);
2020-11-14 18:11:20 +00:00
+ NBTTagCompound compound = new NBTTagCompound();
+ NBTTagCompound entity = new NBTTagCompound();
+ entity.setString("id", IRegistry.ENTITY_TYPE.getKey(EntityTypes.ITEM).toString());
+ entity.set("Item", item.save(new NBTTagCompound()));
+ compound.set("Entity", entity);
+ compound.setInt("Weight", this.getSnapshotNBT().hasKeyOfType("Weight", CraftMagicNumbers.NBT.TAG_ANY_NUMBER) ? this.getSnapshotNBT().getInt("Weight") : 1);
+ this.getSnapshot().getSpawner().setSpawnData(new MobSpawnerData(compound));
+ this.getSnapshot().getSpawner().mobs.clear();
+ }
2019-04-19 17:41:38 +00:00
+ // Paper end
}