From 0b04d2853e74d8fde8a06091c6a6edb96fd9d3c6 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Tue, 20 May 2014 22:06:37 -0500 Subject: [PATCH] Add backwards support for MJ5 ( from MJ6 ) Add another try catch facade test... --- integration/abstraction/IMJ6.java | 5 ++ integration/modules/BC.java | 11 ++++- integration/modules/MJ6.java | 82 ++++++++++++++++++++++++++++++- parts/p2p/PartP2PBCPower.java | 18 +++---- 4 files changed, 104 insertions(+), 12 deletions(-) diff --git a/integration/abstraction/IMJ6.java b/integration/abstraction/IMJ6.java index 4ed7cb13..78c8712a 100644 --- a/integration/abstraction/IMJ6.java +++ b/integration/abstraction/IMJ6.java @@ -1,7 +1,12 @@ package appeng.integration.abstraction; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.mj.IBatteryObject; public interface IMJ6 { + IBatteryObject provider(TileEntity te, ForgeDirection side); + } diff --git a/integration/modules/BC.java b/integration/modules/BC.java index 79ba13d5..17babcd7 100644 --- a/integration/modules/BC.java +++ b/integration/modules/BC.java @@ -121,11 +121,18 @@ public class BC extends BaseModule implements IBC try { - return is.getItem() instanceof ItemFacade && ItemFacade.getType( is ) == ItemFacade.TYPE_BASIC; + return is.getItem() instanceof ItemFacade && ItemFacade.getType( is ) == ItemFacade.FacadeType.Basic; } catch (Throwable t) { - return is.getItem() instanceof ItemFacade; + try + { + return is.getItem() instanceof ItemFacade && ItemFacade.getType( is ) == ItemFacade.TYPE_BASIC; + } + catch (Throwable g) + { + return is.getItem() instanceof ItemFacade; + } } } diff --git a/integration/modules/MJ6.java b/integration/modules/MJ6.java index e47c38ee..ed61940c 100644 --- a/integration/modules/MJ6.java +++ b/integration/modules/MJ6.java @@ -1,10 +1,17 @@ package appeng.integration.modules; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; import appeng.integration.BaseModule; import appeng.integration.abstraction.IMJ6; +import appeng.transformer.annotations.integration.Method; import buildcraft.api.mj.IBatteryObject; import buildcraft.api.mj.IBatteryProvider; import buildcraft.api.mj.ISidedBatteryProvider; +import buildcraft.api.mj.MjAPI; +import buildcraft.api.power.IPowerReceptor; +import buildcraft.api.power.PowerHandler.PowerReceiver; +import buildcraft.api.power.PowerHandler.Type; public class MJ6 extends BaseModule implements IMJ6 { @@ -15,7 +22,6 @@ public class MJ6 extends BaseModule implements IMJ6 TestClass( IBatteryObject.class ); TestClass( IBatteryProvider.class ); TestClass( ISidedBatteryProvider.class ); - throw new RuntimeException( "Disabled For Now!" ); } @Override @@ -28,4 +34,78 @@ public class MJ6 extends BaseModule implements IMJ6 { } + @Override + @Method(iname = "MJ5") + public IBatteryObject provider(final TileEntity te, final ForgeDirection side) + { + if ( te instanceof IPowerReceptor ) + { + final IPowerReceptor recp = (IPowerReceptor) te; + final PowerReceiver ph = recp.getPowerReceiver( side ); + + return new IBatteryObject() { + + @Override + public void setEnergyStored(double mj) + { + + } + + @Override + public IBatteryObject reconfigure(double maxCapacity, double maxReceivedPerCycle, double minimumConsumption) + { + return this; + } + + @Override + public double minimumConsumption() + { + return ph.getMinEnergyReceived(); + } + + @Override + public double maxReceivedPerCycle() + { + return ph.getMaxEnergyReceived(); + } + + @Override + public double maxCapacity() + { + return ph.getMaxEnergyStored(); + } + + @Override + public String kind() + { + return MjAPI.DEFAULT_POWER_FRAMEWORK; + } + + @Override + public double getEnergyStored() + { + return ph.getEnergyStored(); + } + + @Override + public double getEnergyRequested() + { + return ph.getMaxEnergyStored() - ph.getEnergyStored(); + } + + @Override + public double addEnergy(double mj, boolean ignoreCycleLimit) + { + return ph.receiveEnergy( Type.PIPE, mj, side ); + } + + @Override + public double addEnergy(double mj) + { + return ph.receiveEnergy( Type.PIPE, mj, side ); + } + }; + } + return null; + } } diff --git a/parts/p2p/PartP2PBCPower.java b/parts/p2p/PartP2PBCPower.java index 835f1b8b..c326f81c 100644 --- a/parts/p2p/PartP2PBCPower.java +++ b/parts/p2p/PartP2PBCPower.java @@ -16,6 +16,7 @@ import appeng.api.networking.ticking.TickingRequest; import appeng.core.AppEng; import appeng.core.settings.TickRates; import appeng.integration.abstraction.IMJ5; +import appeng.integration.abstraction.IMJ6; import appeng.integration.abstraction.helpers.BaseMJperdition; import appeng.me.GridAccessException; import appeng.me.cache.helpers.TunnelCollection; @@ -153,7 +154,13 @@ public class PartP2PBCPower extends PartP2PTunnel implements IPo { TileEntity te = getWorld().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ ); if ( te != null ) - return MjAPI.getMjBattery( te ); + { + IBatteryObject bo = MjAPI.getMjBattery( te, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite() ); + if ( bo != null ) + return bo; + if ( AppEng.instance.isIntegrationEnabled( "MJ5" ) ) + return ((IMJ6) AppEng.instance.getIntegration( "MJ6" )).provider( te, side.getOpposite() ); + } return null; } @@ -213,13 +220,6 @@ public class PartP2PBCPower extends PartP2PTunnel implements IPo return tile.getWorldObj(); } - @Override - @Method(iname = "MJ6") - public IBatteryObject getMjBattery(String kind) - { - return this; - } - @Override @Method(iname = "MJ6") public IBatteryObject getMjBattery(String kind, ForgeDirection direction) @@ -267,7 +267,7 @@ public class PartP2PBCPower extends PartP2PTunnel implements IPo @Method(iname = "MJ6") private double addEnergyInternal(double mj, boolean cycleLimitMode, boolean ignoreCycleLimit) { - if ( !output && proxy.isActive() ) + if ( output || !proxy.isActive() ) return 0; double originaInput = mj;