From a5b67c2a4a4e8f060ae0c55ea0b1c8fba8966cd7 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Tue, 18 Jan 2022 19:09:04 -0800 Subject: [PATCH] Fix setSpawnedItem from 1.18 update (#7328) --- patches/server/Mob-Spawner-API-Enhancements.patch | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/patches/server/Mob-Spawner-API-Enhancements.patch b/patches/server/Mob-Spawner-API-Enhancements.patch index d6d2c8adc8..dc9e40b772 100644 --- a/patches/server/Mob-Spawner-API-Enhancements.patch +++ b/patches/server/Mob-Spawner-API-Enhancements.patch @@ -76,26 +76,24 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start + @Override + public boolean isActivated() { -+ return this.getSnapshot().getSpawner().isNearPlayer(world.getHandle(), getPosition()); ++ this.requirePlaced(); ++ return this.getSnapshot().getSpawner().isNearPlayer(this.world.getHandle(), this.getPosition()); + } + + @Override + public void resetTimer() { -+ this.getSnapshot().getSpawner().delay(world.getHandle(), getPosition()); ++ this.requirePlaced(); ++ this.getSnapshot().getSpawner().delay(this.world.getHandle(), this.getPosition()); + } + + @Override + public void setSpawnedItem(org.bukkit.inventory.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 compound = new net.minecraft.nbt.CompoundTag(); + net.minecraft.nbt.CompoundTag entity = new net.minecraft.nbt.CompoundTag(); + entity.putString("id", net.minecraft.core.Registry.ENTITY_TYPE.getKey(net.minecraft.world.entity.EntityType.ITEM).toString()); + entity.put("Item", item.save(new net.minecraft.nbt.CompoundTag())); -+ compound.put("Entity", entity); -+ compound.putInt("Weight", this.getSnapshotNBT().contains("Weight", org.bukkit.craftbukkit.util.CraftMagicNumbers.NBT.TAG_ANY_NUMBER) ? this.getSnapshotNBT().getInt("Weight") : 1); -+ this.getSnapshot().getSpawner().setNextSpawnData(world.getHandle(), getPosition(), new net.minecraft.world.level.SpawnData(compound, java.util.Optional.empty())); // 1.18 todo - is empty optional correct -+ this.getSnapshot().getSpawner().spawnPotentials = net.minecraft.util.random.SimpleWeightedRandomList.empty(); // 1.18 todo - previously used removed field, check ++ this.getSnapshot().getSpawner().setNextSpawnData(this.isPlaced() ? this.world.getHandle() : null, this.getPosition(), new net.minecraft.world.level.SpawnData(entity, java.util.Optional.empty())); + } + // Paper end }