diff --git a/src/main/java/cr0s/warpdrive/data/JumpBlock.java b/src/main/java/cr0s/warpdrive/data/JumpBlock.java index 9be1e76c..c4bc312d 100644 --- a/src/main/java/cr0s/warpdrive/data/JumpBlock.java +++ b/src/main/java/cr0s/warpdrive/data/JumpBlock.java @@ -131,19 +131,22 @@ public class JumpBlock { return worldSource.getTileEntity(new BlockPos(x, y, z)); } - private NBTTagCompound getBlockNBT() { + private NBTTagCompound getBlockNBT(final World worldSource) { if (weakTileEntity == null) { return blockNBT == null ? null : blockNBT.copy(); } - final TileEntity tileEntity = weakTileEntity.get(); - if (tileEntity != null) { - final NBTTagCompound tagCompound = new NBTTagCompound(); - tileEntity.writeToNBT(tagCompound); - return tagCompound; + TileEntity tileEntity = weakTileEntity.get(); + if (tileEntity == null) { + tileEntity = worldSource.getTileEntity(new BlockPos(x, y, z)); + if (tileEntity == null) { + WarpDrive.logger.error(String.format("Tile entity lost in %s", + this)); + return blockNBT == null ? null : blockNBT.copy(); + } } - WarpDrive.logger.error(String.format("Tile entity lost in %s", - this)); - return blockNBT == null ? null : blockNBT.copy(); + final NBTTagCompound tagCompound = new NBTTagCompound(); + tileEntity.writeToNBT(tagCompound); + return tagCompound; } public NBTBase getExternal(final String modId) { @@ -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 { - final NBTTagCompound nbtToDeploy = getBlockNBT(); + final NBTTagCompound nbtToDeploy = getBlockNBT(worldSource); int newBlockMeta = blockMeta; if (externals != null) { for (final Entry external : externals.entrySet()) { @@ -297,7 +300,7 @@ public class JumpBlock { block, newBlockMeta, nbtToDeploy)); } final IBlockState blockState = block.getStateFromMeta(newBlockMeta); - setBlockNoLight(targetWorld, target, blockState, 2); + setBlockNoLight(worldTarget, target, blockState, 2); if (nbtToDeploy != null) { nbtToDeploy.setInteger("x", target.getX()); @@ -329,24 +332,24 @@ public class JumpBlock { && nbtToDeploy.hasKey("id") && nbtToDeploy.getString("id").equals("savedMultipart") ) { isForgeMultipart = true; - newTileEntity = (TileEntity) CompatForgeMultipart.methodMultipartHelper_createTileFromNBT.invoke(null, targetWorld, nbtToDeploy); + newTileEntity = (TileEntity) CompatForgeMultipart.methodMultipartHelper_createTileFromNBT.invoke(null, worldTarget, nbtToDeploy); } if (newTileEntity == null) { - newTileEntity = TileEntity.create(targetWorld, nbtToDeploy); + newTileEntity = TileEntity.create(worldTarget, nbtToDeploy); if (newTileEntity == null) { 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", nbtToDeploy)); } } if (newTileEntity != null) { - targetWorld.setTileEntity(target, newTileEntity); + worldTarget.setTileEntity(target, newTileEntity); if (isForgeMultipart) { CompatForgeMultipart.methodTileMultipart_onChunkLoad.invoke(newTileEntity); - CompatForgeMultipart.methodMultipartHelper_sendDescPacket.invoke(null, targetWorld, newTileEntity); + CompatForgeMultipart.methodMultipartHelper_sendDescPacket.invoke(null, worldTarget, newTileEntity); } 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.setByte("blockMeta", (byte) blockMeta); - final NBTTagCompound nbtTileEntity = getBlockNBT(); + final NBTTagCompound nbtTileEntity = getBlockNBT(worldSource); if (nbtTileEntity != null) { tagCompound.setTag("blockNBT", nbtTileEntity); } diff --git a/src/main/java/cr0s/warpdrive/data/JumpShip.java b/src/main/java/cr0s/warpdrive/data/JumpShip.java index f3feba53..b91d903b 100644 --- a/src/main/java/cr0s/warpdrive/data/JumpShip.java +++ b/src/main/java/cr0s/warpdrive/data/JumpShip.java @@ -483,7 +483,7 @@ public class JumpShip { final NBTTagList tagListJumpBlocks = new NBTTagList(); for (final JumpBlock jumpBlock : jumpBlocks) { final NBTTagCompound tagCompoundBlock = new NBTTagCompound(); - jumpBlock.writeToNBT(tagCompoundBlock); + jumpBlock.writeToNBT(world, tagCompoundBlock); tagListJumpBlocks.appendTag(tagCompoundBlock); } tagCompound.setTag("jumpBlocks", tagListJumpBlocks); diff --git a/src/main/java/cr0s/warpdrive/event/JumpSequencer.java b/src/main/java/cr0s/warpdrive/event/JumpSequencer.java index 3849ba5e..6392801a 100644 --- a/src/main/java/cr0s/warpdrive/event/JumpSequencer.java +++ b/src/main/java/cr0s/warpdrive/event/JumpSequencer.java @@ -1028,7 +1028,7 @@ public class JumpSequencer extends AbstractSequencer { jumpBlock.fillEnergyStorage(); } - final BlockPos target = jumpBlock.deploy(targetWorld, transformation); + final BlockPos target = jumpBlock.deploy(sourceWorld, targetWorld, transformation); if ( shipMovementType != EnumShipMovementType.INSTANTIATE && shipMovementType != EnumShipMovementType.RESTORE ) { diff --git a/src/main/java/cr0s/warpdrive/world/WorldGenStructure.java b/src/main/java/cr0s/warpdrive/world/WorldGenStructure.java index c0527184..a10c58bf 100644 --- a/src/main/java/cr0s/warpdrive/world/WorldGenStructure.java +++ b/src/main/java/cr0s/warpdrive/world/WorldGenStructure.java @@ -344,7 +344,7 @@ public class WorldGenStructure { final BlockPos targetLocation = transformation.apply(jumpBlock.x, jumpBlock.y, jumpBlock.z); final Block blockAtTarget = world.getBlockState(targetLocation).getBlock(); if (blockAtTarget == Blocks.AIR || Dictionary.BLOCKS_EXPANDABLE.contains(blockAtTarget)) { - jumpBlock.deploy(world, transformation); + jumpBlock.deploy(null, world, transformation); } else { if (WarpDriveConfig.LOGGING_WORLD_GENERATION && WarpDrive.isDev) { WarpDrive.logger.info(String.format("Deployment collision detected %s with %s during world generation, skipping this block...",