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:
parent
630fae3f73
commit
4f9fd1b369
23 changed files with 559 additions and 993 deletions
|
@ -21,6 +21,6 @@ hwyla_version=1.8.19-B33_1.12
|
||||||
#########################################################
|
#########################################################
|
||||||
jei_version=4.7.1.69
|
jei_version=4.7.1.69
|
||||||
tesla_version=1.0.61
|
tesla_version=1.0.61
|
||||||
ic2_version=2.8.7-ex112
|
ic2_version=2.8.9-ex112
|
||||||
rf_version=2.0.0.1
|
rf_version=2.0.0.1
|
||||||
top_version=1.12-1.4.8-2
|
top_version=1.12-1.4.8-2
|
||||||
|
|
|
@ -27,6 +27,7 @@ package appeng.api.implementations.items;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
import appeng.api.config.AccessRestriction;
|
import appeng.api.config.AccessRestriction;
|
||||||
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.networking.energy.IAEPowerStorage;
|
import appeng.api.networking.energy.IAEPowerStorage;
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,27 +43,27 @@ public interface IAEItemPowerStorage
|
||||||
*
|
*
|
||||||
* @return amount unable to be stored
|
* @return amount unable to be stored
|
||||||
*/
|
*/
|
||||||
double injectAEPower( ItemStack is, double amt );
|
double injectAEPower( ItemStack stack, double amount, Actionable mode );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to extract power from the device, it will extract what it can and
|
* Attempt to extract power from the device, it will extract what it can and
|
||||||
* return it.
|
* return it.
|
||||||
*
|
*
|
||||||
* @param amt to be extracted power from device
|
* @param amount to be extracted power from device
|
||||||
*
|
*
|
||||||
* @return what it could extract
|
* @return what it could extract
|
||||||
*/
|
*/
|
||||||
double extractAEPower( ItemStack is, double amt );
|
double extractAEPower( ItemStack stack, double amount, Actionable mode );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the current maximum power ( this can change :P )
|
* @return the current maximum power ( this can change :P )
|
||||||
*/
|
*/
|
||||||
double getAEMaxPower( ItemStack is );
|
double getAEMaxPower( ItemStack stack );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the current AE Power Level, this may exceed getMEMaxPower()
|
* @return the current AE Power Level, this may exceed getMEMaxPower()
|
||||||
*/
|
*/
|
||||||
double getAECurrentPower( ItemStack is );
|
double getAECurrentPower( ItemStack stack );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Control the power flow by telling what the network can do, either add? or
|
* Control the power flow by telling what the network can do, either add? or
|
||||||
|
@ -70,5 +71,5 @@ public interface IAEItemPowerStorage
|
||||||
*
|
*
|
||||||
* @return access restriction of network
|
* @return access restriction of network
|
||||||
*/
|
*/
|
||||||
AccessRestriction getPowerFlow( ItemStack is );
|
AccessRestriction getPowerFlow( ItemStack stack );
|
||||||
}
|
}
|
|
@ -31,6 +31,7 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
import appeng.api.config.AccessRestriction;
|
import appeng.api.config.AccessRestriction;
|
||||||
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.config.PowerUnits;
|
import appeng.api.config.PowerUnits;
|
||||||
import appeng.api.definitions.IBlockDefinition;
|
import appeng.api.definitions.IBlockDefinition;
|
||||||
import appeng.api.implementations.items.IAEItemPowerStorage;
|
import appeng.api.implementations.items.IAEItemPowerStorage;
|
||||||
|
@ -66,67 +67,39 @@ public class AEBaseItemBlockChargeable extends AEBaseItemBlock implements IAEIte
|
||||||
.gui_localize( PowerUnits.AE.unlocalizedName ) + " - " + MessageFormat.format( " {0,number,#.##%} ", percent ) );
|
.gui_localize( PowerUnits.AE.unlocalizedName ) + " - " + MessageFormat.format( " {0,number,#.##%} ", percent ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getMaxEnergyCapacity()
|
@Override
|
||||||
|
public double injectAEPower( final ItemStack is, double amount, Actionable mode )
|
||||||
{
|
{
|
||||||
final Block blockID = Block.getBlockFromItem( this );
|
final double internalCurrentPower = this.getInternal( is );
|
||||||
final IBlockDefinition energyCell = Api.INSTANCE.definitions().blocks().energyCell();
|
final double internalMaxPower = this.getAEMaxPower( is );
|
||||||
return energyCell.maybeBlock().map( block ->
|
final double required = internalMaxPower - internalCurrentPower;
|
||||||
|
final double overflow = Math.max( 0, amount - required );
|
||||||
|
|
||||||
|
if( mode == Actionable.MODULATE )
|
||||||
{
|
{
|
||||||
if( blockID == block )
|
final double toAdd = Math.min( required, amount );
|
||||||
{
|
final double newPowerStored = internalCurrentPower + toAdd;
|
||||||
return 200000;
|
|
||||||
|
this.setInternal( is, newPowerStored );
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
return overflow;
|
||||||
return 8 * 200000;
|
|
||||||
}
|
|
||||||
} ).orElse( 0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double injectAEPower( final ItemStack is, double amt )
|
public double extractAEPower( final ItemStack is, double amount, Actionable mode )
|
||||||
{
|
{
|
||||||
double internalCurrentPower = this.getInternal( is );
|
final double internalCurrentPower = this.getInternal( is );
|
||||||
final double internalMaxPower = this.getMaxEnergyCapacity();
|
final double fulfillable = Math.min( amount, internalCurrentPower );
|
||||||
internalCurrentPower += amt;
|
|
||||||
if( internalCurrentPower > internalMaxPower )
|
if( mode == Actionable.MODULATE )
|
||||||
{
|
{
|
||||||
amt = internalCurrentPower - internalMaxPower;
|
final double newPowerStored = internalCurrentPower - fulfillable;
|
||||||
internalCurrentPower = internalMaxPower;
|
|
||||||
this.setInternal( is, internalCurrentPower );
|
this.setInternal( is, newPowerStored );
|
||||||
return amt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setInternal( is, internalCurrentPower );
|
return fulfillable;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private double getInternal( final ItemStack is )
|
|
||||||
{
|
|
||||||
final NBTTagCompound nbt = Platform.openNbtData( is );
|
|
||||||
return nbt.getDouble( "internalCurrentPower" );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setInternal( final ItemStack is, final double amt )
|
|
||||||
{
|
|
||||||
final NBTTagCompound nbt = Platform.openNbtData( is );
|
|
||||||
nbt.setDouble( "internalCurrentPower", amt );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double extractAEPower( final ItemStack is, double amt )
|
|
||||||
{
|
|
||||||
double internalCurrentPower = this.getInternal( is );
|
|
||||||
if( internalCurrentPower > amt )
|
|
||||||
{
|
|
||||||
internalCurrentPower -= amt;
|
|
||||||
this.setInternal( is, internalCurrentPower );
|
|
||||||
return amt;
|
|
||||||
}
|
|
||||||
|
|
||||||
amt = internalCurrentPower;
|
|
||||||
this.setInternal( is, 0 );
|
|
||||||
return amt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -146,4 +119,34 @@ public class AEBaseItemBlockChargeable extends AEBaseItemBlock implements IAEIte
|
||||||
{
|
{
|
||||||
return AccessRestriction.WRITE;
|
return AccessRestriction.WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double getMaxEnergyCapacity()
|
||||||
|
{
|
||||||
|
final Block blockID = Block.getBlockFromItem( this );
|
||||||
|
final IBlockDefinition energyCell = Api.INSTANCE.definitions().blocks().energyCell();
|
||||||
|
|
||||||
|
return energyCell.maybeBlock().map( block ->
|
||||||
|
{
|
||||||
|
if( blockID == block )
|
||||||
|
{
|
||||||
|
return 200000;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 8 * 200000;
|
||||||
|
}
|
||||||
|
} ).orElse( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getInternal( final ItemStack is )
|
||||||
|
{
|
||||||
|
final NBTTagCompound nbt = Platform.openNbtData( is );
|
||||||
|
return nbt.getDouble( "internalCurrentPower" );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setInternal( final ItemStack is, final double amt )
|
||||||
|
{
|
||||||
|
final NBTTagCompound nbt = Platform.openNbtData( is );
|
||||||
|
nbt.setDouble( "internalCurrentPower", amt );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,12 +240,6 @@ final class Registration
|
||||||
// final Runnable recipeLoader = new RecipeLoader( recipeDirectory, customRecipeConfig, this.recipeHandler );
|
// final Runnable recipeLoader = new RecipeLoader( recipeDirectory, customRecipeConfig, this.recipeHandler );
|
||||||
// recipeLoader.run();
|
// recipeLoader.run();
|
||||||
|
|
||||||
if( Integrations.ic2().isEnabled() )
|
|
||||||
{
|
|
||||||
partHelper.registerNewLayer( "appeng.parts.layers.LayerIEnergySink", "ic2.api.energy.tile.IEnergySink" );
|
|
||||||
partHelper.registerNewLayer( "appeng.parts.layers.LayerIEnergySource", "ic2.api.energy.tile.IEnergySource" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.RF ) )
|
if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.RF ) )
|
||||||
{
|
{
|
||||||
partHelper.registerNewLayer( "appeng.parts.layers.LayerIEnergyHandler", "cofh.redstoneflux.api.IEnergyReceiver" );
|
partHelper.registerNewLayer( "appeng.parts.layers.LayerIEnergyHandler", "cofh.redstoneflux.api.IEnergyReceiver" );
|
||||||
|
|
|
@ -421,7 +421,6 @@ public final class ApiBlocks implements IBlocks
|
||||||
.build();
|
.build();
|
||||||
this.energyCellCreative = registry.block( "creative_energy_cell", BlockCreativeEnergyCell::new )
|
this.energyCellCreative = registry.block( "creative_energy_cell", BlockCreativeEnergyCell::new )
|
||||||
.features( AEFeature.CREATIVE )
|
.features( AEFeature.CREATIVE )
|
||||||
.item( AEBaseItemBlockChargeable::new )
|
|
||||||
.tileEntity( new TileEntityDefinition( TileCreativeEnergyCell.class ) )
|
.tileEntity( new TileEntityDefinition( TileCreativeEnergyCell.class ) )
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,15 @@ package appeng.integration.modules.ic2;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
|
||||||
|
import ic2.api.item.ElectricItem;
|
||||||
|
|
||||||
import appeng.api.AEApi;
|
import appeng.api.AEApi;
|
||||||
import appeng.api.config.TunnelType;
|
import appeng.api.config.TunnelType;
|
||||||
import appeng.api.features.IP2PTunnelRegistry;
|
import appeng.api.features.IP2PTunnelRegistry;
|
||||||
import appeng.integration.IntegrationHelper;
|
import appeng.integration.IntegrationHelper;
|
||||||
import appeng.integration.abstraction.IC2PowerSink;
|
import appeng.integration.abstraction.IC2PowerSink;
|
||||||
import appeng.integration.abstraction.IIC2;
|
import appeng.integration.abstraction.IIC2;
|
||||||
|
import appeng.integration.modules.ic2.energy.PoweredItemManager;
|
||||||
import appeng.tile.powersink.IExternalPowerSink;
|
import appeng.tile.powersink.IExternalPowerSink;
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +42,11 @@ public class IC2Module implements IIC2
|
||||||
public IC2Module()
|
public IC2Module()
|
||||||
{
|
{
|
||||||
IntegrationHelper.testClassExistence( this, ic2.api.energy.tile.IEnergyTile.class );
|
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.IC2Items.class );
|
||||||
|
IntegrationHelper.testClassExistence( this, ic2.api.item.IBackupElectricItemManager.class );
|
||||||
IntegrationHelper.testClassExistence( this, ic2.api.recipe.Recipes.class );
|
IntegrationHelper.testClassExistence( this, ic2.api.recipe.Recipes.class );
|
||||||
IntegrationHelper.testClassExistence( this, ic2.api.recipe.IRecipeInput.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 );
|
reg.addNewAttunement( this.getCable( string ), TunnelType.IC2_POWER );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ElectricItem.registerBackupManager( new PoweredItemManager() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack getItem( final String name, String variant )
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -79,7 +79,7 @@ public class PortableCellViewer extends MEMonitorHandler<IAEItemStack> implement
|
||||||
return usePowerMultiplier.divide( Math.min( amt, this.ips.getAECurrentPower( this.target ) ) );
|
return usePowerMultiplier.divide( Math.min( amt, this.ips.getAECurrentPower( this.target ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return usePowerMultiplier.divide( this.ips.extractAEPower( this.target, amt ) );
|
return usePowerMultiplier.divide( this.ips.extractAEPower( this.target, amt, Actionable.MODULATE ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,6 +24,7 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.DamageSource;
|
import net.minecraft.util.DamageSource;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
|
|
||||||
|
import appeng.api.config.Actionable;
|
||||||
import appeng.core.AEConfig;
|
import appeng.core.AEConfig;
|
||||||
import appeng.core.AppEng;
|
import appeng.core.AppEng;
|
||||||
import appeng.core.sync.packets.PacketLightning;
|
import appeng.core.sync.packets.PacketLightning;
|
||||||
|
@ -44,7 +45,7 @@ public class ToolChargedStaff extends AEBasePoweredItem
|
||||||
{
|
{
|
||||||
if( this.getAECurrentPower( item ) > 300 )
|
if( this.getAECurrentPower( item ) > 300 )
|
||||||
{
|
{
|
||||||
this.extractAEPower( item, 300 );
|
this.extractAEPower( item, 300, Actionable.MODULATE );
|
||||||
if( Platform.isServer() )
|
if( Platform.isServer() )
|
||||||
{
|
{
|
||||||
for( int x = 0; x < 2; x++ )
|
for( int x = 0; x < 2; x++ )
|
||||||
|
|
|
@ -151,7 +151,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
|
||||||
if( ( (IColorableTile) te ).recolourBlock( side, AEColor.TRANSPARENT, p ) )
|
if( ( (IColorableTile) te ).recolourBlock( side, AEColor.TRANSPARENT, p ) )
|
||||||
{
|
{
|
||||||
inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() );
|
inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() );
|
||||||
this.extractAEPower( is, powerPerUse );
|
this.extractAEPower( is, powerPerUse, Actionable.MODULATE );
|
||||||
return EnumActionResult.SUCCESS;
|
return EnumActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
|
||||||
if( this.getAECurrentPower( is ) > powerPerUse && testBlk instanceof BlockPaint && painted instanceof TilePaint )
|
if( this.getAECurrentPower( is ) > powerPerUse && testBlk instanceof BlockPaint && painted instanceof TilePaint )
|
||||||
{
|
{
|
||||||
inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() );
|
inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() );
|
||||||
this.extractAEPower( is, powerPerUse );
|
this.extractAEPower( is, powerPerUse, Actionable.MODULATE );
|
||||||
( (TilePaint) painted ).cleanSide( side.getOpposite() );
|
( (TilePaint) painted ).cleanSide( side.getOpposite() );
|
||||||
return EnumActionResult.SUCCESS;
|
return EnumActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
|
||||||
if( color != AEColor.TRANSPARENT && this.recolourBlock( blk, side, w, pos, side, color, p ) )
|
if( color != AEColor.TRANSPARENT && this.recolourBlock( blk, side, w, pos, side, color, p ) )
|
||||||
{
|
{
|
||||||
inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() );
|
inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() );
|
||||||
this.extractAEPower( is, powerPerUse );
|
this.extractAEPower( is, powerPerUse, Actionable.MODULATE );
|
||||||
return EnumActionResult.SUCCESS;
|
return EnumActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.util.DimensionalCoord;
|
import appeng.api.util.DimensionalCoord;
|
||||||
import appeng.block.misc.BlockTinyTNT;
|
import appeng.block.misc.BlockTinyTNT;
|
||||||
import appeng.core.AEConfig;
|
import appeng.core.AEConfig;
|
||||||
|
@ -204,7 +205,7 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
|
||||||
{
|
{
|
||||||
if( this.getAECurrentPower( item ) > 1600 )
|
if( this.getAECurrentPower( item ) > 1600 )
|
||||||
{
|
{
|
||||||
this.extractAEPower( item, 1600 );
|
this.extractAEPower( item, 1600, Actionable.MODULATE );
|
||||||
target.setFire( 8 );
|
target.setFire( 8 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +262,7 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
|
||||||
{
|
{
|
||||||
if( this.canCool( state ) )
|
if( this.canCool( state ) )
|
||||||
{
|
{
|
||||||
this.extractAEPower( item, 1600 );
|
this.extractAEPower( item, 1600, Actionable.MODULATE );
|
||||||
this.cool( state, w, pos );
|
this.cool( state, w, pos );
|
||||||
return EnumActionResult.SUCCESS;
|
return EnumActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -284,7 +285,7 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
|
||||||
|
|
||||||
if( this.canHeat( state ) )
|
if( this.canHeat( state ) )
|
||||||
{
|
{
|
||||||
this.extractAEPower( item, 1600 );
|
this.extractAEPower( item, 1600, Actionable.MODULATE );
|
||||||
this.heat( state, w, pos );
|
this.heat( state, w, pos );
|
||||||
return EnumActionResult.SUCCESS;
|
return EnumActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -320,7 +321,7 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
|
||||||
|
|
||||||
if( hasFurnaceable && canFurnaceable )
|
if( hasFurnaceable && canFurnaceable )
|
||||||
{
|
{
|
||||||
this.extractAEPower( item, 1600 );
|
this.extractAEPower( item, 1600, Actionable.MODULATE );
|
||||||
final InWorldToolOperationResult or = InWorldToolOperationResult.getBlockOperationResult( out.toArray( new ItemStack[out.size()] ) );
|
final InWorldToolOperationResult or = InWorldToolOperationResult.getBlockOperationResult( out.toArray( new ItemStack[out.size()] ) );
|
||||||
w.playSound( p, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.PLAYERS, 1.0F,
|
w.playSound( p, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.PLAYERS, 1.0F,
|
||||||
itemRand.nextFloat() * 0.4F + 0.8F );
|
itemRand.nextFloat() * 0.4F + 0.8F );
|
||||||
|
@ -353,7 +354,7 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
|
||||||
|
|
||||||
if( w.isAirBlock( offsetPos ) )
|
if( w.isAirBlock( offsetPos ) )
|
||||||
{
|
{
|
||||||
this.extractAEPower( item, 1600 );
|
this.extractAEPower( item, 1600, Actionable.MODULATE );
|
||||||
w.playSound( p, offsetPos.getX() + 0.5D, offsetPos.getY() + 0.5D, offsetPos.getZ() + 0.5D, SoundEvents.ITEM_FLINTANDSTEEL_USE,
|
w.playSound( p, offsetPos.getX() + 0.5D, offsetPos.getY() + 0.5D, offsetPos.getZ() + 0.5D, SoundEvents.ITEM_FLINTANDSTEEL_USE,
|
||||||
SoundCategory.PLAYERS, 1.0F, itemRand.nextFloat() * 0.4F + 0.8F );
|
SoundCategory.PLAYERS, 1.0F, itemRand.nextFloat() * 0.4F + 0.8F );
|
||||||
w.setBlockState( offsetPos, Blocks.FIRE.getDefaultState() );
|
w.setBlockState( offsetPos, Blocks.FIRE.getDefaultState() );
|
||||||
|
|
|
@ -132,7 +132,7 @@ public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell
|
||||||
shots = Math.min( shots, (int) aeAmmo.getStackSize() );
|
shots = Math.min( shots, (int) aeAmmo.getStackSize() );
|
||||||
for( int sh = 0; sh < shots; sh++ )
|
for( int sh = 0; sh < shots; sh++ )
|
||||||
{
|
{
|
||||||
this.extractAEPower( p.getHeldItem( hand ), 1600 );
|
this.extractAEPower( p.getHeldItem( hand ), 1600, Actionable.MODULATE );
|
||||||
|
|
||||||
if( Platform.isClient() )
|
if( Platform.isClient() )
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,6 +34,7 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
import appeng.api.AEApi;
|
import appeng.api.AEApi;
|
||||||
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.config.Settings;
|
import appeng.api.config.Settings;
|
||||||
import appeng.api.config.SortDir;
|
import appeng.api.config.SortDir;
|
||||||
import appeng.api.config.SortOrder;
|
import appeng.api.config.SortOrder;
|
||||||
|
@ -108,7 +109,7 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless
|
||||||
@Override
|
@Override
|
||||||
public boolean usePower( final EntityPlayer player, final double amount, final ItemStack is )
|
public boolean usePower( final EntityPlayer player, final double amount, final ItemStack is )
|
||||||
{
|
{
|
||||||
return this.extractAEPower( is, amount ) >= amount - 0.5;
|
return this.extractAEPower( is, amount, Actionable.MODULATE ) >= amount - 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* This file is part of Applied Energistics 2.
|
* 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
|
* 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
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
@ -19,12 +19,164 @@
|
||||||
package appeng.items.tools.powered.powersink;
|
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 )
|
public AEBasePoweredItem( final double powerCapacity )
|
||||||
{
|
{
|
||||||
super( powerCapacity );
|
|
||||||
|
|
||||||
this.setMaxStackSize( 1 );
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,215 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of Applied Energistics 2.
|
|
||||||
* 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
|
|
||||||
* 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.items.tools.powered.powersink;
|
|
||||||
|
|
||||||
|
|
||||||
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.PowerUnits;
|
|
||||||
import appeng.api.implementations.items.IAEItemPowerStorage;
|
|
||||||
import appeng.core.localization.GuiText;
|
|
||||||
import appeng.items.AEBaseItem;
|
|
||||||
import appeng.util.Platform;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class AERootPoweredItem extends AEBaseItem implements IAEItemPowerStorage
|
|
||||||
{
|
|
||||||
private static final String POWER_NBT_KEY = "internalCurrentPower";
|
|
||||||
private final double powerCapacity;
|
|
||||||
|
|
||||||
public AERootPoweredItem( final double powerCapacity )
|
|
||||||
{
|
|
||||||
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( "internalCurrentPower" );
|
|
||||||
}
|
|
||||||
|
|
||||||
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( "internalCurrentPower", this.getAEMaxPower( charged ) );
|
|
||||||
tag.setDouble( "internalMaxPower", 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 )
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private double getInternalBattery( final ItemStack is, final batteryOperation op, final double adjustment )
|
|
||||||
{
|
|
||||||
final NBTTagCompound data = Platform.openNbtData( is );
|
|
||||||
|
|
||||||
double currentStorage = data.getDouble( POWER_NBT_KEY );
|
|
||||||
final double maxStorage = this.getAEMaxPower( is );
|
|
||||||
|
|
||||||
switch( op )
|
|
||||||
{
|
|
||||||
case INJECT:
|
|
||||||
currentStorage += adjustment;
|
|
||||||
if( currentStorage > maxStorage )
|
|
||||||
{
|
|
||||||
final double diff = currentStorage - maxStorage;
|
|
||||||
data.setDouble( POWER_NBT_KEY, maxStorage );
|
|
||||||
return diff;
|
|
||||||
}
|
|
||||||
data.setDouble( POWER_NBT_KEY, currentStorage );
|
|
||||||
return 0;
|
|
||||||
case EXTRACT:
|
|
||||||
if( currentStorage > adjustment )
|
|
||||||
{
|
|
||||||
currentStorage -= adjustment;
|
|
||||||
data.setDouble( POWER_NBT_KEY, currentStorage );
|
|
||||||
return adjustment;
|
|
||||||
}
|
|
||||||
data.setDouble( POWER_NBT_KEY, 0 );
|
|
||||||
return currentStorage;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return currentStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inject power into this item using an external unit.
|
|
||||||
*/
|
|
||||||
double injectExternalPower( PowerUnits inputUnit, final ItemStack is, final double amount, final boolean simulate )
|
|
||||||
{
|
|
||||||
if( simulate )
|
|
||||||
{
|
|
||||||
final int requiredExt = (int) PowerUnits.AE.convertTo( inputUnit, this.getAEMaxPower( is ) - this.getAECurrentPower( is ) );
|
|
||||||
if( amount < requiredExt )
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return amount - requiredExt;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
final double powerRemainder = this.injectAEPower( is, inputUnit.convertTo( PowerUnits.AE, amount ) );
|
|
||||||
return PowerUnits.AE.convertTo( inputUnit, powerRemainder );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double injectAEPower( final ItemStack is, final double amt )
|
|
||||||
{
|
|
||||||
return this.getInternalBattery( is, batteryOperation.INJECT, amt );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double extractAEPower( final ItemStack is, final double amt )
|
|
||||||
{
|
|
||||||
return this.getInternalBattery( is, batteryOperation.EXTRACT, amt );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getAEMaxPower( final ItemStack is )
|
|
||||||
{
|
|
||||||
return this.powerCapacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getAECurrentPower( final ItemStack is )
|
|
||||||
{
|
|
||||||
return this.getInternalBattery( is, batteryOperation.STORAGE, 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AccessRestriction getPowerFlow( final ItemStack is )
|
|
||||||
{
|
|
||||||
return AccessRestriction.WRITE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ICapabilityProvider initCapabilities( ItemStack stack, NBTTagCompound nbt )
|
|
||||||
{
|
|
||||||
return new PoweredItemCapabilities( stack, this );
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum batteryOperation
|
|
||||||
{
|
|
||||||
STORAGE, INJECT, EXTRACT
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,125 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.items.tools.powered.powersink;
|
|
||||||
|
|
||||||
|
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
import ic2.api.item.IElectricItemManager;
|
|
||||||
import ic2.api.item.ISpecialElectricItem;
|
|
||||||
|
|
||||||
import appeng.api.config.PowerUnits;
|
|
||||||
import appeng.coremod.annotations.Integration.Interface;
|
|
||||||
import appeng.coremod.annotations.Integration.InterfaceList;
|
|
||||||
import appeng.coremod.annotations.Integration.Method;
|
|
||||||
import appeng.integration.IntegrationType;
|
|
||||||
|
|
||||||
|
|
||||||
@InterfaceList( value = {
|
|
||||||
@Interface( iface = "ic2.api.item.ISpecialElectricItem", iname = IntegrationType.IC2 ),
|
|
||||||
@Interface( iface = "ic2.api.item.IElectricItemManager", iname = IntegrationType.IC2 )
|
|
||||||
} )
|
|
||||||
public abstract class IC2 extends AERootPoweredItem implements IElectricItemManager, ISpecialElectricItem
|
|
||||||
{
|
|
||||||
public IC2( double powerCapacity )
|
|
||||||
{
|
|
||||||
super( powerCapacity );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double charge( ItemStack is, double amount, int tier, boolean ignoreTransferLimit, boolean simulate )
|
|
||||||
{
|
|
||||||
double addedAmt = amount;
|
|
||||||
double limit = this.getTransferLimit( is );
|
|
||||||
|
|
||||||
if( !ignoreTransferLimit && amount > limit )
|
|
||||||
{
|
|
||||||
addedAmt = limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
return addedAmt - ( (int) this.injectExternalPower( PowerUnits.EU, is, addedAmt, simulate ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double discharge( ItemStack itemStack, double amount, int tier, boolean ignoreTransferLimit, boolean externally, boolean simulate )
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getCharge( ItemStack is )
|
|
||||||
{
|
|
||||||
return (int) PowerUnits.AE.convertTo( PowerUnits.EU, this.getAECurrentPower( is ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUse( ItemStack is, double amount )
|
|
||||||
{
|
|
||||||
return this.getCharge( is ) > amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean use( ItemStack is, double amount, EntityLivingBase entity )
|
|
||||||
{
|
|
||||||
if( this.canUse( is, amount ) )
|
|
||||||
{
|
|
||||||
// use the power..
|
|
||||||
this.extractAEPower( is, PowerUnits.EU.convertTo( PowerUnits.AE, amount ) );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void chargeFromArmor( ItemStack itemStack, EntityLivingBase entity )
|
|
||||||
{
|
|
||||||
// wtf?
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getToolTip( ItemStack itemStack )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getMaxCharge( ItemStack itemStack )
|
|
||||||
{
|
|
||||||
return PowerUnits.AE.convertTo( PowerUnits.EU, this.getAEMaxPower( itemStack ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTier( ItemStack itemStack )
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private double getTransferLimit( ItemStack itemStack )
|
|
||||||
{
|
|
||||||
return Math.max( 32, this.getMaxCharge( itemStack ) / 200 );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Method( iname = IntegrationType.IC2 )
|
|
||||||
public IElectricItemManager getManager( ItemStack itemStack )
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -29,6 +29,7 @@ import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||||
import net.minecraftforge.energy.IEnergyStorage;
|
import net.minecraftforge.energy.IEnergyStorage;
|
||||||
|
|
||||||
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.config.PowerUnits;
|
import appeng.api.config.PowerUnits;
|
||||||
import appeng.api.implementations.items.IAEItemPowerStorage;
|
import appeng.api.implementations.items.IAEItemPowerStorage;
|
||||||
import appeng.capabilities.Capabilities;
|
import appeng.capabilities.Capabilities;
|
||||||
|
@ -96,7 +97,7 @@ class PoweredItemCapabilities implements ICapabilityProvider, IEnergyStorage
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
final double powerRemainder = this.item.injectAEPower( this.is, PowerUnits.RF.convertTo( PowerUnits.AE, maxReceive ) );
|
final double powerRemainder = this.item.injectAEPower( this.is, PowerUnits.RF.convertTo( PowerUnits.AE, maxReceive ), Actionable.MODULATE );
|
||||||
return maxReceive - (int) PowerUnits.AE.convertTo( PowerUnits.RF, powerRemainder );
|
return maxReceive - (int) PowerUnits.AE.convertTo( PowerUnits.RF, powerRemainder );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,13 +23,14 @@ import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
import cofh.redstoneflux.api.IEnergyContainerItem;
|
import cofh.redstoneflux.api.IEnergyContainerItem;
|
||||||
|
|
||||||
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.config.PowerUnits;
|
import appeng.api.config.PowerUnits;
|
||||||
import appeng.coremod.annotations.Integration.Interface;
|
import appeng.coremod.annotations.Integration.Interface;
|
||||||
import appeng.integration.IntegrationType;
|
import appeng.integration.IntegrationType;
|
||||||
|
|
||||||
|
|
||||||
@Interface( iface = "cofh.redstoneflux.api.IEnergyContainerItem", iname = IntegrationType.RFItem )
|
@Interface( iface = "cofh.redstoneflux.api.IEnergyContainerItem", iname = IntegrationType.RFItem )
|
||||||
public abstract class RedstoneFlux extends IC2 implements IEnergyContainerItem
|
public abstract class RedstoneFlux extends AEBasePoweredItem implements IEnergyContainerItem
|
||||||
{
|
{
|
||||||
public RedstoneFlux( final double powerCapacity )
|
public RedstoneFlux( final double powerCapacity )
|
||||||
{
|
{
|
||||||
|
@ -39,7 +40,10 @@ public abstract class RedstoneFlux extends IC2 implements IEnergyContainerItem
|
||||||
@Override
|
@Override
|
||||||
public int receiveEnergy( final ItemStack is, final int maxReceive, final boolean simulate )
|
public int receiveEnergy( final ItemStack is, final int maxReceive, final boolean simulate )
|
||||||
{
|
{
|
||||||
return maxReceive - (int) this.injectExternalPower( PowerUnits.RF, is, maxReceive, simulate );
|
final double convertedPower = PowerUnits.RF.convertTo( PowerUnits.AE, maxReceive );
|
||||||
|
final double overflow = (int) this.injectAEPower( is, convertedPower, simulate ? Actionable.SIMULATE : Actionable.MODULATE );
|
||||||
|
|
||||||
|
return (int) ( maxReceive - overflow );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,204 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.parts.layers;
|
|
||||||
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
|
|
||||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
|
||||||
import ic2.api.energy.tile.IEnergyEmitter;
|
|
||||||
import ic2.api.energy.tile.IEnergySink;
|
|
||||||
import ic2.api.energy.tile.IEnergyTile;
|
|
||||||
|
|
||||||
import appeng.api.parts.IPart;
|
|
||||||
import appeng.api.parts.IPartHost;
|
|
||||||
import appeng.api.parts.LayerBase;
|
|
||||||
import appeng.api.parts.LayerFlags;
|
|
||||||
import appeng.util.Platform;
|
|
||||||
|
|
||||||
|
|
||||||
public class LayerIEnergySink extends LayerBase implements IEnergySink
|
|
||||||
{
|
|
||||||
|
|
||||||
private TileEntity getEnergySinkTile()
|
|
||||||
{
|
|
||||||
IPartHost host = (IPartHost) this;
|
|
||||||
return host.getTile();
|
|
||||||
}
|
|
||||||
|
|
||||||
private World getEnergySinkWorld()
|
|
||||||
{
|
|
||||||
if( this.getEnergySinkTile() == null )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.getEnergySinkTile().getWorld();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isTileValid()
|
|
||||||
{
|
|
||||||
TileEntity te = this.getEnergySinkTile();
|
|
||||||
|
|
||||||
if( te == null )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !te.isInvalid() && te.getWorld().isBlockLoaded( te.getPos() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addToENet()
|
|
||||||
{
|
|
||||||
if( this.getEnergySinkWorld() == null )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// re-add
|
|
||||||
this.removeFromENet();
|
|
||||||
|
|
||||||
if( !this.isInIC2() && Platform.isServer() && this.isTileValid() )
|
|
||||||
{
|
|
||||||
this.getLayerFlags().add( LayerFlags.IC2_ENET );
|
|
||||||
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileLoadEvent( (IEnergyTile) this.getEnergySinkTile() ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeFromENet()
|
|
||||||
{
|
|
||||||
if( this.getEnergySinkWorld() == null )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( this.isInIC2() && Platform.isServer() )
|
|
||||||
{
|
|
||||||
this.getLayerFlags().remove( LayerFlags.IC2_ENET );
|
|
||||||
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileUnloadEvent( (IEnergyTile) this.getEnergySinkTile() ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean interestedInIC2()
|
|
||||||
{
|
|
||||||
if( !( (IPartHost) this ).isInWorld() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int interested = 0;
|
|
||||||
for( EnumFacing dir : EnumFacing.values() )
|
|
||||||
{
|
|
||||||
IPart part = this.getPart( dir );
|
|
||||||
if( part instanceof IEnergyTile )
|
|
||||||
{
|
|
||||||
interested++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return interested == 1;// if more then one tile is interested we need to abandon...
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void partChanged()
|
|
||||||
{
|
|
||||||
super.partChanged();
|
|
||||||
|
|
||||||
if( this.interestedInIC2() )
|
|
||||||
{
|
|
||||||
this.addToENet();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.removeFromENet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean acceptsEnergyFrom( IEnergyEmitter emitter, EnumFacing direction )
|
|
||||||
{
|
|
||||||
if( !this.isInIC2() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
IPart part = this.getPart( direction );
|
|
||||||
if( part instanceof IEnergySink )
|
|
||||||
{
|
|
||||||
return ( (IEnergyAcceptor) part ).acceptsEnergyFrom( emitter, direction );
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isInIC2()
|
|
||||||
{
|
|
||||||
return this.getLayerFlags().contains( LayerFlags.IC2_ENET );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getDemandedEnergy()
|
|
||||||
{
|
|
||||||
if( !this.isInIC2() )
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is a flawed implementation, that requires a change to the IC2 API.
|
|
||||||
|
|
||||||
for( EnumFacing dir : EnumFacing.values() )
|
|
||||||
{
|
|
||||||
IPart part = this.getPart( dir );
|
|
||||||
if( part instanceof IEnergySink )
|
|
||||||
{
|
|
||||||
// use lower number cause ic2 deletes power it sends that isn't received.
|
|
||||||
return ( (IEnergySink) part ).getDemandedEnergy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSinkTier()
|
|
||||||
{
|
|
||||||
return Integer.MAX_VALUE; // no real options here...
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double injectEnergy( EnumFacing directionFrom, double amount, double voltage )
|
|
||||||
{
|
|
||||||
if( !this.isInIC2() )
|
|
||||||
{
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
for( EnumFacing dir : EnumFacing.values() )
|
|
||||||
{
|
|
||||||
IPart part = this.getPart( dir );
|
|
||||||
if( part instanceof IEnergySink )
|
|
||||||
{
|
|
||||||
return ( (IEnergySink) part ).injectEnergy( directionFrom, amount, voltage );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,205 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.parts.layers;
|
|
||||||
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
|
|
||||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
|
||||||
import ic2.api.energy.tile.IEnergyEmitter;
|
|
||||||
import ic2.api.energy.tile.IEnergySource;
|
|
||||||
import ic2.api.energy.tile.IEnergyTile;
|
|
||||||
|
|
||||||
import appeng.api.parts.IPart;
|
|
||||||
import appeng.api.parts.IPartHost;
|
|
||||||
import appeng.api.parts.LayerBase;
|
|
||||||
import appeng.api.parts.LayerFlags;
|
|
||||||
import appeng.util.Platform;
|
|
||||||
|
|
||||||
|
|
||||||
public class LayerIEnergySource extends LayerBase implements IEnergySource
|
|
||||||
{
|
|
||||||
|
|
||||||
private TileEntity getEnergySourceTile()
|
|
||||||
{
|
|
||||||
IPartHost host = (IPartHost) this;
|
|
||||||
return host.getTile();
|
|
||||||
}
|
|
||||||
|
|
||||||
private World getEnergySourceWorld()
|
|
||||||
{
|
|
||||||
if( this.getEnergySourceTile() == null )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return this.getEnergySourceTile().getWorld();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isTileValid()
|
|
||||||
{
|
|
||||||
TileEntity te = this.getEnergySourceTile();
|
|
||||||
return te != null && !te.isInvalid();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addToENet()
|
|
||||||
{
|
|
||||||
if( this.getEnergySourceWorld() == null )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// re-add
|
|
||||||
this.removeFromENet();
|
|
||||||
|
|
||||||
if( !this.isInIC2() && Platform.isServer() && this.isTileValid() )
|
|
||||||
{
|
|
||||||
this.getLayerFlags().add( LayerFlags.IC2_ENET );
|
|
||||||
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileLoadEvent( (IEnergyTile) this.getEnergySourceTile() ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeFromENet()
|
|
||||||
{
|
|
||||||
if( this.getEnergySourceWorld() == null )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( this.isInIC2() && Platform.isServer() )
|
|
||||||
{
|
|
||||||
this.getLayerFlags().remove( LayerFlags.IC2_ENET );
|
|
||||||
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileUnloadEvent( (IEnergyTile) this.getEnergySourceTile() ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean interestedInIC2()
|
|
||||||
{
|
|
||||||
if( !( (IPartHost) this ).isInWorld() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int interested = 0;
|
|
||||||
for( EnumFacing dir : EnumFacing.values() )
|
|
||||||
{
|
|
||||||
IPart part = this.getPart( dir );
|
|
||||||
if( part instanceof IEnergyTile )
|
|
||||||
{
|
|
||||||
interested++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return interested == 1;// if more then one tile is interested we need to abandon...
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void partChanged()
|
|
||||||
{
|
|
||||||
super.partChanged();
|
|
||||||
|
|
||||||
if( this.interestedInIC2() )
|
|
||||||
{
|
|
||||||
this.addToENet();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.removeFromENet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean emitsEnergyTo( IEnergyAcceptor receiver, EnumFacing direction )
|
|
||||||
{
|
|
||||||
if( !this.isInIC2() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
IPart part = this.getPart( direction );
|
|
||||||
if( part instanceof IEnergyEmitter )
|
|
||||||
{
|
|
||||||
return ( (IEnergyEmitter) part ).emitsEnergyTo( receiver, direction );
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isInIC2()
|
|
||||||
{
|
|
||||||
return this.getLayerFlags().contains( LayerFlags.IC2_ENET );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getOfferedEnergy()
|
|
||||||
{
|
|
||||||
if( !this.isInIC2() )
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is a flawed implementation, that requires a change to the IC2 API.
|
|
||||||
|
|
||||||
for( EnumFacing dir : EnumFacing.values() )
|
|
||||||
{
|
|
||||||
IPart part = this.getPart( dir );
|
|
||||||
if( part instanceof IEnergySource )
|
|
||||||
{
|
|
||||||
// use lower number cause ic2 deletes power it sends that isn't received.
|
|
||||||
return ( (IEnergySource) part ).getOfferedEnergy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void drawEnergy( double amount )
|
|
||||||
{
|
|
||||||
// this is a flawed implementation, that requires a change to the IC2 API.
|
|
||||||
|
|
||||||
for( EnumFacing dir : EnumFacing.values() )
|
|
||||||
{
|
|
||||||
IPart part = this.getPart( dir );
|
|
||||||
if( part instanceof IEnergySource )
|
|
||||||
{
|
|
||||||
( (IEnergySource) part ).drawEnergy( amount );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSourceTier()
|
|
||||||
{
|
|
||||||
// this is a flawed implementation, that requires a change to the IC2 API.
|
|
||||||
|
|
||||||
for( EnumFacing dir : EnumFacing.values() )
|
|
||||||
{
|
|
||||||
IPart part = this.getPart( dir );
|
|
||||||
if( part instanceof IEnergySource )
|
|
||||||
{
|
|
||||||
return ( (IEnergySource) part ).getSourceTier();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -25,28 +25,22 @@ import java.util.List;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import ic2.api.energy.prefab.BasicSinkSource;
|
||||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||||
import ic2.api.energy.tile.IEnergyEmitter;
|
import ic2.api.energy.tile.IEnergyEmitter;
|
||||||
import ic2.api.energy.tile.IEnergySink;
|
|
||||||
import ic2.api.energy.tile.IEnergySource;
|
|
||||||
|
|
||||||
import appeng.api.config.PowerUnits;
|
import appeng.api.config.PowerUnits;
|
||||||
import appeng.api.parts.IPartModel;
|
import appeng.api.parts.IPartModel;
|
||||||
import appeng.coremod.annotations.Integration.Interface;
|
|
||||||
import appeng.coremod.annotations.Integration.InterfaceList;
|
|
||||||
import appeng.integration.IntegrationType;
|
|
||||||
import appeng.items.parts.PartModels;
|
import appeng.items.parts.PartModels;
|
||||||
import appeng.me.GridAccessException;
|
import appeng.me.GridAccessException;
|
||||||
import appeng.me.cache.helpers.TunnelCollection;
|
import appeng.me.cache.helpers.TunnelCollection;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
|
|
||||||
|
|
||||||
@InterfaceList( value = {
|
public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power>
|
||||||
@Interface( iface = "ic2.api.energy.tile.IEnergySink", iname = IntegrationType.IC2 ),
|
|
||||||
@Interface( iface = "ic2.api.energy.tile.IEnergySource", iname = IntegrationType.IC2 )
|
|
||||||
} )
|
|
||||||
public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements IEnergySink, IEnergySource
|
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final String TAG_BUFFERED_ENERGY_1 = "bufferedEnergy1";
|
private static final String TAG_BUFFERED_ENERGY_1 = "bufferedEnergy1";
|
||||||
|
@ -56,18 +50,14 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements I
|
||||||
|
|
||||||
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_ic2" );
|
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_ic2" );
|
||||||
|
|
||||||
@PartModels
|
|
||||||
public static List<IPartModel> getModels()
|
|
||||||
{
|
|
||||||
return MODELS.getModels();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Buffer the energy + voltage for two IC2 ENET packets
|
// Buffer the energy + voltage for two IC2 ENET packets
|
||||||
private double bufferedEnergy1;
|
private double bufferedEnergy1;
|
||||||
private double bufferedVoltage1;
|
private double bufferedVoltage1;
|
||||||
private double bufferedEnergy2;
|
private double bufferedEnergy2;
|
||||||
private double bufferedVoltage2;
|
private double bufferedVoltage2;
|
||||||
|
|
||||||
|
private BasicSinkSource sinkSource;
|
||||||
|
|
||||||
public PartP2PIC2Power( ItemStack is )
|
public PartP2PIC2Power( ItemStack is )
|
||||||
{
|
{
|
||||||
super( is );
|
super( is );
|
||||||
|
@ -96,38 +86,92 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements I
|
||||||
@Override
|
@Override
|
||||||
public void onTunnelConfigChange()
|
public void onTunnelConfigChange()
|
||||||
{
|
{
|
||||||
|
this.updateSinkSource();
|
||||||
this.getHost().partChanged();
|
this.getHost().partChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTunnelNetworkChange()
|
public void onTunnelNetworkChange()
|
||||||
{
|
{
|
||||||
|
this.updateSinkSource();
|
||||||
this.getHost().notifyNeighbors();
|
this.getHost().notifyNeighbors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptsEnergyFrom( IEnergyEmitter emitter, EnumFacing direction )
|
public void removeFromWorld()
|
||||||
{
|
{
|
||||||
return !this.isOutput() && direction == this.getSide().getFacing();
|
super.removeFromWorld();
|
||||||
|
this.invalidateSinkSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean emitsEnergyTo( IEnergyAcceptor receiver, EnumFacing direction )
|
public void addToWorld()
|
||||||
{
|
{
|
||||||
return this.isOutput() && direction == this.getSide().getFacing();
|
super.addToWorld();
|
||||||
|
this.updateSinkSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPartModel getStaticModels()
|
||||||
|
{
|
||||||
|
return MODELS.getModel( this.isPowered(), this.isActive() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@PartModels
|
||||||
|
public static List<IPartModel> getModels()
|
||||||
|
{
|
||||||
|
return MODELS.getModels();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSinkSource()
|
||||||
|
{
|
||||||
|
if( this.sinkSource == null )
|
||||||
|
{
|
||||||
|
this.sinkSource = new SinkSource( this.getHost().getTile().getWorld(), this.getHost().getLocation().getPos(), 2048, 4, 4 );
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sinkSource.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void invalidateSinkSource()
|
||||||
|
{
|
||||||
|
if( this.sinkSource != null )
|
||||||
|
{
|
||||||
|
this.sinkSource.invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SinkSource extends BasicSinkSource
|
||||||
|
{
|
||||||
|
|
||||||
|
SinkSource( World world, BlockPos pos, int i, int j, int k )
|
||||||
|
{
|
||||||
|
super( world, pos, i, j, k );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean emitsEnergyTo( IEnergyAcceptor receiver, EnumFacing side )
|
||||||
|
{
|
||||||
|
return PartP2PIC2Power.this.isOutput() && side == PartP2PIC2Power.this.getSide().getFacing();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean acceptsEnergyFrom( IEnergyEmitter emitter, EnumFacing side )
|
||||||
|
{
|
||||||
|
return !PartP2PIC2Power.this.isOutput() && side == PartP2PIC2Power.this.getSide().getFacing();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getDemandedEnergy()
|
public double getDemandedEnergy()
|
||||||
{
|
{
|
||||||
if( this.isOutput() )
|
if( PartP2PIC2Power.this.isOutput() )
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for( PartP2PIC2Power t : this.getOutputs() )
|
for( PartP2PIC2Power t : PartP2PIC2Power.this.getOutputs() )
|
||||||
{
|
{
|
||||||
if( t.bufferedEnergy1 <= 0.0001 || t.bufferedEnergy2 <= 0.0001 )
|
if( t.bufferedEnergy1 <= 0.0001 || t.bufferedEnergy2 <= 0.0001 )
|
||||||
{
|
{
|
||||||
|
@ -143,19 +187,13 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements I
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSinkTier()
|
|
||||||
{
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double injectEnergy( EnumFacing directionFrom, double amount, double voltage )
|
public double injectEnergy( EnumFacing directionFrom, double amount, double voltage )
|
||||||
{
|
{
|
||||||
TunnelCollection<PartP2PIC2Power> outs;
|
TunnelCollection<PartP2PIC2Power> outs;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
outs = this.getOutputs();
|
outs = PartP2PIC2Power.this.getOutputs();
|
||||||
}
|
}
|
||||||
catch( GridAccessException e )
|
catch( GridAccessException e )
|
||||||
{
|
{
|
||||||
|
@ -204,7 +242,7 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements I
|
||||||
|
|
||||||
if( x != null && x.bufferedEnergy1 <= 0.001 )
|
if( x != null && x.bufferedEnergy1 <= 0.001 )
|
||||||
{
|
{
|
||||||
this.queueTunnelDrain( PowerUnits.EU, amount );
|
PartP2PIC2Power.this.queueTunnelDrain( PowerUnits.EU, amount );
|
||||||
x.bufferedEnergy1 = amount;
|
x.bufferedEnergy1 = amount;
|
||||||
x.bufferedVoltage1 = voltage;
|
x.bufferedVoltage1 = voltage;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -212,7 +250,7 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements I
|
||||||
|
|
||||||
if( x != null && x.bufferedEnergy2 <= 0.001 )
|
if( x != null && x.bufferedEnergy2 <= 0.001 )
|
||||||
{
|
{
|
||||||
this.queueTunnelDrain( PowerUnits.EU, amount );
|
PartP2PIC2Power.this.queueTunnelDrain( PowerUnits.EU, amount );
|
||||||
x.bufferedEnergy2 = amount;
|
x.bufferedEnergy2 = amount;
|
||||||
x.bufferedVoltage2 = voltage;
|
x.bufferedVoltage2 = voltage;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -224,9 +262,9 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements I
|
||||||
@Override
|
@Override
|
||||||
public double getOfferedEnergy()
|
public double getOfferedEnergy()
|
||||||
{
|
{
|
||||||
if( this.isOutput() )
|
if( PartP2PIC2Power.this.isOutput() )
|
||||||
{
|
{
|
||||||
return this.bufferedEnergy1;
|
return PartP2PIC2Power.this.bufferedEnergy1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -234,30 +272,16 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements I
|
||||||
@Override
|
@Override
|
||||||
public void drawEnergy( double amount )
|
public void drawEnergy( double amount )
|
||||||
{
|
{
|
||||||
this.bufferedEnergy1 -= amount;
|
PartP2PIC2Power.this.bufferedEnergy1 -= amount;
|
||||||
if( this.bufferedEnergy1 < 0.001 )
|
if( PartP2PIC2Power.this.bufferedEnergy1 < 0.001 )
|
||||||
{
|
{
|
||||||
this.bufferedEnergy1 = this.bufferedEnergy2;
|
PartP2PIC2Power.this.bufferedEnergy1 = PartP2PIC2Power.this.bufferedEnergy2;
|
||||||
this.bufferedEnergy2 = 0;
|
PartP2PIC2Power.this.bufferedEnergy2 = 0;
|
||||||
|
|
||||||
this.bufferedVoltage1 = this.bufferedVoltage2;
|
PartP2PIC2Power.this.bufferedVoltage1 = PartP2PIC2Power.this.bufferedVoltage2;
|
||||||
this.bufferedVoltage2 = 0;
|
PartP2PIC2Power.this.bufferedVoltage2 = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSourceTier()
|
|
||||||
{
|
|
||||||
// Sadly IC2 doesn't support changing the tier once we're registered, so we
|
|
||||||
// go with the highest here... At this point it's somewhat unclear as to what effect
|
|
||||||
// this realistically has.
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPartModel getStaticModels()
|
|
||||||
{
|
|
||||||
return MODELS.getModel( this.isPowered(), this.isActive() );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -246,7 +246,7 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
|
||||||
{
|
{
|
||||||
final double oldPower = this.getInternalCurrentPower();
|
final double oldPower = this.getInternalCurrentPower();
|
||||||
|
|
||||||
final double adjustment = ps.injectAEPower( myItem, this.extractAEPower( 150.0, Actionable.MODULATE, PowerMultiplier.CONFIG ) );
|
final double adjustment = ps.injectAEPower( myItem, this.extractAEPower( 150.0, Actionable.MODULATE, PowerMultiplier.CONFIG ), Actionable.MODULATE );
|
||||||
this.setInternalCurrentPower( this.getInternalCurrentPower() + adjustment );
|
this.setInternalCurrentPower( this.getInternalCurrentPower() + adjustment );
|
||||||
|
|
||||||
if( oldPower > this.getInternalCurrentPower() )
|
if( oldPower > this.getInternalCurrentPower() )
|
||||||
|
|
|
@ -170,7 +170,6 @@ public class TileSkyChest extends AEBaseInvTile implements ITickable
|
||||||
|
|
||||||
public float getLidAngle()
|
public float getLidAngle()
|
||||||
{
|
{
|
||||||
// System.out.println( lidAngle );
|
|
||||||
return this.lidAngle;
|
return this.lidAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue