Skip to content

Commit 4533821

Browse files
Fix setSpawnedItem from 1.18 update (#7328)
1 parent 6b526f9 commit 4533821

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

patches/server/0321-Mob-Spawner-API-Enhancements.patch

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,37 +65,35 @@ index 30930a24c197c45f2ed86eaf7a150252005e7a37..c0f33a6cb4812e13204552c125df0621
6565
nbt.putShort("MaxNearbyEntities", (short) this.maxNearbyEntities);
6666
nbt.putShort("RequiredPlayerRange", (short) this.requiredPlayerRange);
6767
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java b/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
68-
index 6c427b15f78970912bae881f5aba1cfae2a4ba53..3877376619d633f48e37b6c854ae7df77ccca456 100644
68+
index 6c427b15f78970912bae881f5aba1cfae2a4ba53..0af969746b1984bd5de0510f815b54815c9322bf 100644
6969
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
7070
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
71-
@@ -116,4 +116,30 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti
71+
@@ -116,4 +116,28 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti
7272
public void setSpawnRange(int spawnRange) {
7373
this.getSnapshot().getSpawner().spawnRange = spawnRange;
7474
}
7575
+
7676
+ // Paper start
7777
+ @Override
7878
+ public boolean isActivated() {
79-
+ return this.getSnapshot().getSpawner().isNearPlayer(world.getHandle(), getPosition());
79+
+ this.requirePlaced();
80+
+ return this.getSnapshot().getSpawner().isNearPlayer(this.world.getHandle(), this.getPosition());
8081
+ }
8182
+
8283
+ @Override
8384
+ public void resetTimer() {
84-
+ this.getSnapshot().getSpawner().delay(world.getHandle(), getPosition());
85+
+ this.requirePlaced();
86+
+ this.getSnapshot().getSpawner().delay(this.world.getHandle(), this.getPosition());
8587
+ }
8688
+
8789
+ @Override
8890
+ public void setSpawnedItem(org.bukkit.inventory.ItemStack itemStack) {
8991
+ Preconditions.checkArgument(itemStack != null && !itemStack.getType().isAir(), "spawners cannot spawn air");
9092
+ net.minecraft.world.item.ItemStack item = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(itemStack);
91-
+ net.minecraft.nbt.CompoundTag compound = new net.minecraft.nbt.CompoundTag();
9293
+ net.minecraft.nbt.CompoundTag entity = new net.minecraft.nbt.CompoundTag();
9394
+ entity.putString("id", net.minecraft.core.Registry.ENTITY_TYPE.getKey(net.minecraft.world.entity.EntityType.ITEM).toString());
9495
+ entity.put("Item", item.save(new net.minecraft.nbt.CompoundTag()));
95-
+ compound.put("Entity", entity);
96-
+ compound.putInt("Weight", this.getSnapshotNBT().contains("Weight", org.bukkit.craftbukkit.util.CraftMagicNumbers.NBT.TAG_ANY_NUMBER) ? this.getSnapshotNBT().getInt("Weight") : 1);
97-
+ 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
98-
+ this.getSnapshot().getSpawner().spawnPotentials = net.minecraft.util.random.SimpleWeightedRandomList.empty(); // 1.18 todo - previously used removed field, check
96+
+ this.getSnapshot().getSpawner().setNextSpawnData(this.isPlaced() ? this.world.getHandle() : null, this.getPosition(), new net.minecraft.world.level.SpawnData(entity, java.util.Optional.empty()));
9997
+ }
10098
+ // Paper end
10199
}

0 commit comments

Comments
 (0)