Commits

md_5 authored aa69d1cfb99
Only remove tile entity if block type changes
No tags

src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java

Modified
176 176 setBlockData(data, true);
177 177 }
178 178
179 179 @Override
180 180 public void setBlockData(BlockData data, boolean applyPhysics) {
181 181 Preconditions.checkArgument(data != null, "BlockData cannot be null");
182 182 setTypeAndData(((CraftBlockData) data).getState(), applyPhysics);
183 183 }
184 184
185 185 public boolean setTypeAndData(final IBlockData blockData, final boolean applyPhysics) {
186 + IBlockData old = getNMS();
186 187 // SPIGOT-611: need to do this to prevent glitchiness. Easier to handle this here (like /setblock) than to fix weirdness in tile entity cleanup
187 - if (getNMS().isTileEntity()) { // SPIGOT-3725 always remove old tile entity
188 + if (old.isTileEntity() && blockData.getBlock() != old.getBlock()) { // SPIGOT-3725 remove old tile entity if block changes
188 189 // SPIGOT-4612: faster - just clear tile
189 190 if (world instanceof net.minecraft.world.level.World) {
190 191 ((net.minecraft.world.level.World) world).removeTileEntity(position);
191 192 } else {
192 193 world.setTypeAndData(position, Blocks.AIR.getBlockData(), 0);
193 194 }
194 195 }
195 196
196 197 if (applyPhysics) {
197 198 return world.setTypeAndData(position, blockData, 3);
198 199 } else {
199 - IBlockData old = world.getType(position);
200 200 boolean success = world.setTypeAndData(position, blockData, 2 | 16 | 1024); // NOTIFY | NO_OBSERVER | NO_PLACE (custom)
201 201 if (success) {
202 202 world.getMinecraftWorld().notify(
203 203 position,
204 204 old,
205 205 blockData,
206 206 3
207 207 );
208 208 }
209 209 return success;

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut