Remove unnecessary CraftBlock creation in CraftRegionAccessor#setBlock

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2021-11-24 08:16:10 +11:00
parent 2a6e33ffed
commit f3b1f97464
2 changed files with 10 additions and 3 deletions

View file

@ -272,7 +272,11 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
@Override
public void setBlockData(int x, int y, int z, BlockData blockData) {
CraftBlock.at(getHandle(), new BlockPosition(x, y, z)).setTypeAndData(((CraftBlockData) blockData).getState(), true);
GeneratorAccessSeed world = getHandle();
BlockPosition pos = new BlockPosition(x, y, z);
IBlockData old = getHandle().getBlockState(pos);
CraftBlock.setTypeAndData(world, pos, old, ((CraftBlockData) blockData).getState(), true);
}
@Override

View file

@ -185,8 +185,11 @@ public class CraftBlock implements Block {
setTypeAndData(((CraftBlockData) data).getState(), applyPhysics);
}
public boolean setTypeAndData(final IBlockData blockData, final boolean applyPhysics) {
IBlockData old = getNMS();
boolean setTypeAndData(final IBlockData blockData, final boolean applyPhysics) {
return setTypeAndData(world, position, getNMS(), blockData, applyPhysics);
}
public static boolean setTypeAndData(GeneratorAccess world, BlockPosition position, IBlockData old, IBlockData blockData, boolean applyPhysics) {
// SPIGOT-611: need to do this to prevent glitchiness. Easier to handle this here (like /setblock) than to fix weirdness in tile entity cleanup
if (old.hasBlockEntity() && blockData.getBlock() != old.getBlock()) { // SPIGOT-3725 remove old tile entity if block changes
// SPIGOT-4612: faster - just clear tile