From ded594c86c701a0ff1f2282b4d6bff9cc7b1b9f6 Mon Sep 17 00:00:00 2001 From: Dimach Date: Sun, 27 Aug 2017 01:55:20 +0300 Subject: [PATCH] Patched ME energy tunnel, now they can emit GT energy. --- .../java/appeng/parts/p2p/PartP2PGTPower.java | 86 +++++++++++++++++++ src/main/java/gregtech/GT_Mod.java | 1 + .../postload/GT_AE2EnergyTunnelLoader.java | 29 +++++++ 3 files changed, 116 insertions(+) create mode 100644 src/main/java/appeng/parts/p2p/PartP2PGTPower.java create mode 100644 src/main/java/gregtech/loaders/postload/GT_AE2EnergyTunnelLoader.java diff --git a/src/main/java/appeng/parts/p2p/PartP2PGTPower.java b/src/main/java/appeng/parts/p2p/PartP2PGTPower.java new file mode 100644 index 00000000..a4fc3ce2 --- /dev/null +++ b/src/main/java/appeng/parts/p2p/PartP2PGTPower.java @@ -0,0 +1,86 @@ +package appeng.parts.p2p; + +import appeng.api.networking.IGridNode; +import appeng.api.networking.ticking.IGridTickable; +import appeng.api.networking.ticking.TickRateModulation; +import appeng.api.networking.ticking.TickingRequest; +import gregtech.api.interfaces.tileentity.IEnergyConnected; +import gregtech.api.util.GT_Utility; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public class PartP2PGTPower extends PartP2PIC2Power implements IGridTickable { + public PartP2PGTPower(ItemStack is) { + super(is); + } + + public final World getWorld() { + return tile.getWorldObj(); + } + + public final int getXCoord() { + return tile.xCoord; + } + + public final short getYCoord() { + return (short) tile.yCoord; + } + + public final int getZCoord() { + return tile.zCoord; + } + + public final int getOffsetX(byte aSide, int aMultiplier) { + return getXCoord() + ForgeDirection.getOrientation(aSide).offsetX * aMultiplier; + } + + public final short getOffsetY(byte aSide, int aMultiplier) { + return (short) (getYCoord() + ForgeDirection.getOrientation(aSide).offsetY * aMultiplier); + } + + public final int getOffsetZ(byte aSide, int aMultiplier) { + return getZCoord() + ForgeDirection.getOrientation(aSide).offsetZ * aMultiplier; + } + + public final TileEntity getTileEntity(int aX, int aY, int aZ) { + return getWorld().getTileEntity(aX, aY, aZ); + } + + public final TileEntity getTileEntityAtSide(byte aSide) { + int tX = getOffsetX(aSide, 1), tY = getOffsetY(aSide, 1), tZ = getOffsetZ(aSide, 1); + return getWorld().getTileEntity(tX, tY, tZ); + } + + public boolean outputEnergy() { + if (OutputEnergyA == 0) { + return false; + } + TileEntity t = getTileEntityAtSide((byte) side.ordinal()); + if (t instanceof IEnergyConnected) { + long l = ((IEnergyConnected) t).injectEnergyUnits(GT_Utility.getOppositeSide(side.ordinal()), (long) OutputVoltageA, ((long) OutputEnergyA) / ((long) OutputVoltageA)); + if (l > 0) { + OutputEnergyA -= ((long) OutputVoltageA) * l; + if (OutputEnergyA < 1) { + OutputEnergyA = OutputEnergyB; + OutputVoltageA = OutputVoltageB; + OutputEnergyB = 0; + OutputVoltageB = 0; + } + return true; + } + } + return false; + } + + @Override + public TickingRequest getTickingRequest(IGridNode iGridNode) { + return new TickingRequest(1, 10, false, false); + } + + @Override + public TickRateModulation tickingRequest(IGridNode iGridNode, int i) { + return outputEnergy() ? TickRateModulation.FASTER : TickRateModulation.SLOWER; + } +} diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index 7ab912b7..5c3a660a 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -597,6 +597,7 @@ public class GT_Mod implements IGT_Mod { new GT_CropLoader().run(); new GT_Worldgenloader().run(); new GT_CoverLoader().run(); + new GT_AE2EnergyTunnelLoader().run(); LoadArmorComponents.init(); GT_RecipeRegistrator.registerUsagesForMaterials(new ItemStack(Blocks.planks, 1), null, false); diff --git a/src/main/java/gregtech/loaders/postload/GT_AE2EnergyTunnelLoader.java b/src/main/java/gregtech/loaders/postload/GT_AE2EnergyTunnelLoader.java new file mode 100644 index 00000000..c6f753d7 --- /dev/null +++ b/src/main/java/gregtech/loaders/postload/GT_AE2EnergyTunnelLoader.java @@ -0,0 +1,29 @@ +package gregtech.loaders.postload; + +import appeng.items.parts.PartType; +import appeng.parts.p2p.PartP2PGTPower; +import gregtech.GT_Mod; +import gregtech.api.util.GT_Log; + +import java.lang.reflect.Field; + +public class GT_AE2EnergyTunnelLoader implements Runnable { + @Override + public void run() { + if (GT_Mod.gregtechproxy.mAE2Integration) { + try { + load(); + } catch (Throwable e) { + GT_Log.out.println("Failed to load P2P tunnel for GT electricity"); + e.printStackTrace(GT_Log.out); + } + } + } + + public void load() throws Throwable { + Field f = PartType.class.getDeclaredField("myPart"); + f.setAccessible(true); + f.set(PartType.P2PTunnelEU, PartP2PGTPower.class); + } +} +