Don't construct new BaseBlock

This commit is contained in:
Jesse Boyd 2019-04-06 01:12:57 +11:00
parent 99db2d557a
commit 144215c813
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
12 changed files with 15 additions and 18 deletions

View File

@ -379,8 +379,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
trio.set(x, y, z); trio.set(x, y, z);
CompoundTag nbt = nbtMap.get(trio); CompoundTag nbt = nbtMap.get(trio);
if (nbt != null) { if (nbt != null) {
BaseBlock block = new BaseBlock(state, nbt); task.run(x, y, z, state.toBaseBlock(nbt));
task.run(x, y, z, block);
continue; continue;
} }
} }
@ -411,8 +410,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
trio.set(x, y, z); trio.set(x, y, z);
CompoundTag nbt = nbtMap.get(trio); CompoundTag nbt = nbtMap.get(trio);
if (nbt != null) { if (nbt != null) {
BaseBlock block = new BaseBlock(state, nbt); task.run(x, y, z, state.toBaseBlock(nbt));
task.run(x, y, z, block);
continue; continue;
} }
} }

View File

@ -12,7 +12,6 @@ import com.sk89q.worldedit.world.block.BlockTypes;
public class IdDataMaskPattern extends AbstractExtentPattern { public class IdDataMaskPattern extends AbstractExtentPattern {
private final Pattern pattern; private final Pattern pattern;
private final int bitMask; private final int bitMask;
private final BaseBlock mutable = new BaseBlock(BlockTypes.AIR);
public IdDataMaskPattern(Extent extent, Pattern parent, int bitMask) { public IdDataMaskPattern(Extent extent, Pattern parent, int bitMask) {
super(extent); super(extent);

View File

@ -205,7 +205,7 @@ public class PropertyPattern extends AbstractExtentPattern {
if (newOrdinal != ordinal) { if (newOrdinal != ordinal) {
CompoundTag nbt = block.getNbtData(); CompoundTag nbt = block.getNbtData();
BlockState newState = BlockState.getFromOrdinal(newOrdinal); BlockState newState = BlockState.getFromOrdinal(newOrdinal);
return nbt != null ? new BaseBlock(newState, nbt) : newState.toBaseBlock(); return newState.toBaseBlock(nbt);
} }
return orDefault; return orDefault;
} }

View File

@ -122,7 +122,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter {
if (state.getBlockType().getMaterial().hasContainer()) { if (state.getBlockType().getMaterial().hasContainer()) {
CompoundTag nbt = (CompoundTag) blockMap.get("nbt"); CompoundTag nbt = (CompoundTag) blockMap.get("nbt");
if (nbt != null) { if (nbt != null) {
BaseBlock block = new BaseBlock(state, nbt); BaseBlock block = state.toBaseBlock(nbt);
clipboard.setBlock(x, y, z, block); clipboard.setBlock(x, y, z, block);
continue; continue;
} }

View File

@ -153,7 +153,7 @@ public class FakePlayer extends AbstractPlayerActor {
@Override @Override
public BaseBlock getBlockInHand(HandSide ignore) { public BaseBlock getBlockInHand(HandSide ignore) {
return new BaseBlock(BlockTypes.AIR.getDefaultState()); return BlockTypes.AIR.getDefaultState().toBaseBlock();
} }
@Override @Override

View File

@ -341,7 +341,7 @@ public class CuboidClipboard {
public BaseBlock getPoint(BlockVector3 position) throws ArrayIndexOutOfBoundsException { public BaseBlock getPoint(BlockVector3 position) throws ArrayIndexOutOfBoundsException {
final BaseBlock block = getBlock(position); final BaseBlock block = getBlock(position);
if (block == null) { if (block == null) {
return new BaseBlock(BlockTypes.AIR); return BlockTypes.AIR.getDefaultState().toBaseBlock();
} }
return block; return block;

View File

@ -271,7 +271,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
} }
} }
if (nbt != null) return new BaseBlock(state, nbt); if (nbt != null) return state.toBaseBlock(nbt);
if (blockType == BlockTypes.SIGN || blockType == BlockTypes.WALL_SIGN) { if (blockType == BlockTypes.SIGN || blockType == BlockTypes.WALL_SIGN) {
// Allow special sign text syntax // Allow special sign text syntax

View File

@ -203,8 +203,8 @@ public class WorldEditBinding {
@BindingMatch(type = {BaseBlock.class, BlockState.class, BlockStateHolder.class}, @BindingMatch(type = {BaseBlock.class, BlockState.class, BlockStateHolder.class},
behavior = BindingBehavior.CONSUMES, behavior = BindingBehavior.CONSUMES,
consumedCount = 1) consumedCount = 1)
public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException { public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException {
return new BaseBlock(getBlockState(context)); return getBlockState(context).toBaseBlock();
} }
/** /**

View File

@ -153,6 +153,6 @@ public class ServerCUIHandler {
structureTag.put("id", new StringTag(BlockTypes.STRUCTURE_BLOCK.getId())); structureTag.put("id", new StringTag(BlockTypes.STRUCTURE_BLOCK.getId()));
// return BlockTypes.STRUCTURE_BLOCK.getDefaultState().toBaseBlock(new CompoundTag(structureTag)); // 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));
} }
} }

View File

@ -111,7 +111,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
this(getState(id, data)); 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); BlockState blockState = LegacyMapper.getInstance().getBlockFromLegacy(id, data);
if (blockState == null) { if (blockState == null) {
blockState = BlockTypes.AIR.getDefaultState(); blockState = BlockTypes.AIR.getDefaultState();
@ -124,8 +124,8 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
} }
@Deprecated @Deprecated
public static BaseBlock getFromInternalId(int id, CompoundTag nbtData) { public static BaseBlock getFromInternalId(int internalId, CompoundTag nbtData) {
return new BaseBlock(id, nbtData); return BlockState.getFromInternalId(internalId).toBaseBlock(nbtData);
} }
/** /**

View File

@ -245,7 +245,7 @@ public class AnvilChunk13 implements Chunk {
BlockState state = sectionBlocks != null ? sectionBlocks[(yIndex << 8) | (z << 4) | x] : BlockTypes.AIR.getDefaultState(); BlockState state = sectionBlocks != null ? sectionBlocks[(yIndex << 8) | (z << 4) | x] : BlockTypes.AIR.getDefaultState();
if (state.getMaterial().hasContainer()) { if (state.getMaterial().hasContainer()) {
CompoundTag tileEntity = getBlockTileEntity(position); CompoundTag tileEntity = getBlockTileEntity(position);
if (tileEntity != null) return new BaseBlock(state, tileEntity); return state.toBaseBlock(tileEntity);
} }
return state.toBaseBlock(); return state.toBaseBlock();

View File

@ -238,7 +238,7 @@ public class LegacyMapper {
} }
}else if(plotBlock instanceof LegacyPlotBlock) { }else if(plotBlock instanceof LegacyPlotBlock) {
try { try {
return new BaseBlock(((LegacyPlotBlock)plotBlock).getId(), ((LegacyPlotBlock)plotBlock).getData()); return BaseBlock.getState(((LegacyPlotBlock)plotBlock).getId(), ((LegacyPlotBlock)plotBlock).getData()).toBaseBlock();
}catch(Throwable failed) { }catch(Throwable failed) {
log.error("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!"); log.error("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!");
failed.printStackTrace(); failed.printStackTrace();