Updated externals support in BlockTransformer

This commit is contained in:
LemADEC 2017-08-14 16:22:26 +02:00
parent aa3d1b665e
commit c6d6ea75ff
32 changed files with 105 additions and 52 deletions

View file

@ -21,11 +21,12 @@ public interface IBlockTransformer {
NBTBase saveExternals(final World world, final int x, final int y, final int z, NBTBase saveExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity); final Block block, final int blockMeta, final TileEntity tileEntity);
// Called when removing the original ship structure. // Called when removing the original ship structure, if saveExternals() returned non-null for that block.
// Use this to prevents drops, clear energy networks, etc. // Use this to prevents drops, clear energy networks, etc.
// Block and TileEntity will be removed right after this call. // Block and TileEntity will be removed right after this call.
// When moving, the new ship is placed first. // When moving, the new ship is placed first.
void remove(final TileEntity tileEntity); void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity);
// Called when restoring a ship in the world. // Called when restoring a ship in the world.
// Use this to apply metadata & NBT rotation, right before block & tile entity placement. // Use this to apply metadata & NBT rotation, right before block & tile entity placement.
@ -33,7 +34,7 @@ public interface IBlockTransformer {
// Warning: do NOT place the block or tile entity! // Warning: do NOT place the block or tile entity!
int rotate(final Block block, int metadata, final NBTTagCompound nbtTileEntity, final ITransformation transformation); int rotate(final Block block, int metadata, final NBTTagCompound nbtTileEntity, final ITransformation transformation);
// Called when placing back a ship in the world. // Called when placing back a ship in the world, if saveExternals() returned non-null for that block.
// Use this to restore external data from the ship schematic, right after block & tile entity placement. // Use this to restore external data from the ship schematic, right after block & tile entity placement.
// Use priority placement to ensure dependent blocks are placed first. // Use priority placement to ensure dependent blocks are placed first.
// This is will be called whether saveExternals returned null or not. // This is will be called whether saveExternals returned null or not.

View file

@ -49,7 +49,8 @@ public class CompatAdvancedRepulsionSystems implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }
@ -115,7 +116,9 @@ public class CompatAdvancedRepulsionSystems implements IBlockTransformer {
} }
@Override @Override
public void restoreExternals(final World world, final int x, final int y, final int z, final Block block, final int blockMeta, final TileEntity tileEntity, final ITransformation transformation, final NBTBase nbtBase) { public void restoreExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity,
final ITransformation transformation, final NBTBase nbtBase) {
// nothing to do // nothing to do
} }
} }

View file

@ -74,7 +74,8 @@ public class CompatAppliedEnergistics2 implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }
@ -187,7 +188,9 @@ public class CompatAppliedEnergistics2 implements IBlockTransformer {
} }
@Override @Override
public void restoreExternals(final World world, final int x, final int y, final int z, final Block block, final int blockMeta, final TileEntity tileEntity, final ITransformation transformation, final NBTBase nbtBase) { public void restoreExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity,
final ITransformation transformation, final NBTBase nbtBase) {
// nothing to do // nothing to do
} }
} }

View file

@ -66,7 +66,8 @@ public class CompatArsMagica2 implements IBlockTransformer {
@Override @Override
@Optional.Method(modid = "arsmagica2") @Optional.Method(modid = "arsmagica2")
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
if (tileEntity instanceof IPowerNode) { if (tileEntity instanceof IPowerNode) {
PowerNodeRegistry.For(tileEntity.getWorldObj()).removePowerNode((IPowerNode) tileEntity); PowerNodeRegistry.For(tileEntity.getWorldObj()).removePowerNode((IPowerNode) tileEntity);
} }
@ -127,7 +128,9 @@ public class CompatArsMagica2 implements IBlockTransformer {
@Override @Override
@Optional.Method(modid = "arsmagica2") @Optional.Method(modid = "arsmagica2")
public void restoreExternals(final World world, final int x, final int y, final int z, final Block block, final int blockMeta, final TileEntity tileEntity, final ITransformation transformation, final NBTBase nbtBase) { public void restoreExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity,
final ITransformation transformation, final NBTBase nbtBase) {
if (!(tileEntity instanceof IPowerNode) || nbtBase == null) { if (!(tileEntity instanceof IPowerNode) || nbtBase == null) {
return; return;
} }

View file

@ -46,7 +46,8 @@ public class CompatBiblioCraft implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -49,7 +49,8 @@ public class CompatBotania implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }
@ -116,7 +117,9 @@ public class CompatBotania implements IBlockTransformer {
} }
@Override @Override
public void restoreExternals(final World world, final int x, final int y, final int z, final Block block, final int blockMeta, final TileEntity tileEntity, final ITransformation transformation, final NBTBase nbtBase) { public void restoreExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity,
final ITransformation transformation, final NBTBase nbtBase) {
// nothing to do // nothing to do
} }
} }

View file

@ -66,7 +66,8 @@ public class CompatBuildCraft implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }
@ -241,7 +242,9 @@ public class CompatBuildCraft implements IBlockTransformer {
} }
@Override @Override
public void restoreExternals(final World world, final int x, final int y, final int z, final Block block, final int blockMeta, final TileEntity tileEntity, final ITransformation transformation, final NBTBase nbtBase) { public void restoreExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity,
final ITransformation transformation, final NBTBase nbtBase) {
// nothing to do // nothing to do
} }
} }

View file

@ -78,7 +78,8 @@ public class CompatCarpentersBlocks implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -49,7 +49,8 @@ public class CompatComputerCraft implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -55,7 +55,8 @@ public class CompatCustomNpcs implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -52,7 +52,8 @@ public class CompatEnderIO implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -40,7 +40,8 @@ public class CompatEvilCraft implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -58,7 +58,8 @@ public class CompatForgeMultipart implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -61,8 +61,8 @@ public class CompatImmersiveEngineering implements IBlockTransformer {
} }
@Override @Override
@Optional.Method(modid = "ImmersiveEngineering") public void removeExternals(final World world, final int x, final int y, final int z,
public void remove(TileEntity tileEntity) { final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -41,10 +41,13 @@ public class CompatIndustrialCraft2 implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }
private static final short[] mrotFacing = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
@Override @Override
public int rotate(final Block block, final int metadata, final NBTTagCompound nbtTileEntity, final ITransformation transformation) { public int rotate(final Block block, final int metadata, final NBTTagCompound nbtTileEntity, final ITransformation transformation) {
final byte rotationSteps = transformation.getRotationSteps(); final byte rotationSteps = transformation.getRotationSteps();
@ -66,17 +69,16 @@ public class CompatIndustrialCraft2 implements IBlockTransformer {
return metadata; return metadata;
} }
short facing = nbtTileEntity.getShort("facing"); final short facing = nbtTileEntity.getShort("facing");
final short[] mrot = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
switch (rotationSteps) { switch (rotationSteps) {
case 1: case 1:
nbtTileEntity.setShort("facing", mrot[facing]); nbtTileEntity.setShort("facing", mrotFacing[facing]);
return metadata; return metadata;
case 2: case 2:
nbtTileEntity.setShort("facing", mrot[mrot[facing]]); nbtTileEntity.setShort("facing", mrotFacing[mrotFacing[facing]]);
return metadata; return metadata;
case 3: case 3:
nbtTileEntity.setShort("facing", mrot[mrot[mrot[facing]]]); nbtTileEntity.setShort("facing", mrotFacing[mrotFacing[mrotFacing[facing]]]);
return metadata; return metadata;
default: default:
return metadata; return metadata;

View file

@ -40,7 +40,8 @@ public class CompatJABBA implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -45,7 +45,8 @@ public class CompatMekanism implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -40,7 +40,8 @@ public class CompatMetallurgy implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -40,7 +40,8 @@ public class CompatNatura implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -40,7 +40,8 @@ public class CompatOpenComputers implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -42,7 +42,8 @@ public class CompatPneumaticCraft implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -40,7 +40,8 @@ public class CompatRedstonePaste implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -65,7 +65,8 @@ public class CompatSGCraft implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -59,7 +59,8 @@ public class CompatStargateTech2 implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -52,7 +52,8 @@ public class CompatTConstruct implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -50,7 +50,8 @@ public class CompatTechguns implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -67,7 +67,8 @@ public class CompatThaumcraft implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -45,7 +45,8 @@ public class CompatThermalDynamics implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -41,7 +41,8 @@ public class CompatThermalExpansion implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
final Block block, final int blockMeta, final TileEntity tileEntity) {
// nothing to do // nothing to do
} }

View file

@ -28,6 +28,8 @@ public class CompatWarpDrive implements IBlockTransformer {
@Override @Override
public boolean isApplicable(final Block block, final int metadata, final TileEntity tileEntity) { public boolean isApplicable(final Block block, final int metadata, final TileEntity tileEntity) {
return block instanceof BlockHullSlab return block instanceof BlockHullSlab
|| block instanceof BlockAirFlow
|| block instanceof BlockAirSource
|| tileEntity instanceof TileEntityEnergyBank; || tileEntity instanceof TileEntityEnergyBank;
} }
@ -59,8 +61,18 @@ public class CompatWarpDrive implements IBlockTransformer {
} }
@Override @Override
public void remove(TileEntity tileEntity) { public void removeExternals(final World world, final int x, final int y, final int z,
// nothing to do final Block block, final int blockMeta, final TileEntity tileEntity) {
if (block instanceof BlockAirFlow || block instanceof BlockAirSource) {
final ChunkData chunkData = ChunkHandler.getChunkData(world, x, y, z, false);
if (chunkData == null) {
WarpDrive.logger.error(String.format("CompatWarpDrive trying to get data from an non-loaded chunk in %s @ (%d %d %d)",
world.provider.getDimensionName(), x, y, z));
assert(false);
return;
}
chunkData.setDataAir(x, y, z, StateAir.AIR_DEFAULT);
}
} }
private static final short[] mrotDirection = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; private static final short[] mrotDirection = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

View file

@ -82,7 +82,8 @@ public class JumpBlock {
// save externals // save externals
for (Entry<String, IBlockTransformer> entryBlockTransformer : WarpDriveConfig.blockTransformers.entrySet()) { for (Entry<String, IBlockTransformer> entryBlockTransformer : WarpDriveConfig.blockTransformers.entrySet()) {
if (entryBlockTransformer.getValue().isApplicable(block, blockMeta, tileEntity)) { if (entryBlockTransformer.getValue().isApplicable(block, blockMeta, tileEntity)) {
NBTBase nbtBase = entryBlockTransformer.getValue().saveExternals(world, x, y, z, block, blockMeta, tileEntity); final NBTBase nbtBase = entryBlockTransformer.getValue().saveExternals(world, x, y, z, block, blockMeta, tileEntity);
// (we always save, even if null as a reminder on which transformer applies to this block)
setExternal(entryBlockTransformer.getKey(), nbtBase); setExternal(entryBlockTransformer.getKey(), nbtBase);
} }
} }
@ -107,7 +108,7 @@ public class JumpBlock {
} }
NBTBase nbtExternal = externals.get(modId); NBTBase nbtExternal = externals.get(modId);
if (WarpDriveConfig.LOGGING_JUMPBLOCKS) { if (WarpDriveConfig.LOGGING_JUMPBLOCKS) {
WarpDrive.logger.info("Restoring " + modId + " externals at " + x + " " + y + " " + z + " " + nbtExternal); WarpDrive.logger.info("Returning " + modId + " externals at " + x + " " + y + " " + z + " " + nbtExternal);
} }
if (nbtExternal == null) { if (nbtExternal == null) {
return null; return null;

View file

@ -898,7 +898,7 @@ public class JumpSequencer extends AbstractSequencer {
} }
int index = 0; int index = 0;
while (index < blocksToMove && actualIndexInShip < ship.jumpBlocks.length) { while (index < blocksToMove && actualIndexInShip < ship.jumpBlocks.length) {
JumpBlock jumpBlock = ship.jumpBlocks[ship.jumpBlocks.length - actualIndexInShip - 1]; final JumpBlock jumpBlock = ship.jumpBlocks[ship.jumpBlocks.length - actualIndexInShip - 1];
if (jumpBlock == null) { if (jumpBlock == null) {
if (WarpDriveConfig.LOGGING_JUMP) { if (WarpDriveConfig.LOGGING_JUMP) {
WarpDrive.logger.info(this + " Moving ship externals: unexpected null found at ship[" + actualIndexInShip + "]"); WarpDrive.logger.info(this + " Moving ship externals: unexpected null found at ship[" + actualIndexInShip + "]");
@ -907,17 +907,18 @@ public class JumpSequencer extends AbstractSequencer {
continue; continue;
} }
if (jumpBlock.blockTileEntity != null && jumpBlock.externals != null) { if (jumpBlock.externals != null) {
if (WarpDriveConfig.LOGGING_JUMPBLOCKS) { if (WarpDriveConfig.LOGGING_JUMPBLOCKS) {
WarpDrive.logger.info("Moving externals for block " + jumpBlock.block + "@" + jumpBlock.blockMeta + " at " + jumpBlock.x + " " + jumpBlock.y + " " + jumpBlock.z); WarpDrive.logger.info("Moving externals for block " + jumpBlock.block + "@" + jumpBlock.blockMeta + " at " + jumpBlock.x + " " + jumpBlock.y + " " + jumpBlock.z);
} }
for (Entry<String, NBTBase> external : jumpBlock.externals.entrySet()) { for (Entry<String, NBTBase> external : jumpBlock.externals.entrySet()) {
IBlockTransformer blockTransformer = WarpDriveConfig.blockTransformers.get(external.getKey()); final IBlockTransformer blockTransformer = WarpDriveConfig.blockTransformers.get(external.getKey());
if (blockTransformer != null) { if (blockTransformer != null) {
blockTransformer.remove(jumpBlock.blockTileEntity); blockTransformer.removeExternals(sourceWorld, jumpBlock.x, jumpBlock.y, jumpBlock.z,
jumpBlock.block, jumpBlock.blockMeta, jumpBlock.blockTileEntity);
ChunkCoordinates target = transformation.apply(jumpBlock.x, jumpBlock.y, jumpBlock.z); final ChunkCoordinates target = transformation.apply(jumpBlock.x, jumpBlock.y, jumpBlock.z);
TileEntity newTileEntity = targetWorld.getTileEntity(target.posX, target.posY, target.posZ); final TileEntity newTileEntity = jumpBlock.blockTileEntity == null ? null : targetWorld.getTileEntity(target.posX, target.posY, target.posZ);
blockTransformer.restoreExternals(targetWorld, target.posX, target.posY, target.posZ, blockTransformer.restoreExternals(targetWorld, target.posX, target.posY, target.posZ,
jumpBlock.block, jumpBlock.blockMeta, newTileEntity, transformation, external.getValue()); jumpBlock.block, jumpBlock.blockMeta, newTileEntity, transformation, external.getValue());
} }