Fixed regression causing dup/exploit during jump

This commit is contained in:
Unknown 2019-01-31 22:33:07 +01:00 committed by unknown
parent 0d2699efa0
commit c601498859
4 changed files with 25 additions and 22 deletions

View file

@ -131,20 +131,23 @@ public class JumpBlock {
return worldSource.getTileEntity(new BlockPos(x, y, z)); return worldSource.getTileEntity(new BlockPos(x, y, z));
} }
private NBTTagCompound getBlockNBT() { private NBTTagCompound getBlockNBT(final World worldSource) {
if (weakTileEntity == null) { if (weakTileEntity == null) {
return blockNBT == null ? null : blockNBT.copy(); return blockNBT == null ? null : blockNBT.copy();
} }
final TileEntity tileEntity = weakTileEntity.get(); TileEntity tileEntity = weakTileEntity.get();
if (tileEntity != null) { if (tileEntity == null) {
final NBTTagCompound tagCompound = new NBTTagCompound(); tileEntity = worldSource.getTileEntity(new BlockPos(x, y, z));
tileEntity.writeToNBT(tagCompound); if (tileEntity == null) {
return tagCompound;
}
WarpDrive.logger.error(String.format("Tile entity lost in %s", WarpDrive.logger.error(String.format("Tile entity lost in %s",
this)); this));
return blockNBT == null ? null : blockNBT.copy(); return blockNBT == null ? null : blockNBT.copy();
} }
}
final NBTTagCompound tagCompound = new NBTTagCompound();
tileEntity.writeToNBT(tagCompound);
return tagCompound;
}
public NBTBase getExternal(final String modId) { public NBTBase getExternal(final String modId) {
if (externals == null) { if (externals == null) {
@ -276,9 +279,9 @@ public class JumpBlock {
} }
} }
public BlockPos deploy(final World targetWorld, final ITransformation transformation) { public BlockPos deploy(final World worldSource, final World worldTarget, final ITransformation transformation) {
try { try {
final NBTTagCompound nbtToDeploy = getBlockNBT(); final NBTTagCompound nbtToDeploy = getBlockNBT(worldSource);
int newBlockMeta = blockMeta; int newBlockMeta = blockMeta;
if (externals != null) { if (externals != null) {
for (final Entry<String, NBTBase> external : externals.entrySet()) { for (final Entry<String, NBTBase> external : externals.entrySet()) {
@ -297,7 +300,7 @@ public class JumpBlock {
block, newBlockMeta, nbtToDeploy)); block, newBlockMeta, nbtToDeploy));
} }
final IBlockState blockState = block.getStateFromMeta(newBlockMeta); final IBlockState blockState = block.getStateFromMeta(newBlockMeta);
setBlockNoLight(targetWorld, target, blockState, 2); setBlockNoLight(worldTarget, target, blockState, 2);
if (nbtToDeploy != null) { if (nbtToDeploy != null) {
nbtToDeploy.setInteger("x", target.getX()); nbtToDeploy.setInteger("x", target.getX());
@ -329,24 +332,24 @@ public class JumpBlock {
&& nbtToDeploy.hasKey("id") && nbtToDeploy.hasKey("id")
&& nbtToDeploy.getString("id").equals("savedMultipart") ) { && nbtToDeploy.getString("id").equals("savedMultipart") ) {
isForgeMultipart = true; isForgeMultipart = true;
newTileEntity = (TileEntity) CompatForgeMultipart.methodMultipartHelper_createTileFromNBT.invoke(null, targetWorld, nbtToDeploy); newTileEntity = (TileEntity) CompatForgeMultipart.methodMultipartHelper_createTileFromNBT.invoke(null, worldTarget, nbtToDeploy);
} }
if (newTileEntity == null) { if (newTileEntity == null) {
newTileEntity = TileEntity.create(targetWorld, nbtToDeploy); newTileEntity = TileEntity.create(worldTarget, nbtToDeploy);
if (newTileEntity == null) { if (newTileEntity == null) {
WarpDrive.logger.error(String.format("%s deploy failed to create new tile entity %s block %s:%d", WarpDrive.logger.error(String.format("%s deploy failed to create new tile entity %s block %s:%d",
this, Commons.format(targetWorld, x, y, z), block, blockMeta)); this, Commons.format(worldTarget, x, y, z), block, blockMeta));
WarpDrive.logger.error(String.format("NBT data was %s", WarpDrive.logger.error(String.format("NBT data was %s",
nbtToDeploy)); nbtToDeploy));
} }
} }
if (newTileEntity != null) { if (newTileEntity != null) {
targetWorld.setTileEntity(target, newTileEntity); worldTarget.setTileEntity(target, newTileEntity);
if (isForgeMultipart) { if (isForgeMultipart) {
CompatForgeMultipart.methodTileMultipart_onChunkLoad.invoke(newTileEntity); CompatForgeMultipart.methodTileMultipart_onChunkLoad.invoke(newTileEntity);
CompatForgeMultipart.methodMultipartHelper_sendDescPacket.invoke(null, targetWorld, newTileEntity); CompatForgeMultipart.methodMultipartHelper_sendDescPacket.invoke(null, worldTarget, newTileEntity);
} }
newTileEntity.markDirty(); newTileEntity.markDirty();
@ -480,10 +483,10 @@ public class JumpBlock {
} }
} }
public void writeToNBT(final NBTTagCompound tagCompound) { public void writeToNBT(final World worldSource, final NBTTagCompound tagCompound) {
tagCompound.setString("block", Block.REGISTRY.getNameForObject(block).toString()); tagCompound.setString("block", Block.REGISTRY.getNameForObject(block).toString());
tagCompound.setByte("blockMeta", (byte) blockMeta); tagCompound.setByte("blockMeta", (byte) blockMeta);
final NBTTagCompound nbtTileEntity = getBlockNBT(); final NBTTagCompound nbtTileEntity = getBlockNBT(worldSource);
if (nbtTileEntity != null) { if (nbtTileEntity != null) {
tagCompound.setTag("blockNBT", nbtTileEntity); tagCompound.setTag("blockNBT", nbtTileEntity);
} }

View file

@ -483,7 +483,7 @@ public class JumpShip {
final NBTTagList tagListJumpBlocks = new NBTTagList(); final NBTTagList tagListJumpBlocks = new NBTTagList();
for (final JumpBlock jumpBlock : jumpBlocks) { for (final JumpBlock jumpBlock : jumpBlocks) {
final NBTTagCompound tagCompoundBlock = new NBTTagCompound(); final NBTTagCompound tagCompoundBlock = new NBTTagCompound();
jumpBlock.writeToNBT(tagCompoundBlock); jumpBlock.writeToNBT(world, tagCompoundBlock);
tagListJumpBlocks.appendTag(tagCompoundBlock); tagListJumpBlocks.appendTag(tagCompoundBlock);
} }
tagCompound.setTag("jumpBlocks", tagListJumpBlocks); tagCompound.setTag("jumpBlocks", tagListJumpBlocks);

View file

@ -1028,7 +1028,7 @@ public class JumpSequencer extends AbstractSequencer {
jumpBlock.fillEnergyStorage(); jumpBlock.fillEnergyStorage();
} }
final BlockPos target = jumpBlock.deploy(targetWorld, transformation); final BlockPos target = jumpBlock.deploy(sourceWorld, targetWorld, transformation);
if ( shipMovementType != EnumShipMovementType.INSTANTIATE if ( shipMovementType != EnumShipMovementType.INSTANTIATE
&& shipMovementType != EnumShipMovementType.RESTORE ) { && shipMovementType != EnumShipMovementType.RESTORE ) {

View file

@ -344,7 +344,7 @@ public class WorldGenStructure {
final BlockPos targetLocation = transformation.apply(jumpBlock.x, jumpBlock.y, jumpBlock.z); final BlockPos targetLocation = transformation.apply(jumpBlock.x, jumpBlock.y, jumpBlock.z);
final Block blockAtTarget = world.getBlockState(targetLocation).getBlock(); final Block blockAtTarget = world.getBlockState(targetLocation).getBlock();
if (blockAtTarget == Blocks.AIR || Dictionary.BLOCKS_EXPANDABLE.contains(blockAtTarget)) { if (blockAtTarget == Blocks.AIR || Dictionary.BLOCKS_EXPANDABLE.contains(blockAtTarget)) {
jumpBlock.deploy(world, transformation); jumpBlock.deploy(null, world, transformation);
} else { } else {
if (WarpDriveConfig.LOGGING_WORLD_GENERATION && WarpDrive.isDev) { if (WarpDriveConfig.LOGGING_WORLD_GENERATION && WarpDrive.isDev) {
WarpDrive.logger.info(String.format("Deployment collision detected %s with %s during world generation, skipping this block...", WarpDrive.logger.info(String.format("Deployment collision detected %s with %s during world generation, skipping this block...",