From 6718764aaa00068191b8dfeb0dccc0f7b2844eac Mon Sep 17 00:00:00 2001 From: LemADEC Date: Sun, 17 Apr 2016 03:48:06 +0200 Subject: [PATCH] Added EvilCraft rotation support --- .../warpdrive/compat/CompatEvilCraft.java | 82 +++++++++++++++++++ .../warpdrive/config/WarpDriveConfig.java | 5 ++ 2 files changed, 87 insertions(+) create mode 100644 src/main/java/cr0s/warpdrive/compat/CompatEvilCraft.java diff --git a/src/main/java/cr0s/warpdrive/compat/CompatEvilCraft.java b/src/main/java/cr0s/warpdrive/compat/CompatEvilCraft.java new file mode 100644 index 00000000..038790fc --- /dev/null +++ b/src/main/java/cr0s/warpdrive/compat/CompatEvilCraft.java @@ -0,0 +1,82 @@ +package cr0s.warpdrive.compat; + +import net.minecraft.block.Block; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import cr0s.warpdrive.api.IBlockTransformer; +import cr0s.warpdrive.api.ITransformation; +import cr0s.warpdrive.config.WarpDriveConfig; + +public class CompatEvilCraft implements IBlockTransformer { + + private static Class classBlockConfigurableBlockContainer; + + public static void register() { + try { + classBlockConfigurableBlockContainer = Class.forName("evilcraft.core.config.configurable.ConfigurableBlockContainer"); + WarpDriveConfig.registerBlockTransformer("evilcraft", new CompatEvilCraft()); + } catch(ClassNotFoundException exception) { + exception.printStackTrace(); + } + } + + @Override + public boolean isApplicable(final Block block, final int metadata, final TileEntity tileEntity) { + return classBlockConfigurableBlockContainer.isInstance(block); + } + + @Override + public boolean isJumpReady(final Block block, final int metadata, final TileEntity tileEntity, StringBuilder reason) { + return true; + } + + @Override + public NBTBase saveExternals(final TileEntity tileEntity) { + // nothing to do + return null; + } + + @Override + public void remove(TileEntity tileEntity) { + // nothing to do + } + + private static final int[] rotRotation = { 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, NBTTagCompound nbtTileEntity, final ITransformation transformation) { + byte rotationSteps = transformation.getRotationSteps(); + if (rotationSteps == 0 || nbtTileEntity == null) { + return metadata; + } + + // tile entity rotations + if (nbtTileEntity.hasKey("rotatable")) { + if (!nbtTileEntity.getBoolean("rotatable")) { + return metadata; + } + int rotation = nbtTileEntity.getInteger("rotation"); + switch (rotationSteps) { + case 1: + nbtTileEntity.setInteger("rotation", rotRotation[rotation]); + return metadata; + case 2: + nbtTileEntity.setInteger("rotation", rotRotation[rotRotation[rotation]]); + return metadata; + case 3: + nbtTileEntity.setInteger("rotation", rotRotation[rotRotation[rotRotation[rotation]]]); + return metadata; + default: + return metadata; + } + } + + return metadata; + } + + @Override + public void restoreExternals(TileEntity tileEntity, ITransformation transformation, NBTBase nbtBase) { + // nothing to do + } +} diff --git a/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java b/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java index cfd14593..28f82437 100644 --- a/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java +++ b/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java @@ -27,6 +27,7 @@ import cr0s.warpdrive.compat.CompatArsMagica2; import cr0s.warpdrive.compat.CompatBiblioCraft; import cr0s.warpdrive.compat.CompatComputerCraft; import cr0s.warpdrive.compat.CompatEnderIO; +import cr0s.warpdrive.compat.CompatEvilCraft; import cr0s.warpdrive.compat.CompatImmersiveEngineering; import cr0s.warpdrive.compat.CompatIndustrialCraft2; import cr0s.warpdrive.compat.CompatJABBA; @@ -832,6 +833,10 @@ public class WarpDriveConfig { if (isThaumcraftLoaded) { CompatThaumcraft.register(); } + boolean isEvilCraftLoaded = Loader.isModLoaded("evilcraft"); + if (isEvilCraftLoaded) { + CompatEvilCraft.register(); + } } public static void onFMLPostInitialization() {