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:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* Copyright (c) 2013 - 2015, 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
|
||||
@@ -19,12 +19,164 @@
|
||||
package appeng.items.tools.powered.powersink;
|
||||
|
||||
|
||||
public abstract class AEBasePoweredItem extends RedstoneFlux
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.implementations.items.IAEItemPowerStorage;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public abstract class AEBasePoweredItem extends AEBaseItem implements IAEItemPowerStorage
|
||||
{
|
||||
private static final String CURRENT_POWER_NBT_KEY = "internalCurrentPower";
|
||||
private static final String MAX_POWER_NBT_KEY = "internalMaxPower";
|
||||
private final double powerCapacity;
|
||||
|
||||
public AEBasePoweredItem( final double powerCapacity )
|
||||
{
|
||||
super( powerCapacity );
|
||||
|
||||
this.setMaxStackSize( 1 );
|
||||
this.setMaxDamage( 32 );
|
||||
this.hasSubtypes = false;
|
||||
this.setFull3D();
|
||||
|
||||
this.powerCapacity = powerCapacity;
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
@Override
|
||||
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
|
||||
{
|
||||
final NBTTagCompound tag = stack.getTagCompound();
|
||||
double internalCurrentPower = 0;
|
||||
final double internalMaxPower = this.getAEMaxPower( stack );
|
||||
|
||||
if( tag != null )
|
||||
{
|
||||
internalCurrentPower = tag.getDouble( CURRENT_POWER_NBT_KEY );
|
||||
}
|
||||
|
||||
final double percent = internalCurrentPower / internalMaxPower;
|
||||
|
||||
lines.add( GuiText.StoredEnergy.getLocal() + ':' + MessageFormat.format( " {0,number,#} ", internalCurrentPower ) + Platform
|
||||
.gui_localize( PowerUnits.AE.unlocalizedName ) + " - " + MessageFormat.format( " {0,number,#.##%} ", percent ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getCheckedSubItems( final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks )
|
||||
{
|
||||
super.getCheckedSubItems( creativeTab, itemStacks );
|
||||
|
||||
final ItemStack charged = new ItemStack( this, 1 );
|
||||
final NBTTagCompound tag = Platform.openNbtData( charged );
|
||||
tag.setDouble( CURRENT_POWER_NBT_KEY, this.getAEMaxPower( charged ) );
|
||||
tag.setDouble( MAX_POWER_NBT_KEY, this.getAEMaxPower( charged ) );
|
||||
|
||||
itemStacks.add( charged );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRepairable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDurabilityForDisplay( final ItemStack is )
|
||||
{
|
||||
return 1 - this.getAECurrentPower( is ) / this.getAEMaxPower( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamaged( final ItemStack stack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage( final ItemStack stack, final int damage )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectAEPower( final ItemStack is, final double amount, Actionable mode )
|
||||
{
|
||||
final double maxStorage = this.getAEMaxPower( is );
|
||||
final double currentStorage = this.getAECurrentPower( is );
|
||||
final double required = maxStorage - currentStorage;
|
||||
final double overflow = amount - required;
|
||||
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
final NBTTagCompound data = Platform.openNbtData( is );
|
||||
final double toAdd = Math.min( amount, required );
|
||||
|
||||
data.setDouble( CURRENT_POWER_NBT_KEY, currentStorage + toAdd );
|
||||
}
|
||||
|
||||
return Math.max( 0, overflow );
|
||||
}
|
||||
|
||||
@Override
|
||||
public double extractAEPower( final ItemStack is, final double amount, Actionable mode )
|
||||
{
|
||||
final double currentStorage = this.getAECurrentPower( is );
|
||||
final double fulfillable = Math.min( amount, currentStorage );
|
||||
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
final NBTTagCompound data = Platform.openNbtData( is );
|
||||
|
||||
data.setDouble( CURRENT_POWER_NBT_KEY, currentStorage - fulfillable );
|
||||
}
|
||||
|
||||
return fulfillable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAEMaxPower( final ItemStack is )
|
||||
{
|
||||
return this.powerCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAECurrentPower( final ItemStack is )
|
||||
{
|
||||
final NBTTagCompound data = Platform.openNbtData( is );
|
||||
|
||||
return data.getDouble( CURRENT_POWER_NBT_KEY );
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessRestriction getPowerFlow( final ItemStack is )
|
||||
{
|
||||
return AccessRestriction.WRITE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities( ItemStack stack, NBTTagCompound nbt )
|
||||
{
|
||||
return new PoweredItemCapabilities( stack, this );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user