Fixed CC:Tweaked support for 1.12
This commit is contained in:
parent
6cdbc4819a
commit
62493a2434
3 changed files with 77 additions and 26 deletions
|
@ -16,27 +16,43 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
public class CompatComputerCraft implements IBlockTransformer {
|
public class CompatComputerCraft implements IBlockTransformer {
|
||||||
|
|
||||||
private static Class<?> classBlockDirectional;
|
private static Class<?> classBlockGeneric;
|
||||||
|
|
||||||
|
private static Class<?> classBlockAdvancedModem;
|
||||||
private static Class<?> classBlockComputerBase;
|
private static Class<?> classBlockComputerBase;
|
||||||
private static Class<?> classBlockCable;
|
private static Class<?> classBlockCable;
|
||||||
private static Class<?> classBlockPeripheral;
|
private static Class<?> classBlockPeripheral;
|
||||||
private static Class<?> classBlockTurtle;
|
private static Class<?> classBlockTurtle;
|
||||||
|
private static Class<?> classBlockWiredModemFull;
|
||||||
|
|
||||||
public static void register() {
|
public static void register(final boolean isCCTweakedLoaded) {
|
||||||
try {
|
try {
|
||||||
classBlockDirectional = Class.forName("dan200.computercraft.shared.common.BlockDirectional");
|
// several changes are introduced in the CC-Tweaked fork, notably:
|
||||||
classBlockComputerBase = Class.forName("dan200.computercraft.shared.computer.blocks.BlockComputerBase");
|
// - non-ticking tile entities are separated
|
||||||
|
// - BlockCable changed location
|
||||||
// BlockCable changed location between original and CC-Tweaked fork
|
if (!isCCTweakedLoaded) {// original mod
|
||||||
try {
|
WarpDrive.logger.info("Loading ComputerCraft compatibility with its original flavor...");
|
||||||
classBlockCable = Class.forName("dan200.computercraft.shared.peripheral.common.BlockCable");
|
classBlockGeneric = Class.forName("dan200.computercraft.shared.common.BlockGeneric");
|
||||||
} catch(final ClassNotFoundException exception) {
|
|
||||||
classBlockCable = Class.forName("dan200.computercraft.shared.peripheral.modem.wired.BlockCable");
|
classBlockAdvancedModem = Class.forName("dan200.computercraft.shared.peripheral.modem.BlockAdvancedModem");
|
||||||
WarpDrive.logger.info("CC-Tweaked detected...");
|
classBlockComputerBase = Class.forName("dan200.computercraft.shared.computer.blocks.BlockComputerBase");
|
||||||
|
classBlockCable = Class.forName("dan200.computercraft.shared.peripheral.common.BlockCable");
|
||||||
|
classBlockPeripheral = Class.forName("dan200.computercraft.shared.peripheral.common.BlockPeripheral");
|
||||||
|
classBlockTurtle = Class.forName("dan200.computercraft.shared.turtle.blocks.BlockTurtle");
|
||||||
|
classBlockWiredModemFull = null;
|
||||||
|
|
||||||
|
} else {// CC-Tweaked fork
|
||||||
|
WarpDrive.logger.info("Loading ComputerCraft compatibility with its CC-Tweaked fork...");
|
||||||
|
classBlockGeneric = Class.forName("dan200.computercraft.shared.common.BlockGeneric");
|
||||||
|
|
||||||
|
classBlockAdvancedModem = Class.forName("dan200.computercraft.shared.peripheral.modem.wireless.BlockAdvancedModem");
|
||||||
|
classBlockComputerBase = Class.forName("dan200.computercraft.shared.computer.blocks.BlockComputerBase");
|
||||||
|
classBlockCable = Class.forName("dan200.computercraft.shared.peripheral.modem.wired.BlockCable");
|
||||||
|
classBlockPeripheral = Class.forName("dan200.computercraft.shared.peripheral.common.BlockPeripheral");
|
||||||
|
classBlockTurtle = Class.forName("dan200.computercraft.shared.turtle.blocks.BlockTurtle");
|
||||||
|
classBlockWiredModemFull = Class.forName("dan200.computercraft.shared.peripheral.modem.wired.BlockWiredModemFull");
|
||||||
}
|
}
|
||||||
|
|
||||||
classBlockPeripheral = Class.forName("dan200.computercraft.shared.peripheral.common.BlockPeripheral");
|
|
||||||
classBlockTurtle = Class.forName("dan200.computercraft.shared.turtle.blocks.BlockTurtle");
|
|
||||||
WarpDriveConfig.registerBlockTransformer("computercraft", new CompatComputerCraft());
|
WarpDriveConfig.registerBlockTransformer("computercraft", new CompatComputerCraft());
|
||||||
} catch(final ClassNotFoundException exception) {
|
} catch(final ClassNotFoundException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
|
@ -45,7 +61,8 @@ public class CompatComputerCraft 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 classBlockDirectional.isInstance(block);
|
return classBlockGeneric.isInstance(block)
|
||||||
|
&& (classBlockWiredModemFull == null || !classBlockWiredModemFull.isInstance(block));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,14 +82,20 @@ public class CompatComputerCraft implements IBlockTransformer {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
// CC-Computer rotations
|
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
||||||
private static final int[] mrotComputer = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 13, 12, 10, 11, 14, 15 }; // computer (normal/advanced)
|
// computer rotations: normal (2-5), advanced (8-13)
|
||||||
// CC-Peripheral rotations
|
private static final int[] mrotComputer = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 13, 12, 10, 11, 14, 15 };
|
||||||
private static final int[] mrotPeripheral = { 0, 1, 5, 4, 2, 3, 9, 8, 6, 7, 10, 11, 12, 13, 14, 15 }; // disk drive (2-5), wireless modem (0-1/6-9), monitor (10/12), printer (11)
|
// peripheral rotations: wireless modem (0-1/6-9), disk drive (2-5), monitor (10/12), printer (11), speaker (13)
|
||||||
// CC-Cable rotations
|
private static final int[] mrotPeripheral = { 0, 1, 5, 4, 2, 3, 9, 8, 6, 7, 10, 11, 12, 13, 14, 15 };
|
||||||
private static final int[] mrotWiredModem = { 0, 1, 5, 4, 2, 3, 6, 7, 11, 10, 8, 9, 12, 13, 14, 15 }; // wired modem, cable
|
// cable rotations: wired modem (0-5), with cable (6-11), just cable (13)
|
||||||
// NBT rotations for printer, monitor and turtles
|
private static final int[] mrotWiredModem = { 0, 1, 5, 4, 2, 3, 6, 7, 11, 10, 8, 9, 12, 13, 14, 15 };
|
||||||
private static final int[] rotDir = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; // printer, monitor, turtle
|
// advanced modem rotations: wired modem (0-5), with cable (6-11), just cable (13)
|
||||||
|
private static final int[] mrotAdvancedModem = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
|
||||||
|
|
||||||
|
// NBT rotations for monitor, printer, speaker and turtles
|
||||||
|
// printer, speaker and turtle rotation is 2 5 3 4
|
||||||
|
// monitor rotation is 2 5 3 4 / 8 11 9 10 / 14 17 15 16
|
||||||
|
private static final int[] rotDir = { 0, 1, 5, 4, 2, 3, 6, 7, 11, 10, 8, 9, 12, 13, 17, 16, 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) {
|
||||||
|
@ -81,7 +104,9 @@ public class CompatComputerCraft implements IBlockTransformer {
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classBlockComputerBase.isInstance(block) && !classBlockTurtle.isInstance(block)) {
|
// computers are rotating with metadata only
|
||||||
|
if ( classBlockComputerBase.isInstance(block)
|
||||||
|
&& !classBlockTurtle.isInstance(block) ) {
|
||||||
switch (rotationSteps) {
|
switch (rotationSteps) {
|
||||||
case 1:
|
case 1:
|
||||||
return mrotComputer[metadata];
|
return mrotComputer[metadata];
|
||||||
|
@ -93,6 +118,8 @@ public class CompatComputerCraft implements IBlockTransformer {
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cables are rotating with metadata only
|
||||||
if (classBlockCable.isInstance(block)) {
|
if (classBlockCable.isInstance(block)) {
|
||||||
switch (rotationSteps) {
|
switch (rotationSteps) {
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -105,8 +132,26 @@ public class CompatComputerCraft implements IBlockTransformer {
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// advanced modems are rotating with metadata only
|
||||||
|
if (classBlockAdvancedModem.isInstance(block)) {
|
||||||
|
switch (rotationSteps) {
|
||||||
|
case 1:
|
||||||
|
return mrotAdvancedModem[metadata];
|
||||||
|
case 2:
|
||||||
|
return mrotAdvancedModem[mrotAdvancedModem[metadata]];
|
||||||
|
case 3:
|
||||||
|
return mrotAdvancedModem[mrotAdvancedModem[mrotAdvancedModem[metadata]]];
|
||||||
|
default:
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// disk drive, wireless modem, monitor, printer are over optimized...
|
||||||
if (classBlockPeripheral.isInstance(block)) {
|
if (classBlockPeripheral.isInstance(block)) {
|
||||||
if (metadata >= 2 && metadata <= 9) {// disk drive, wireless modem, monitor, printer
|
// disk drive and wireless modem are rotating with metadata only
|
||||||
|
if ( metadata >= 0
|
||||||
|
&& metadata <= 9 ) {
|
||||||
switch (rotationSteps) {
|
switch (rotationSteps) {
|
||||||
case 1:
|
case 1:
|
||||||
return mrotPeripheral[metadata];
|
return mrotPeripheral[metadata];
|
||||||
|
@ -118,17 +163,20 @@ public class CompatComputerCraft implements IBlockTransformer {
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// monitor, printer and speaker are rotating with NBT only through the dir tag
|
||||||
if (!nbtTileEntity.hasKey("dir")) {// unknown
|
if (!nbtTileEntity.hasKey("dir")) {// unknown
|
||||||
WarpDrive.logger.error(String.format("Unknown ComputerCraft Peripheral block %s with metadata %d and tile entity %s",
|
WarpDrive.logger.error(String.format("Unknown ComputerCraft Peripheral block %s with metadata %d and tile entity %s",
|
||||||
block, metadata, nbtTileEntity));
|
block, metadata, nbtTileEntity));
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
// printer or monitor have the dir tag
|
|
||||||
} else if (!nbtTileEntity.hasKey("dir")) {// unknown
|
} else if (!nbtTileEntity.hasKey("dir")) {// unknown
|
||||||
WarpDrive.logger.error(String.format("Unknown ComputerCraft directional block %s with metadata %d and tile entity %s",
|
WarpDrive.logger.error(String.format("Unknown ComputerCraft directional block %s with metadata %d and tile entity %s",
|
||||||
block, metadata, nbtTileEntity));
|
block, metadata, nbtTileEntity));
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
// turtles and others
|
// turtles and others
|
||||||
final int dir = nbtTileEntity.getInteger("dir");
|
final int dir = nbtTileEntity.getInteger("dir");
|
||||||
switch (rotationSteps) {
|
switch (rotationSteps) {
|
||||||
|
|
|
@ -221,6 +221,7 @@ public class Dictionary {
|
||||||
// config.get("block_tags", "AdvancedRepulsionSystems:field" , "PlaceEarlier StopMining NoBlink").getString();
|
// config.get("block_tags", "AdvancedRepulsionSystems:field" , "PlaceEarlier StopMining NoBlink").getString();
|
||||||
config.get("block_tags", "advancedrocketry:forcefield" , "PlaceLatest StopMining NoMass").getString();
|
config.get("block_tags", "advancedrocketry:forcefield" , "PlaceLatest StopMining NoMass").getString();
|
||||||
config.get("block_tags", "embers:caminite_lever" , "PlaceLatest").getString();
|
config.get("block_tags", "embers:caminite_lever" , "PlaceLatest").getString();
|
||||||
|
config.get("block_tags", "computercraft:advanced_modem" , "PlaceLatest").getString();
|
||||||
config.get("block_tags", "galacticraftcore:glowstone_torch" , "PlaceLatest").getString();
|
config.get("block_tags", "galacticraftcore:glowstone_torch" , "PlaceLatest").getString();
|
||||||
config.get("block_tags", "galacticraftcore:unlit_torch" , "PlaceLatest").getString();
|
config.get("block_tags", "galacticraftcore:unlit_torch" , "PlaceLatest").getString();
|
||||||
config.get("block_tags", "galacticraftcore:unlit_torch_lit" , "PlaceLatest").getString();
|
config.get("block_tags", "galacticraftcore:unlit_torch_lit" , "PlaceLatest").getString();
|
||||||
|
|
|
@ -137,6 +137,7 @@ public class WarpDriveConfig {
|
||||||
public static boolean isAdvancedRepulsionSystemLoaded = false;
|
public static boolean isAdvancedRepulsionSystemLoaded = false;
|
||||||
public static boolean isRedstoneFluxLoaded = false;
|
public static boolean isRedstoneFluxLoaded = false;
|
||||||
public static boolean isComputerCraftLoaded = false;
|
public static boolean isComputerCraftLoaded = false;
|
||||||
|
public static boolean isCCTweakedLoaded = false;
|
||||||
public static boolean isEnderIOLoaded = false;
|
public static boolean isEnderIOLoaded = false;
|
||||||
public static boolean isForgeMultipartLoaded = false;
|
public static boolean isForgeMultipartLoaded = false;
|
||||||
public static boolean isGregtechLoaded = false;
|
public static boolean isGregtechLoaded = false;
|
||||||
|
@ -713,6 +714,7 @@ public class WarpDriveConfig {
|
||||||
// read mod dependencies at runtime and for recipes
|
// read mod dependencies at runtime and for recipes
|
||||||
isRedstoneFluxLoaded = Loader.isModLoaded("redstoneflux");
|
isRedstoneFluxLoaded = Loader.isModLoaded("redstoneflux");
|
||||||
isComputerCraftLoaded = Loader.isModLoaded("computercraft");
|
isComputerCraftLoaded = Loader.isModLoaded("computercraft");
|
||||||
|
isCCTweakedLoaded = Loader.isModLoaded("cctweaked");
|
||||||
isEnderIOLoaded = Loader.isModLoaded("enderio");
|
isEnderIOLoaded = Loader.isModLoaded("enderio");
|
||||||
isGregtechLoaded = Loader.isModLoaded("gregtech");
|
isGregtechLoaded = Loader.isModLoaded("gregtech");
|
||||||
isIndustrialCraft2Loaded = Loader.isModLoaded("ic2");
|
isIndustrialCraft2Loaded = Loader.isModLoaded("ic2");
|
||||||
|
@ -1346,7 +1348,7 @@ public class WarpDriveConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isComputerCraftLoaded) {
|
if (isComputerCraftLoaded) {
|
||||||
CompatComputerCraft.register();
|
CompatComputerCraft.register(isCCTweakedLoaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEnderIOLoaded) {
|
if (isEnderIOLoaded) {
|
||||||
|
|
Loading…
Reference in a new issue