Merge pull request #1200 from Dimach/unstable-11
Patched ME energy tunnel, now they can emit GT energy.
This commit is contained in:
commit
7a4795f7af
3 changed files with 113 additions and 0 deletions
|
@ -598,6 +598,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);
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package gregtech.loaders.postload;
|
||||
|
||||
import appeng.items.parts.PartType;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
84
src/main/java/gregtech/loaders/postload/PartP2PGTPower.java
Normal file
84
src/main/java/gregtech/loaders/postload/PartP2PGTPower.java
Normal file
|
@ -0,0 +1,84 @@
|
|||
package gregtech.loaders.postload;
|
||||
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.parts.p2p.PartP2PIC2Power;
|
||||
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 (getOfferedEnergy() == 0) {
|
||||
return false;
|
||||
}
|
||||
TileEntity t = getTileEntityAtSide((byte) side.ordinal());
|
||||
if (t instanceof IEnergyConnected) {
|
||||
long voltage = 8 << (getSourceTier() * 2);
|
||||
if (voltage > getOfferedEnergy()) {
|
||||
voltage = (long) getOfferedEnergy();
|
||||
}
|
||||
if (((IEnergyConnected) t).injectEnergyUnits(GT_Utility.getOppositeSide(side.ordinal()), voltage, 1) > 0) {
|
||||
drawEnergy(voltage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode iGridNode) {
|
||||
return new TickingRequest(1, 20, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode iGridNode, int i) {
|
||||
return outputEnergy() ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue