From 26744da88c23c3ca4f682ea92def85307dcd17eb Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 8 Dec 2018 13:50:17 +0100 Subject: [PATCH] Added IndustrialForegoing compatibility for 1.12.2 --- .../compat/CompatIndustrialForegoing.java | 154 ++++++++++++++++++ .../cr0s/warpdrive/config/Dictionary.java | 1 + .../warpdrive/config/WarpDriveConfig.java | 6 + 3 files changed, 161 insertions(+) create mode 100644 src/main/java/cr0s/warpdrive/compat/CompatIndustrialForegoing.java diff --git a/src/main/java/cr0s/warpdrive/compat/CompatIndustrialForegoing.java b/src/main/java/cr0s/warpdrive/compat/CompatIndustrialForegoing.java new file mode 100644 index 00000000..6089b605 --- /dev/null +++ b/src/main/java/cr0s/warpdrive/compat/CompatIndustrialForegoing.java @@ -0,0 +1,154 @@ +package cr0s.warpdrive.compat; + +import cr0s.warpdrive.api.IBlockTransformer; +import cr0s.warpdrive.api.ITransformation; +import cr0s.warpdrive.api.WarpDriveText; +import cr0s.warpdrive.config.WarpDriveConfig; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class CompatIndustrialForegoing implements IBlockTransformer { + + private static Class classAxisAlignedBlock; + private static Class classBlockConveyor; + private static Class classBlockLabel; + + public static void register() { + try { + classAxisAlignedBlock = Class.forName("net.ndrei.teslacorelib.blocks.AxisAlignedBlock"); + classBlockConveyor = Class.forName("com.buuz135.industrial.proxy.block.BlockConveyor"); + classBlockLabel = Class.forName("com.buuz135.industrial.proxy.block.BlockLabel"); + + WarpDriveConfig.registerBlockTransformer("IndustrialForegoing", new CompatIndustrialForegoing()); + } catch(final ClassNotFoundException exception) { + exception.printStackTrace(); + } + } + + @Override + public boolean isApplicable(final Block block, final int metadata, final TileEntity tileEntity) { + return classAxisAlignedBlock.isInstance(block) + || classBlockConveyor.isInstance(block) + || classBlockLabel.isInstance(block); + } + + @Override + public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, final WarpDriveText reason) { + return true; + } + + @Override + public NBTBase saveExternals(final World world, final int x, final int y, final int z, final Block block, final int blockMeta, final TileEntity tileEntity) { + // nothing to do + return null; + } + + @Override + 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 + } + + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 + private static final byte[] rotFacing = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; + + private static final Map rotFacingNames; + static { + final Map map = new HashMap<>(); + map.put("north", "east"); + map.put("east", "south"); + map.put("south", "west"); + map.put("west", "north"); + rotFacingNames = Collections.unmodifiableMap(map); + } + + @Override + public int rotate(final Block block, final int metadata, final NBTTagCompound nbtTileEntity, final ITransformation transformation) { + final byte rotationSteps = transformation.getRotationSteps(); + if (rotationSteps == 0) { + return metadata; + } + + if (classBlockConveyor.isInstance(block)) { + // facing property + if (nbtTileEntity.hasKey("Facing")) { + final String facing = nbtTileEntity.getString("Facing"); + switch (rotationSteps) { + case 1: + nbtTileEntity.setString("Facing", rotFacingNames.get(facing)); + break; + case 2: + nbtTileEntity.setString("Facing", rotFacingNames.get(rotFacingNames.get(facing))); + break; + case 3: + nbtTileEntity.setString("Facing", rotFacingNames.get(rotFacingNames.get(rotFacingNames.get(facing)))); + break; + default: + break; + } + } + + // upgrades + if (nbtTileEntity.hasKey("Upgrades")) { + final NBTTagCompound tagCompoundUpgrades = nbtTileEntity.getCompoundTag("Upgrades"); + final Map map = new HashMap<>(); + for (final String key : rotFacingNames.keySet()) { + if (tagCompoundUpgrades.hasKey(key)) { + final NBTBase tagBase = tagCompoundUpgrades.getTag(key); + switch (rotationSteps) { + case 1: + map.put(rotFacingNames.get(key), tagBase); + break; + case 2: + map.put(rotFacingNames.get(rotFacingNames.get(key)), tagBase); + break; + case 3: + map.put(rotFacingNames.get(rotFacingNames.get(rotFacingNames.get(key))), tagBase); + break; + default: + map.put(key, tagBase); + break; + } + tagCompoundUpgrades.removeTag(key); + } + } + if (!map.isEmpty()) { + for (final Entry entry : map.entrySet()) { + tagCompoundUpgrades.setTag(entry.getKey(), entry.getValue()); + } + } + } + } + + // vanilla facing + switch (rotationSteps) { + case 1: + return rotFacing[metadata]; + case 2: + return rotFacing[rotFacing[metadata]]; + case 3: + return rotFacing[rotFacing[rotFacing[metadata]]]; + default: + return metadata; + } + } + + @Override + public void restoreExternals(final World world, final BlockPos blockPos, + final IBlockState blockState, final TileEntity tileEntity, + final ITransformation transformation, final NBTBase nbtBase) { + // nothing to do + } +} diff --git a/src/main/java/cr0s/warpdrive/config/Dictionary.java b/src/main/java/cr0s/warpdrive/config/Dictionary.java index f8c53a1b..991d3858 100644 --- a/src/main/java/cr0s/warpdrive/config/Dictionary.java +++ b/src/main/java/cr0s/warpdrive/config/Dictionary.java @@ -145,6 +145,7 @@ public class Dictionary { config.get("block_tags", "ic2:foam" , "PlaceEarliest StopMining").getString(); // @TODO MC1.12 config.get("block_tags", "ic2:blockAlloy" , "PlaceEarliest StopMining").getString(); config.get("block_tags", "ic2:glass" , "PlaceEarliest StopMining").getString(); + config.get("block_tags", "industrialforegoing:black_hole_label" , "PlaceLatest").getString(); config.get("block_tags", "minecraft:obsidian" , "PlaceEarliest Mining").getString(); // config.get("block_tags", "AdvancedRepulsionSystems:field" , "PlaceEarlier StopMining NoBlink").getString(); // config.get("block_tags", "MFFS:field" , "PlaceEarlier StopMining NoBlink").getString(); diff --git a/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java b/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java index ead1052a..9fe07992 100644 --- a/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java +++ b/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java @@ -20,6 +20,7 @@ import cr0s.warpdrive.compat.CompatExtraUtilities2; import cr0s.warpdrive.compat.CompatForgeMultipart; import cr0s.warpdrive.compat.CompatImmersiveEngineering; import cr0s.warpdrive.compat.CompatIndustrialCraft2; +import cr0s.warpdrive.compat.CompatIndustrialForegoing; import cr0s.warpdrive.compat.CompatIronChest; import cr0s.warpdrive.compat.CompatJABBA; import cr0s.warpdrive.compat.CompatMekanism; @@ -1285,6 +1286,11 @@ public class WarpDriveConfig { CompatExtraUtilities2.register(); } + final boolean isIndustrialForegoingLoaded = Loader.isModLoaded("industrialforegoing"); + if (isIndustrialForegoingLoaded) { + CompatIndustrialForegoing.register(); + } + final boolean isIronChestLoaded = Loader.isModLoaded("ironchest"); if (isIronChestLoaded) { CompatIronChest.register();