Added IC2 integration.
This commit is contained in:
parent
623e9eea3c
commit
344958aefb
58
src/main/java/appeng/integration/modules/IC2.java
Normal file
58
src/main/java/appeng/integration/modules/IC2.java
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Applied Energistics 2.
|
||||||
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package appeng.integration.modules;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import appeng.helpers.Reflected;
|
||||||
|
import appeng.integration.IIntegrationModule;
|
||||||
|
import appeng.integration.modules.ic2.IC2PowerSink;
|
||||||
|
import appeng.integration.modules.ic2.IC2PowerSinkAdapter;
|
||||||
|
import appeng.integration.modules.ic2.IC2PowerSinkStub;
|
||||||
|
import appeng.tile.powersink.IExternalPowerSink;
|
||||||
|
|
||||||
|
|
||||||
|
public class IC2 implements IIntegrationModule
|
||||||
|
{
|
||||||
|
|
||||||
|
@Reflected
|
||||||
|
public static IC2 instance;
|
||||||
|
|
||||||
|
private Function<IExternalPowerSink, IC2PowerSink> powerSinkFactory = ( sink -> IC2PowerSinkStub.INSTANCE );
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws Throwable
|
||||||
|
{
|
||||||
|
powerSinkFactory = IC2PowerSinkAdapter::new;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postInit()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an IC2 power sink for the given external sink.
|
||||||
|
*/
|
||||||
|
public static IC2PowerSink createPowerSink( IExternalPowerSink externalSink )
|
||||||
|
{
|
||||||
|
return instance.powerSinkFactory.apply( externalSink );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Applied Energistics 2.
|
||||||
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package appeng.integration.modules.ic2;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an abstraction for the IC2 Basic Sink so it can be stubbed out easily when the integration is disabled, or
|
||||||
|
* if the IC2 API is not available.
|
||||||
|
*/
|
||||||
|
public interface IC2PowerSink
|
||||||
|
{
|
||||||
|
|
||||||
|
default void invalidate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
default void onChunkUnload()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
default void onLoad()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
default void setValidFaces( Set<EnumFacing> faces )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Applied Energistics 2.
|
||||||
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package appeng.integration.modules.ic2;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
|
||||||
|
import ic2.api.energy.prefab.BasicSink;
|
||||||
|
import ic2.api.energy.tile.IEnergyEmitter;
|
||||||
|
|
||||||
|
import appeng.api.config.PowerUnits;
|
||||||
|
import appeng.tile.powersink.IExternalPowerSink;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The real implementation of IC2PowerSink.
|
||||||
|
*/
|
||||||
|
public class IC2PowerSinkAdapter extends BasicSink implements IC2PowerSink
|
||||||
|
{
|
||||||
|
|
||||||
|
private final IExternalPowerSink powerSink;
|
||||||
|
|
||||||
|
private final Set<EnumFacing> validFaces = EnumSet.allOf( EnumFacing.class );
|
||||||
|
|
||||||
|
public IC2PowerSinkAdapter( IExternalPowerSink powerSink )
|
||||||
|
{
|
||||||
|
super( (TileEntity) powerSink, 0, Integer.MAX_VALUE );
|
||||||
|
this.powerSink = powerSink;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidate()
|
||||||
|
{
|
||||||
|
super.onChunkUnload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChunkUnload()
|
||||||
|
{
|
||||||
|
super.onChunkUnload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad()
|
||||||
|
{
|
||||||
|
super.onLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getDemandedEnergy()
|
||||||
|
{
|
||||||
|
return powerSink.getExternalPowerDemand( PowerUnits.EU, Double.MAX_VALUE );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double injectEnergy( EnumFacing directionFrom, double amount, double voltage )
|
||||||
|
{
|
||||||
|
return PowerUnits.EU.convertTo( PowerUnits.AE, powerSink.injectExternalPower( PowerUnits.EU, amount ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean acceptsEnergyFrom( IEnergyEmitter iEnergyEmitter, EnumFacing side )
|
||||||
|
{
|
||||||
|
return validFaces.contains( side );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValidFaces( Set<EnumFacing> faces )
|
||||||
|
{
|
||||||
|
this.validFaces.clear();
|
||||||
|
this.validFaces.addAll( faces );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Applied Energistics 2.
|
||||||
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package appeng.integration.modules.ic2;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of IC2PowerSink that just stubs out all methods and does nothing.
|
||||||
|
*/
|
||||||
|
public enum IC2PowerSinkStub implements IC2PowerSink
|
||||||
|
{
|
||||||
|
INSTANCE
|
||||||
|
}
|
|
@ -36,6 +36,8 @@ import appeng.api.config.PowerMultiplier;
|
||||||
import appeng.api.config.PowerUnits;
|
import appeng.api.config.PowerUnits;
|
||||||
import appeng.api.networking.energy.IAEPowerStorage;
|
import appeng.api.networking.energy.IAEPowerStorage;
|
||||||
import appeng.api.networking.events.MENetworkPowerStorage.PowerEventType;
|
import appeng.api.networking.events.MENetworkPowerStorage.PowerEventType;
|
||||||
|
import appeng.integration.modules.IC2;
|
||||||
|
import appeng.integration.modules.ic2.IC2PowerSink;
|
||||||
import appeng.tile.AEBaseInvTile;
|
import appeng.tile.AEBaseInvTile;
|
||||||
import appeng.tile.TileEvent;
|
import appeng.tile.TileEvent;
|
||||||
import appeng.tile.events.TileEventType;
|
import appeng.tile.events.TileEventType;
|
||||||
|
@ -57,12 +59,16 @@ public abstract class AERootPoweredTile extends AEBaseInvTile implements IAEPowe
|
||||||
private final IEnergyStorage forgeEnergyAdapter;
|
private final IEnergyStorage forgeEnergyAdapter;
|
||||||
private Object teslaEnergyAdapter;
|
private Object teslaEnergyAdapter;
|
||||||
|
|
||||||
|
private IC2PowerSink ic2Sink;
|
||||||
|
|
||||||
public AERootPoweredTile()
|
public AERootPoweredTile()
|
||||||
{
|
{
|
||||||
forgeEnergyAdapter = new ForgeEnergyAdapter( this );
|
forgeEnergyAdapter = new ForgeEnergyAdapter( this );
|
||||||
if ( teslaConsumerCapability != null ) {
|
if ( teslaConsumerCapability != null ) {
|
||||||
teslaEnergyAdapter = new TeslaEnergyAdapter( this );
|
teslaEnergyAdapter = new TeslaEnergyAdapter( this );
|
||||||
}
|
}
|
||||||
|
ic2Sink = IC2.createPowerSink(this);
|
||||||
|
ic2Sink.setValidFaces( internalPowerSides );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected EnumSet<EnumFacing> getPowerSides()
|
protected EnumSet<EnumFacing> getPowerSides()
|
||||||
|
@ -73,6 +79,7 @@ public abstract class AERootPoweredTile extends AEBaseInvTile implements IAEPowe
|
||||||
protected void setPowerSides( final EnumSet<EnumFacing> sides )
|
protected void setPowerSides( final EnumSet<EnumFacing> sides )
|
||||||
{
|
{
|
||||||
this.internalPowerSides = sides;
|
this.internalPowerSides = sides;
|
||||||
|
ic2Sink.setValidFaces( sides );
|
||||||
// trigger re-calc!
|
// trigger re-calc!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,6 +258,30 @@ public abstract class AERootPoweredTile extends AEBaseInvTile implements IAEPowe
|
||||||
this.internalPowerFlow = internalPowerFlow;
|
this.internalPowerFlow = internalPowerFlow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReady()
|
||||||
|
{
|
||||||
|
super.onReady();
|
||||||
|
|
||||||
|
ic2Sink.onLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChunkUnload()
|
||||||
|
{
|
||||||
|
super.onChunkUnload();
|
||||||
|
|
||||||
|
ic2Sink.onChunkUnload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidate()
|
||||||
|
{
|
||||||
|
super.invalidate();
|
||||||
|
|
||||||
|
ic2Sink.invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCapability( Capability<?> capability, EnumFacing facing )
|
public boolean hasCapability( Capability<?> capability, EnumFacing facing )
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,3 +1,20 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Applied Energistics 2.
|
||||||
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||||
|
*/
|
||||||
package appeng.tile.powersink;
|
package appeng.tile.powersink;
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +22,7 @@ import appeng.api.config.PowerUnits;
|
||||||
import appeng.api.networking.energy.IAEPowerStorage;
|
import appeng.api.networking.energy.IAEPowerStorage;
|
||||||
|
|
||||||
|
|
||||||
interface IExternalPowerSink extends IAEPowerStorage
|
public interface IExternalPowerSink extends IAEPowerStorage
|
||||||
{
|
{
|
||||||
|
|
||||||
double injectExternalPower( PowerUnits input, double amt );
|
double injectExternalPower( PowerUnits input, double amt );
|
||||||
|
|
Loading…
Reference in a new issue