From 144215c813bfe776877edf965e9561505b120340 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 6 Apr 2019 01:12:57 +1100 Subject: [PATCH] Don't construct new BaseBlock --- .../fawe/object/clipboard/DiskOptimizedClipboard.java | 6 ++---- .../com/boydti/fawe/object/pattern/IdDataMaskPattern.java | 1 - .../com/boydti/fawe/object/pattern/PropertyPattern.java | 2 +- .../com/boydti/fawe/object/schematic/StructureFormat.java | 2 +- .../src/main/java/com/boydti/fawe/wrappers/FakePlayer.java | 2 +- .../src/main/java/com/sk89q/worldedit/CuboidClipboard.java | 2 +- .../extension/factory/parser/DefaultBlockParser.java | 2 +- .../sk89q/worldedit/internal/command/WorldEditBinding.java | 4 ++-- .../com/sk89q/worldedit/internal/cui/ServerCUIHandler.java | 2 +- .../java/com/sk89q/worldedit/world/block/BaseBlock.java | 6 +++--- .../java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java | 2 +- .../com/sk89q/worldedit/world/registry/LegacyMapper.java | 2 +- 12 files changed, 15 insertions(+), 18 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index 72fc58050..86152947d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -379,8 +379,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { trio.set(x, y, z); CompoundTag nbt = nbtMap.get(trio); if (nbt != null) { - BaseBlock block = new BaseBlock(state, nbt); - task.run(x, y, z, block); + task.run(x, y, z, state.toBaseBlock(nbt)); continue; } } @@ -411,8 +410,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { trio.set(x, y, z); CompoundTag nbt = nbtMap.get(trio); if (nbt != null) { - BaseBlock block = new BaseBlock(state, nbt); - task.run(x, y, z, block); + task.run(x, y, z, state.toBaseBlock(nbt)); continue; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdDataMaskPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdDataMaskPattern.java index 2ad33fe3a..65a15f1c7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdDataMaskPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdDataMaskPattern.java @@ -12,7 +12,6 @@ import com.sk89q.worldedit.world.block.BlockTypes; public class IdDataMaskPattern extends AbstractExtentPattern { private final Pattern pattern; private final int bitMask; - private final BaseBlock mutable = new BaseBlock(BlockTypes.AIR); public IdDataMaskPattern(Extent extent, Pattern parent, int bitMask) { super(extent); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PropertyPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PropertyPattern.java index 9c603fa71..2533017a2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PropertyPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PropertyPattern.java @@ -205,7 +205,7 @@ public class PropertyPattern extends AbstractExtentPattern { if (newOrdinal != ordinal) { CompoundTag nbt = block.getNbtData(); BlockState newState = BlockState.getFromOrdinal(newOrdinal); - return nbt != null ? new BaseBlock(newState, nbt) : newState.toBaseBlock(); + return newState.toBaseBlock(nbt); } return orDefault; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/StructureFormat.java b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/StructureFormat.java index 120327d3f..89838bad3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/StructureFormat.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/StructureFormat.java @@ -122,7 +122,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter { if (state.getBlockType().getMaterial().hasContainer()) { CompoundTag nbt = (CompoundTag) blockMap.get("nbt"); if (nbt != null) { - BaseBlock block = new BaseBlock(state, nbt); + BaseBlock block = state.toBaseBlock(nbt); clipboard.setBlock(x, y, z, block); continue; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/wrappers/FakePlayer.java b/worldedit-core/src/main/java/com/boydti/fawe/wrappers/FakePlayer.java index 44ba6cc34..980409b0a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/wrappers/FakePlayer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/wrappers/FakePlayer.java @@ -153,7 +153,7 @@ public class FakePlayer extends AbstractPlayerActor { @Override public BaseBlock getBlockInHand(HandSide ignore) { - return new BaseBlock(BlockTypes.AIR.getDefaultState()); + return BlockTypes.AIR.getDefaultState().toBaseBlock(); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java index c4e957a05..af1392e4a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java @@ -341,7 +341,7 @@ public class CuboidClipboard { public BaseBlock getPoint(BlockVector3 position) throws ArrayIndexOutOfBoundsException { final BaseBlock block = getBlock(position); if (block == null) { - return new BaseBlock(BlockTypes.AIR); + return BlockTypes.AIR.getDefaultState().toBaseBlock(); } return block; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java index 42618fa6c..03d62887e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java @@ -271,7 +271,7 @@ public class DefaultBlockParser extends InputParser { } } - if (nbt != null) return new BaseBlock(state, nbt); + if (nbt != null) return state.toBaseBlock(nbt); if (blockType == BlockTypes.SIGN || blockType == BlockTypes.WALL_SIGN) { // Allow special sign text syntax diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java index b3b170ada..8f2c46486 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java @@ -203,8 +203,8 @@ public class WorldEditBinding { @BindingMatch(type = {BaseBlock.class, BlockState.class, BlockStateHolder.class}, behavior = BindingBehavior.CONSUMES, consumedCount = 1) -public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException { - return new BaseBlock(getBlockState(context)); + public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException { + return getBlockState(context).toBaseBlock(); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java index 596f0b63c..dfc2886ff 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java @@ -153,6 +153,6 @@ public class ServerCUIHandler { structureTag.put("id", new StringTag(BlockTypes.STRUCTURE_BLOCK.getId())); // return BlockTypes.STRUCTURE_BLOCK.getDefaultState().toBaseBlock(new CompoundTag(structureTag)); - return new BaseBlock(BlockTypes.STRUCTURE_BLOCK.getDefaultState(), new CompoundTag(structureTag)); + return BlockTypes.STRUCTURE_BLOCK.getDefaultState().toBaseBlock(new CompoundTag(structureTag)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java index 61caf1561..dbd628aaa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java @@ -111,7 +111,7 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { this(getState(id, data)); } - private static final BlockState getState(int id, int data) { + public static final BlockState getState(int id, int data) { BlockState blockState = LegacyMapper.getInstance().getBlockFromLegacy(id, data); if (blockState == null) { blockState = BlockTypes.AIR.getDefaultState(); @@ -124,8 +124,8 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { } @Deprecated - public static BaseBlock getFromInternalId(int id, CompoundTag nbtData) { - return new BaseBlock(id, nbtData); + public static BaseBlock getFromInternalId(int internalId, CompoundTag nbtData) { + return BlockState.getFromInternalId(internalId).toBaseBlock(nbtData); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java index 8d18bd90f..a8d2ac171 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java @@ -245,7 +245,7 @@ public class AnvilChunk13 implements Chunk { BlockState state = sectionBlocks != null ? sectionBlocks[(yIndex << 8) | (z << 4) | x] : BlockTypes.AIR.getDefaultState(); if (state.getMaterial().hasContainer()) { CompoundTag tileEntity = getBlockTileEntity(position); - if (tileEntity != null) return new BaseBlock(state, tileEntity); + return state.toBaseBlock(tileEntity); } return state.toBaseBlock(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java index 76b141465..58f7cb8e9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java @@ -238,7 +238,7 @@ public class LegacyMapper { } }else if(plotBlock instanceof LegacyPlotBlock) { try { - return new BaseBlock(((LegacyPlotBlock)plotBlock).getId(), ((LegacyPlotBlock)plotBlock).getData()); + return BaseBlock.getState(((LegacyPlotBlock)plotBlock).getId(), ((LegacyPlotBlock)plotBlock).getData()).toBaseBlock(); }catch(Throwable failed) { log.error("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!"); failed.printStackTrace();