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);
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;
}
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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;

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) {
// Allow special sign text syntax

View File

@ -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();
}
/**

View File

@ -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));
}
}

View File

@ -111,7 +111,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, 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<BaseBlock>, 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);
}
/**

View File

@ -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();

View File

@ -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();