Added AdvancedRepulsionSystems rotation support
This commit is contained in:
parent
e355e614c5
commit
2191726198
2 changed files with 123 additions and 0 deletions
|
@ -0,0 +1,119 @@
|
|||
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 CompatAdvancedRepulsionSystems implements IBlockTransformer {
|
||||
|
||||
private static Class<?> classBlockDFDoor;
|
||||
private static Class<?> classBlockMachine;
|
||||
private static Class<?> classBlockUpgrades;
|
||||
private static Class<?> classBlockBeam;
|
||||
|
||||
public static void register() {
|
||||
try {
|
||||
classBlockDFDoor = Class.forName("mods.immibis.ars.DeFence.BlockDFDoor");
|
||||
classBlockBeam = Class.forName("mods.immibis.ars.beams.BlockBeam");
|
||||
classBlockMachine = Class.forName("mods.immibis.ars.BlockMachine");
|
||||
classBlockUpgrades = Class.forName("mods.immibis.ars.BlockUpgrades");
|
||||
WarpDriveConfig.registerBlockTransformer("AdvancedRepulsionSystems", new CompatAdvancedRepulsionSystems());
|
||||
} catch(ClassNotFoundException | SecurityException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(final Block block, final int metadata, final TileEntity tileEntity) {
|
||||
return classBlockDFDoor.isInstance(block)
|
||||
|| classBlockBeam.isInstance(block)
|
||||
|| classBlockMachine.isInstance(block)
|
||||
|| classBlockUpgrades.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
|
||||
}
|
||||
|
||||
// { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
|
||||
private static final byte[] mrotBeam = { 0, 1, 5, 4, 2, 3, 6, 7, 11, 10, 8, 9, 12, 13, 14, 15 };
|
||||
private static final short[] rotFacing = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
|
||||
private static final byte[] rotOutputFace = { 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) {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
if (classBlockBeam.isInstance(block)) {
|
||||
switch (rotationSteps) {
|
||||
case 1:
|
||||
return mrotBeam[metadata];
|
||||
case 2:
|
||||
return mrotBeam[mrotBeam[metadata]];
|
||||
case 3:
|
||||
return mrotBeam[mrotBeam[mrotBeam[metadata]]];
|
||||
default:
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
|
||||
if (nbtTileEntity.hasKey("facing")) {
|
||||
short facing = nbtTileEntity.getShort("facing");
|
||||
switch (rotationSteps) {
|
||||
case 1:
|
||||
nbtTileEntity.setShort("facing", rotFacing[facing]);
|
||||
return metadata;
|
||||
case 2:
|
||||
nbtTileEntity.setShort("facing", rotFacing[rotFacing[facing]]);
|
||||
return metadata;
|
||||
case 3:
|
||||
nbtTileEntity.setShort("facing", rotFacing[rotFacing[rotFacing[facing]]]);
|
||||
return metadata;
|
||||
default:
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
|
||||
if (nbtTileEntity.hasKey("outputFace")) {
|
||||
byte outputFace = nbtTileEntity.getByte("outputFace");
|
||||
switch (rotationSteps) {
|
||||
case 1:
|
||||
nbtTileEntity.setByte("outputFace", rotOutputFace[outputFace]);
|
||||
return metadata;
|
||||
case 2:
|
||||
nbtTileEntity.setByte("outputFace", rotOutputFace[rotOutputFace[outputFace]]);
|
||||
return metadata;
|
||||
case 3:
|
||||
nbtTileEntity.setByte("outputFace", rotOutputFace[rotOutputFace[rotOutputFace[outputFace]]]);
|
||||
return metadata;
|
||||
default:
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreExternals(TileEntity tileEntity, ITransformation transformation, NBTBase nbtBase) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ import cpw.mods.fml.common.Loader;
|
|||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.IBlockTransformer;
|
||||
import cr0s.warpdrive.compat.CompatAdvancedRepulsionSystems;
|
||||
import cr0s.warpdrive.compat.CompatAppliedEnergistics2;
|
||||
import cr0s.warpdrive.compat.CompatArsMagica2;
|
||||
import cr0s.warpdrive.compat.CompatBiblioCraft;
|
||||
|
@ -797,6 +798,9 @@ public class WarpDriveConfig {
|
|||
CompatEnderIO.register();
|
||||
}
|
||||
isAdvancedRepulsionSystemLoaded = Loader.isModLoaded("AdvancedRepulsionSystems");
|
||||
if (isAdvancedRepulsionSystemLoaded) {
|
||||
CompatAdvancedRepulsionSystems.register();
|
||||
}
|
||||
|
||||
boolean isBotaniaLoaded = Loader.isModLoaded("Botania");
|
||||
if (isBotaniaLoaded) {
|
||||
|
|
Loading…
Reference in a new issue