Fixed CC:Tweaked support for 1.12

This commit is contained in:
Unknown 2019-04-13 16:04:36 +02:00 committed by unknown
parent 6cdbc4819a
commit 62493a2434
3 changed files with 77 additions and 26 deletions

View file

@ -16,27 +16,43 @@ import net.minecraft.world.World;
public class CompatComputerCraft implements IBlockTransformer {
private static Class<?> classBlockDirectional;
private static Class<?> classBlockGeneric;
private static Class<?> classBlockAdvancedModem;
private static Class<?> classBlockComputerBase;
private static Class<?> classBlockCable;
private static Class<?> classBlockPeripheral;
private static Class<?> classBlockTurtle;
private static Class<?> classBlockWiredModemFull;
public static void register() {
public static void register(final boolean isCCTweakedLoaded) {
try {
classBlockDirectional = Class.forName("dan200.computercraft.shared.common.BlockDirectional");
classBlockComputerBase = Class.forName("dan200.computercraft.shared.computer.blocks.BlockComputerBase");
// BlockCable changed location between original and CC-Tweaked fork
try {
classBlockCable = Class.forName("dan200.computercraft.shared.peripheral.common.BlockCable");
} catch(final ClassNotFoundException exception) {
classBlockCable = Class.forName("dan200.computercraft.shared.peripheral.modem.wired.BlockCable");
WarpDrive.logger.info("CC-Tweaked detected...");
// several changes are introduced in the CC-Tweaked fork, notably:
// - non-ticking tile entities are separated
// - BlockCable changed location
if (!isCCTweakedLoaded) {// original mod
WarpDrive.logger.info("Loading ComputerCraft compatibility with its original flavor...");
classBlockGeneric = Class.forName("dan200.computercraft.shared.common.BlockGeneric");
classBlockAdvancedModem = Class.forName("dan200.computercraft.shared.peripheral.modem.BlockAdvancedModem");
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());
} catch(final ClassNotFoundException exception) {
exception.printStackTrace();
@ -45,7 +61,8 @@ public class CompatComputerCraft implements IBlockTransformer {
@Override
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
@ -65,14 +82,20 @@ public class CompatComputerCraft implements IBlockTransformer {
// nothing to do
}
// CC-Computer rotations
private static final int[] mrotComputer = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 13, 12, 10, 11, 14, 15 }; // computer (normal/advanced)
// CC-Peripheral rotations
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)
// CC-Cable rotations
private static final int[] mrotWiredModem = { 0, 1, 5, 4, 2, 3, 6, 7, 11, 10, 8, 9, 12, 13, 14, 15 }; // wired modem, cable
// NBT rotations for printer, monitor and turtles
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
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// computer rotations: normal (2-5), advanced (8-13)
private static final int[] mrotComputer = { 0, 1, 5, 4, 2, 3, 6, 7, 8, 9, 13, 12, 10, 11, 14, 15 };
// peripheral rotations: wireless modem (0-1/6-9), disk drive (2-5), monitor (10/12), printer (11), speaker (13)
private static final int[] mrotPeripheral = { 0, 1, 5, 4, 2, 3, 9, 8, 6, 7, 10, 11, 12, 13, 14, 15 };
// cable rotations: wired modem (0-5), with cable (6-11), just cable (13)
private static final int[] mrotWiredModem = { 0, 1, 5, 4, 2, 3, 6, 7, 11, 10, 8, 9, 12, 13, 14, 15 };
// 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
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;
}
if (classBlockComputerBase.isInstance(block) && !classBlockTurtle.isInstance(block)) {
// computers are rotating with metadata only
if ( classBlockComputerBase.isInstance(block)
&& !classBlockTurtle.isInstance(block) ) {
switch (rotationSteps) {
case 1:
return mrotComputer[metadata];
@ -93,6 +118,8 @@ public class CompatComputerCraft implements IBlockTransformer {
return metadata;
}
}
// cables are rotating with metadata only
if (classBlockCable.isInstance(block)) {
switch (rotationSteps) {
case 1:
@ -105,8 +132,26 @@ public class CompatComputerCraft implements IBlockTransformer {
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 (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) {
case 1:
return mrotPeripheral[metadata];
@ -118,17 +163,20 @@ public class CompatComputerCraft implements IBlockTransformer {
return metadata;
}
}
// monitor, printer and speaker are rotating with NBT only through the dir tag
if (!nbtTileEntity.hasKey("dir")) {// unknown
WarpDrive.logger.error(String.format("Unknown ComputerCraft Peripheral block %s with metadata %d and tile entity %s",
block, metadata, nbtTileEntity));
return metadata;
}
// printer or monitor have the dir tag
} else if (!nbtTileEntity.hasKey("dir")) {// unknown
WarpDrive.logger.error(String.format("Unknown ComputerCraft directional block %s with metadata %d and tile entity %s",
block, metadata, nbtTileEntity));
return metadata;
}
// turtles and others
final int dir = nbtTileEntity.getInteger("dir");
switch (rotationSteps) {

View file

@ -221,6 +221,7 @@ public class Dictionary {
// config.get("block_tags", "AdvancedRepulsionSystems:field" , "PlaceEarlier StopMining NoBlink").getString();
config.get("block_tags", "advancedrocketry:forcefield" , "PlaceLatest StopMining NoMass").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:unlit_torch" , "PlaceLatest").getString();
config.get("block_tags", "galacticraftcore:unlit_torch_lit" , "PlaceLatest").getString();

View file

@ -137,6 +137,7 @@ public class WarpDriveConfig {
public static boolean isAdvancedRepulsionSystemLoaded = false;
public static boolean isRedstoneFluxLoaded = false;
public static boolean isComputerCraftLoaded = false;
public static boolean isCCTweakedLoaded = false;
public static boolean isEnderIOLoaded = false;
public static boolean isForgeMultipartLoaded = false;
public static boolean isGregtechLoaded = false;
@ -713,6 +714,7 @@ public class WarpDriveConfig {
// read mod dependencies at runtime and for recipes
isRedstoneFluxLoaded = Loader.isModLoaded("redstoneflux");
isComputerCraftLoaded = Loader.isModLoaded("computercraft");
isCCTweakedLoaded = Loader.isModLoaded("cctweaked");
isEnderIOLoaded = Loader.isModLoaded("enderio");
isGregtechLoaded = Loader.isModLoaded("gregtech");
isIndustrialCraft2Loaded = Loader.isModLoaded("ic2");
@ -1346,7 +1348,7 @@ public class WarpDriveConfig {
}
if (isComputerCraftLoaded) {
CompatComputerCraft.register();
CompatComputerCraft.register(isCCTweakedLoaded);
}
if (isEnderIOLoaded) {