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,
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.
// Block and TileEntity will be removed right after this call.
// 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.
// 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!
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 priority placement to ensure dependent blocks are placed first.
// This is will be called whether saveExternals returned null or not.

View file

@ -49,7 +49,8 @@ public class CompatAdvancedRepulsionSystems implements IBlockTransformer {
}
@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
}
@ -115,7 +116,9 @@ public class CompatAdvancedRepulsionSystems implements IBlockTransformer {
}
@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
}
}

View file

@ -74,7 +74,8 @@ public class CompatAppliedEnergistics2 implements IBlockTransformer {
}
@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
}
@ -187,7 +188,9 @@ public class CompatAppliedEnergistics2 implements IBlockTransformer {
}
@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
}
}

View file

@ -66,7 +66,8 @@ public class CompatArsMagica2 implements IBlockTransformer {
@Override
@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) {
PowerNodeRegistry.For(tileEntity.getWorldObj()).removePowerNode((IPowerNode) tileEntity);
}
@ -127,7 +128,9 @@ public class CompatArsMagica2 implements IBlockTransformer {
@Override
@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) {
return;
}

View file

@ -46,7 +46,8 @@ public class CompatBiblioCraft implements IBlockTransformer {
}
@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
}

View file

@ -49,7 +49,8 @@ public class CompatBotania implements IBlockTransformer {
}
@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
}
@ -116,7 +117,9 @@ public class CompatBotania implements IBlockTransformer {
}
@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
}
}

View file

@ -66,7 +66,8 @@ public class CompatBuildCraft implements IBlockTransformer {
}
@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
}
@ -241,7 +242,9 @@ public class CompatBuildCraft implements IBlockTransformer {
}
@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
}
}

View file

@ -78,7 +78,8 @@ public class CompatCarpentersBlocks implements IBlockTransformer {
}
@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
}

View file

@ -49,7 +49,8 @@ public class CompatComputerCraft implements IBlockTransformer {
}
@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
}

View file

@ -55,7 +55,8 @@ public class CompatCustomNpcs implements IBlockTransformer {
}
@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
}

View file

@ -52,7 +52,8 @@ public class CompatEnderIO implements IBlockTransformer {
}
@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
}

View file

@ -40,7 +40,8 @@ public class CompatEvilCraft implements IBlockTransformer {
}
@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
}

View file

@ -58,7 +58,8 @@ public class CompatForgeMultipart implements IBlockTransformer {
}
@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
}

View file

@ -61,8 +61,8 @@ public class CompatImmersiveEngineering implements IBlockTransformer {
}
@Override
@Optional.Method(modid = "ImmersiveEngineering")
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
}

View file

@ -41,10 +41,13 @@ public class CompatIndustrialCraft2 implements IBlockTransformer {
}
@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
}
private static final short[] mrotFacing = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
@Override
public int rotate(final Block block, final int metadata, final NBTTagCompound nbtTileEntity, final ITransformation transformation) {
final byte rotationSteps = transformation.getRotationSteps();
@ -66,17 +69,16 @@ public class CompatIndustrialCraft2 implements IBlockTransformer {
return metadata;
}
short facing = nbtTileEntity.getShort("facing");
final short[] mrot = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
final short facing = nbtTileEntity.getShort("facing");
switch (rotationSteps) {
case 1:
nbtTileEntity.setShort("facing", mrot[facing]);
nbtTileEntity.setShort("facing", mrotFacing[facing]);
return metadata;
case 2:
nbtTileEntity.setShort("facing", mrot[mrot[facing]]);
nbtTileEntity.setShort("facing", mrotFacing[mrotFacing[facing]]);
return metadata;
case 3:
nbtTileEntity.setShort("facing", mrot[mrot[mrot[facing]]]);
nbtTileEntity.setShort("facing", mrotFacing[mrotFacing[mrotFacing[facing]]]);
return metadata;
default:
return metadata;

View file

@ -40,7 +40,8 @@ public class CompatJABBA implements IBlockTransformer {
}
@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
}

View file

@ -45,7 +45,8 @@ public class CompatMekanism implements IBlockTransformer {
}
@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
}

View file

@ -40,7 +40,8 @@ public class CompatMetallurgy implements IBlockTransformer {
}
@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
}

View file

@ -40,7 +40,8 @@ public class CompatNatura implements IBlockTransformer {
}
@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
}

View file

@ -40,7 +40,8 @@ public class CompatOpenComputers implements IBlockTransformer {
}
@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
}

View file

@ -42,7 +42,8 @@ public class CompatPneumaticCraft implements IBlockTransformer {
}
@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
}

View file

@ -40,7 +40,8 @@ public class CompatRedstonePaste implements IBlockTransformer {
}
@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
}

View file

@ -65,7 +65,8 @@ public class CompatSGCraft implements IBlockTransformer {
}
@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
}

View file

@ -59,7 +59,8 @@ public class CompatStargateTech2 implements IBlockTransformer {
}
@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
}

View file

@ -52,7 +52,8 @@ public class CompatTConstruct implements IBlockTransformer {
}
@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
}

View file

@ -50,7 +50,8 @@ public class CompatTechguns implements IBlockTransformer {
}
@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
}

View file

@ -67,7 +67,8 @@ public class CompatThaumcraft implements IBlockTransformer {
}
@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
}

View file

@ -45,7 +45,8 @@ public class CompatThermalDynamics implements IBlockTransformer {
}
@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
}

View file

@ -41,7 +41,8 @@ public class CompatThermalExpansion implements IBlockTransformer {
}
@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
}

View file

@ -28,6 +28,8 @@ public class CompatWarpDrive implements IBlockTransformer {
@Override
public boolean isApplicable(final Block block, final int metadata, final TileEntity tileEntity) {
return block instanceof BlockHullSlab
|| block instanceof BlockAirFlow
|| block instanceof BlockAirSource
|| tileEntity instanceof TileEntityEnergyBank;
}
@ -59,8 +61,18 @@ public class CompatWarpDrive implements IBlockTransformer {
}
@Override
public void remove(TileEntity tileEntity) {
// nothing to do
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 (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 };

View file

@ -82,7 +82,8 @@ public class JumpBlock {
// save externals
for (Entry<String, IBlockTransformer> entryBlockTransformer : WarpDriveConfig.blockTransformers.entrySet()) {
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);
}
}
@ -107,7 +108,7 @@ public class JumpBlock {
}
NBTBase nbtExternal = externals.get(modId);
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) {
return null;

View file

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