IC2 rework to avoid a coremod or @Optional (#3034)

* IC2 rework to avoid a coremod or @Optional

Updated IC2 dependency

Refactored IC2 itemcharging to use an IBackupElectricManager.
Allows charging any ae powered item by using an IBackupElectricManager
instead of having to implement IElectricItem and stripping it by some
sort.

Updated IAEItemPowerStorage to use Actionable for an easier handling
with power APIs supporting a simulation.

Refactored EU P2P to avoid method stripping
Use a modified internal BasicSinkSource instead of implementing
IEnergySource and IEnergySink directly on the tunnel.

Removed the superfluous EU P2P layers.

* Removed internalBattery due to being too complex

* Creative Energy Cell is not a chargeable item
This commit is contained in:
yueh
2017-08-17 17:35:34 +02:00
committed by GitHub
parent 630fae3f73
commit 4f9fd1b369
23 changed files with 559 additions and 993 deletions
@@ -22,12 +22,15 @@ package appeng.integration.modules.ic2;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import ic2.api.item.ElectricItem;
import appeng.api.AEApi;
import appeng.api.config.TunnelType;
import appeng.api.features.IP2PTunnelRegistry;
import appeng.integration.IntegrationHelper;
import appeng.integration.abstraction.IC2PowerSink;
import appeng.integration.abstraction.IIC2;
import appeng.integration.modules.ic2.energy.PoweredItemManager;
import appeng.tile.powersink.IExternalPowerSink;
@@ -39,7 +42,11 @@ public class IC2Module implements IIC2
public IC2Module()
{
IntegrationHelper.testClassExistence( this, ic2.api.energy.tile.IEnergyTile.class );
IntegrationHelper.testClassExistence( this, ic2.api.energy.tile.IEnergyAcceptor.class );
IntegrationHelper.testClassExistence( this, ic2.api.energy.tile.IEnergyEmitter.class );
IntegrationHelper.testClassExistence( this, ic2.api.energy.prefab.BasicSinkSource.class );
IntegrationHelper.testClassExistence( this, ic2.api.item.IC2Items.class );
IntegrationHelper.testClassExistence( this, ic2.api.item.IBackupElectricItemManager.class );
IntegrationHelper.testClassExistence( this, ic2.api.recipe.Recipes.class );
IntegrationHelper.testClassExistence( this, ic2.api.recipe.IRecipeInput.class );
}
@@ -53,6 +60,8 @@ public class IC2Module implements IIC2
{
reg.addNewAttunement( this.getCable( string ), TunnelType.IC2_POWER );
}
ElectricItem.registerBackupManager( new PoweredItemManager() );
}
private ItemStack getItem( final String name, String variant )
@@ -0,0 +1,126 @@
/*
* 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.energy;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import ic2.api.item.IBackupElectricItemManager;
import appeng.api.config.Actionable;
import appeng.api.config.PowerUnits;
import appeng.api.implementations.items.IAEItemPowerStorage;
public class PoweredItemManager implements IBackupElectricItemManager
{
@Override
public double charge( ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean simulate )
{
final double limit = this.getTransferLimit( stack );
final IAEItemPowerStorage poweredItem = (IAEItemPowerStorage) stack.getItem();
final double convertedPower = PowerUnits.EU.convertTo( PowerUnits.AE, amount );
double toAdd = convertedPower;
if( !ignoreTransferLimit && amount > limit )
{
toAdd = limit;
}
final double overflow = poweredItem.injectAEPower( stack, toAdd, simulate ? Actionable.SIMULATE : Actionable.MODULATE );
final double addedAmount = toAdd - (int) overflow;
return PowerUnits.AE.convertTo( PowerUnits.EU, addedAmount );
}
@Override
public double discharge( ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean externally, boolean simulate )
{
return 0;
}
@Override
public double getCharge( ItemStack stack )
{
final IAEItemPowerStorage poweredItem = (IAEItemPowerStorage) stack.getItem();
return (int) PowerUnits.AE.convertTo( PowerUnits.EU, poweredItem.getAECurrentPower( stack ) );
}
@Override
public double getMaxCharge( ItemStack stack )
{
final IAEItemPowerStorage poweredItem = (IAEItemPowerStorage) stack.getItem();
return PowerUnits.AE.convertTo( PowerUnits.EU, poweredItem.getAEMaxPower( stack ) );
}
@Override
public boolean canUse( ItemStack stack, double amount )
{
return this.getCharge( stack ) > amount;
}
@Override
public boolean use( ItemStack stack, double amount, EntityLivingBase entity )
{
final IAEItemPowerStorage poweredItem = (IAEItemPowerStorage) stack.getItem();
if( this.canUse( stack, amount ) )
{
final double toUse = PowerUnits.EU.convertTo( PowerUnits.AE, amount );
poweredItem.extractAEPower( stack, toUse, Actionable.MODULATE );
return true;
}
return false;
}
@Override
public void chargeFromArmor( ItemStack stack, EntityLivingBase entity )
{
// TODO Auto-generated method stub
}
@Override
public String getToolTip( ItemStack stack )
{
return null;
}
@Override
public int getTier( ItemStack stack )
{
return 1;
}
@Override
public boolean handles( ItemStack stack )
{
return !stack.isEmpty() && ( stack.getItem() instanceof IAEItemPowerStorage );
}
private double getTransferLimit( ItemStack itemStack )
{
return Math.max( 32, this.getMaxCharge( itemStack ) / 200 );
}
}