diff options
Diffstat (limited to 'patches/server/0289-Mob-Spawner-API-Enhancements.patch')
-rw-r--r-- | patches/server/0289-Mob-Spawner-API-Enhancements.patch | 144 |
1 files changed, 126 insertions, 18 deletions
diff --git a/patches/server/0289-Mob-Spawner-API-Enhancements.patch b/patches/server/0289-Mob-Spawner-API-Enhancements.patch index dc419af692..9f35b91c5a 100644 --- a/patches/server/0289-Mob-Spawner-API-Enhancements.patch +++ b/patches/server/0289-Mob-Spawner-API-Enhancements.patch @@ -69,43 +69,151 @@ index 1d0964a7f544735a0213d5c7832c71f53db139a9..b90127f9f805fdb5bb43a4b8ad2b1049 nbt.putShort("MaxNearbyEntities", (short) this.maxNearbyEntities); nbt.putShort("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 -index 33718f8861b46452ef9977ac0cbd7624a86edb30..4659f11c3aadda2617951f9d98b4858efe1400d7 100644 +index 9b2b6697d0b64da2bc99dc646f552c2689d5a1fc..146dde200845abcbe11015dda2c826a1aa711e42 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java -@@ -256,4 +256,36 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti +@@ -29,7 +29,7 @@ import org.bukkit.craftbukkit.entity.CraftEntityType; + import org.bukkit.entity.EntitySnapshot; + import org.bukkit.entity.EntityType; + +-public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEntity> implements CreatureSpawner { ++public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEntity> implements CreatureSpawner, org.bukkit.craftbukkit.spawner.PaperSharedSpawnerLogic { // Paper - more spawner API + + public CraftCreatureSpawner(World world, SpawnerBlockEntity tileEntity) { + super(world, tileEntity); +@@ -291,4 +291,38 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti new HashMap<>(nms.slotDropChances().entrySet().stream().collect(Collectors.toMap((entry) -> CraftEquipmentSlot.getSlot(entry.getKey()), Map.Entry::getValue))) )).orElse(null); } + -+ // Paper start ++ // Paper start - more spawner API + @Override + public boolean isActivated() { -+ this.requirePlaced(); -+ return this.getSnapshot().getSpawner().isNearPlayer(this.world.getHandle(), this.getPosition()); ++ requirePlaced(); ++ return org.bukkit.craftbukkit.spawner.PaperSharedSpawnerLogic.super.isActivated(); + } + + @Override + public void resetTimer() { -+ this.requirePlaced(); -+ this.getSnapshot().getSpawner().delay(this.world.getHandle(), this.getPosition()); ++ requirePlaced(); ++ org.bukkit.craftbukkit.spawner.PaperSharedSpawnerLogic.super.resetTimer(); ++ } ++ ++ @Override ++ public void setNextSpawnData(final SpawnData spawnData) { ++ this.getSpawner().setNextSpawnData(this.isPlaced() ? this.getInternalWorld() : null, this.getInternalPosition(), spawnData); ++ } ++ ++ @Override ++ public BaseSpawner getSpawner() { ++ return this.getSnapshot().getSpawner(); ++ } ++ ++ @Override ++ public net.minecraft.core.BlockPos getInternalPosition() { ++ return this.getPosition(); ++ } ++ ++ @Override ++ public net.minecraft.world.level.Level getInternalWorld() { ++ return this.world.getHandle(); ++ } ++ // Paper end - more spawner API + } +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartMobSpawner.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartMobSpawner.java +index 72e34dbfadcebb26a0707ce095b0d270f4d1d97c..e8ece01669373ecf6552d33b2ed72668524e2650 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartMobSpawner.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartMobSpawner.java +@@ -16,7 +16,7 @@ import org.bukkit.entity.EntitySnapshot; + import org.bukkit.entity.EntityType; + import org.bukkit.entity.minecart.SpawnerMinecart; + +-final class CraftMinecartMobSpawner extends CraftMinecart implements SpawnerMinecart { ++final class CraftMinecartMobSpawner extends CraftMinecart implements SpawnerMinecart, org.bukkit.craftbukkit.spawner.PaperSharedSpawnerLogic { // Paper - more spawner API + CraftMinecartMobSpawner(CraftServer server, MinecartSpawner entity) { + super(server, entity); + } +@@ -171,4 +171,21 @@ final class CraftMinecartMobSpawner extends CraftMinecart implements SpawnerMine + public String toString() { + return "CraftMinecartMobSpawner"; + } ++ ++ // Paper start - more spawner API ++ @Override ++ public net.minecraft.world.level.BaseSpawner getSpawner() { ++ return this.getHandle().getSpawner(); + } + + @Override -+ public void setSpawnedItem(org.bukkit.inventory.ItemStack itemStack) { ++ public net.minecraft.world.level.Level getInternalWorld() { ++ return this.getHandle().level(); ++ } ++ ++ @Override ++ public net.minecraft.core.BlockPos getInternalPosition() { ++ return this.getHandle().blockPosition(); ++ } ++ // Paper end - more spawner API + } +diff --git a/src/main/java/org/bukkit/craftbukkit/spawner/PaperSharedSpawnerLogic.java b/src/main/java/org/bukkit/craftbukkit/spawner/PaperSharedSpawnerLogic.java +new file mode 100644 +index 0000000000000000000000000000000000000000..b1d08dc4c4257a6f5cd70dfdddade58ff7eedb4b +--- /dev/null ++++ b/src/main/java/org/bukkit/craftbukkit/spawner/PaperSharedSpawnerLogic.java +@@ -0,0 +1,56 @@ ++package org.bukkit.craftbukkit.spawner; ++ ++import com.google.common.base.Preconditions; ++import java.util.Optional; ++import net.minecraft.core.BlockPos; ++import net.minecraft.core.registries.BuiltInRegistries; ++import net.minecraft.nbt.CompoundTag; ++import net.minecraft.world.entity.Entity; ++import net.minecraft.world.entity.EntityType; ++import net.minecraft.world.level.BaseSpawner; ++import net.minecraft.world.level.Level; ++import net.minecraft.world.level.SpawnData; ++import org.bukkit.craftbukkit.inventory.CraftItemStack; ++import org.bukkit.inventory.ItemStack; ++import org.bukkit.spawner.Spawner; ++ ++/** ++ * A common parent interface for both the {@link org.bukkit.craftbukkit.block.CraftCreatureSpawner} and minecart mob spawner. ++ */ ++public interface PaperSharedSpawnerLogic extends Spawner { ++ ++ BaseSpawner getSpawner(); ++ ++ Level getInternalWorld(); ++ ++ BlockPos getInternalPosition(); ++ ++ default boolean isActivated() { ++ return this.getSpawner().isNearPlayer(this.getInternalWorld(), this.getInternalPosition()); ++ } ++ ++ default void resetTimer() { ++ this.getSpawner().delay(this.getInternalWorld(), this.getInternalPosition()); ++ } ++ ++ default void setNextSpawnData(SpawnData spawnData) { ++ this.getSpawner().setNextSpawnData(this.getInternalWorld(), this.getInternalPosition(), spawnData); ++ } ++ ++ default void setSpawnedItem(final ItemStack itemStack) { + Preconditions.checkArgument(itemStack != null && !itemStack.getType().isAir(), "spawners cannot spawn air"); -+ net.minecraft.world.item.ItemStack item = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(itemStack); -+ net.minecraft.nbt.CompoundTag entity = new net.minecraft.nbt.CompoundTag(); -+ entity.putString("id", net.minecraft.core.registries.BuiltInRegistries.ENTITY_TYPE.getKey(net.minecraft.world.entity.EntityType.ITEM).toString()); -+ entity.put("Item", item.save(this.world.getHandle().registryAccess())); -+ this.getSnapshot().getSpawner().setNextSpawnData( -+ this.isPlaced() ? this.world.getHandle() : null, -+ this.getPosition(), ++ ++ final net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(itemStack); ++ final CompoundTag entity = new CompoundTag(); ++ entity.putString(Entity.ID_TAG, BuiltInRegistries.ENTITY_TYPE.getKey(EntityType.ITEM).toString()); ++ entity.put("Item", item.save(this.getInternalWorld().registryAccess())); ++ ++ this.setNextSpawnData( + new net.minecraft.world.level.SpawnData( + entity, + java.util.Optional.empty(), -+ Optional.ofNullable(this.getSnapshot().getSpawner().nextSpawnData).flatMap(SpawnData::equipment) ++ Optional.ofNullable(this.getSpawner().nextSpawnData).flatMap(SpawnData::equipment) + ) + ); + } -+ // Paper end - } ++} |