Compare commits

...

15 Commits

Author SHA1 Message Date
yueh 6c91e852ec Fixes #2608: Handle scrollbar on mouseclicks not during rendering. 2016-11-13 13:16:08 +01:00
yueh 52f516299b Fixes #2605: Formation plane now using the correct offset position. 2016-11-13 12:41:39 +01:00
yueh c74166b02a Restrict ItemHandlerAdaptor to not exceed the stacksize of a slot. (#2595) 2016-11-13 11:33:31 +01:00
yueh 26e86a114c Added an explicit ignore section to .gitignore
Current intention is to maintain a single blacklist for common OS
dependent files without having to define each and every folder and their
allowed filetypes to avoid commiting these.
2016-11-13 11:30:27 +01:00
yueh fc834036a0 Prevent hard to reproducable stacktraces from being swallowed. 2016-11-10 12:16:39 +01:00
yueh f96f7d82c5 Fixes #2544: NetworkTool now returns PASS for shift+right click on parts. 2016-11-10 11:55:13 +01:00
yueh c592f54a77 Fixes #2599: Missing instanceof EntityPlayerMP test. 2016-11-09 15:46:10 +01:00
yueh 89609a83ea Fixes #2593: Subtract the extracted not already gathered amount. 2016-11-07 13:33:11 +01:00
Sebastian Hartte e67969f52f Fixes #2566: Update packet deserialization was broken when parts were present that were not a grid host. 2016-11-07 00:44:53 +01:00
Sebastian Hartte 32a0496bc2 Fixes facade stilts sometimes being rendered using the facade texture's tint. 2016-11-07 00:17:24 +01:00
Sebastian Hartte 6df311c11a AE now accepts power via the legacy RF API (i.e. from Immersive Engineering). 2016-11-06 23:02:22 +01:00
Sebastian Hartte 2e23b92763 Added charging items via IC2 API. 2016-11-06 22:43:30 +01:00
Sebastian Hartte 41a029ffb4 Added item charging via legacy RF API. 2016-11-06 22:22:49 +01:00
Sebastian Hartte 9c8f914f42 Added CoFH Energy API. 2016-11-06 22:22:34 +01:00
shartte d75cdc9696 Gradle Source Set Changes (#2588)
Introduced separate source sets for "api" and "apis" (in preparation for source only 3rd party APIs).
2016-11-06 21:55:58 +01:00
31 changed files with 1120 additions and 213 deletions
+4 -1
View File
@@ -25,4 +25,7 @@
!codeformat/
# Github specific files and directories
!.github/
!.github/
# Explicit ignores
Thumbs.db
+16 -18
View File
@@ -55,6 +55,9 @@ jar {
attributes 'FMLCorePluginContainsFMLMod': 'true'
}
from sourceSets.api.output
dependsOn apiClasses
// specify which files are really included, can control which APIs should be in
include "appeng/**"
include "assets/**"
@@ -81,26 +84,21 @@ minecraft {
}
sourceSets {
main {
java {
srcDirs += 'src/api/java'
srcDirs += 'src/main/java/'
}
resources {
srcDir "src/main/resources/"
include "assets/appliedenergistics2/recipes/**/*.recipe",
"assets/appliedenergistics2/recipes/README.html",
"assets/appliedenergistics2/lang/*.lang",
"assets/appliedenergistics2/blockstates/**/*.json",
"assets/appliedenergistics2/models/**/*.json",
"assets/appliedenergistics2/textures/**/*.png",
"assets/appliedenergistics2/textures/**/*.mcmeta",
"assets/appliedenergistics2/meta/*",
"mcmod.info",
"pack.mcmeta"
}
api
// This source set will contain third party API code that we need to compile, but which is not shipped with the jar
thirdparty {
// Third Party APIs often need access to Minecraft classes (i.e. EnumFacing), so set this up here
compileClasspath += configurations.forgeGradleMc + configurations.forgeGradleMcDeps
}
main
}
dependencies {
compile sourceSets.thirdparty.output
}
processResources
+1 -1
View File
@@ -46,7 +46,7 @@ task apiJar(type: Jar) {
from sourceSets.api.java
include "appeng/api/**"
from sourceSets.main.output
from sourceSets.api.output
include "appeng/api/**"
classifier = 'api'
+27 -14
View File
@@ -161,12 +161,6 @@ public abstract class AEBaseGui extends GuiContainer
{
super.drawScreen( mouseX, mouseY, btn );
final boolean hasClicked = Mouse.isButtonDown( 0 );
if( hasClicked && this.getScrollBar() != null )
{
this.getScrollBar().click( this, mouseX - this.guiLeft, mouseY - this.guiTop );
}
for( final Object c : this.buttonList )
{
if( c instanceof ITooltip )
@@ -258,13 +252,15 @@ public abstract class AEBaseGui extends GuiContainer
{
if( fs.isEnabled() )
{
this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.getSourceX() - 1, fs.getSourceY() - 1, 18, 18 );
this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.getSourceX() - 1, fs.getSourceY() - 1, 18,
18 );
}
else
{
GlStateManager.color( 1.0F, 1.0F, 1.0F, 0.4F );
GlStateManager.enableBlend();
this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.getSourceX() - 1, fs.getSourceY() - 1, 18, 18 );
this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.getSourceX() - 1, fs.getSourceY() - 1, 18,
18 );
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
}
}
@@ -290,6 +286,11 @@ public abstract class AEBaseGui extends GuiContainer
}
}
if( this.getScrollBar() != null )
{
this.getScrollBar().click( this, xCoord - this.guiLeft, yCoord - this.guiTop );
}
super.mouseClicked( xCoord, yCoord, btn );
}
@@ -299,6 +300,11 @@ public abstract class AEBaseGui extends GuiContainer
final Slot slot = this.getSlot( x, y );
final ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack();
if( this.getScrollBar() != null )
{
this.getScrollBar().click( this, x - this.guiLeft, y - this.guiTop );
}
if( slot instanceof SlotFake && itemstack != null )
{
this.drag_click.add( slot );
@@ -515,7 +521,9 @@ public abstract class AEBaseGui extends GuiContainer
final List<Slot> slots = this.getInventorySlots();
for( final Slot inventorySlot : slots )
{
if( inventorySlot != null && inventorySlot.canTakeStack( this.mc.thePlayer ) && inventorySlot.getHasStack() && inventorySlot.inventory == slot.inventory && Container.canAddItemToSlot( inventorySlot, this.dbl_whichItem, true ) )
if( inventorySlot != null && inventorySlot.canTakeStack(
this.mc.thePlayer ) && inventorySlot.getHasStack() && inventorySlot.inventory == slot.inventory && Container.canAddItemToSlot(
inventorySlot, this.dbl_whichItem, true ) )
{
this.handleMouseClick( inventorySlot, inventorySlot.slotNumber, 1, clickType );
}
@@ -759,11 +767,15 @@ public abstract class AEBaseGui extends GuiContainer
final float f1 = 0.00390625F;
final float f = 0.00390625F;
final float par6 = 16;
vb.pos( par1 + 0, par2 + par6, this.zLevel ).tex( ( par3 + 0 ) * f, ( par4 + par6 ) * f1 ).color( 1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon() ).endVertex();
vb.pos( par1 + 0, par2 + par6, this.zLevel ).tex( ( par3 + 0 ) * f, ( par4 + par6 ) * f1 ).color( 1.0f, 1.0f, 1.0f,
aes.getOpacityOfIcon() ).endVertex();
final float par5 = 16;
vb.pos( par1 + par5, par2 + par6, this.zLevel ).tex( ( par3 + par5 ) * f, ( par4 + par6 ) * f1 ).color( 1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon() ).endVertex();
vb.pos( par1 + par5, par2 + 0, this.zLevel ).tex( ( par3 + par5 ) * f, ( par4 + 0 ) * f1 ).color( 1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon() ).endVertex();
vb.pos( par1 + 0, par2 + 0, this.zLevel ).tex( ( par3 + 0 ) * f, ( par4 + 0 ) * f1 ).color( 1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon() ).endVertex();
vb.pos( par1 + par5, par2 + par6, this.zLevel ).tex( ( par3 + par5 ) * f, ( par4 + par6 ) * f1 ).color( 1.0f, 1.0f, 1.0f,
aes.getOpacityOfIcon() ).endVertex();
vb.pos( par1 + par5, par2 + 0, this.zLevel ).tex( ( par3 + par5 ) * f, ( par4 + 0 ) * f1 ).color( 1.0f, 1.0f, 1.0f,
aes.getOpacityOfIcon() ).endVertex();
vb.pos( par1 + 0, par2 + 0, this.zLevel ).tex( ( par3 + 0 ) * f, ( par4 + 0 ) * f1 ).color( 1.0f, 1.0f, 1.0f,
aes.getOpacityOfIcon() ).endVertex();
tessellator.draw();
}
@@ -777,7 +789,8 @@ public abstract class AEBaseGui extends GuiContainer
{
if( ( (AppEngSlot) s ).getIsValid() == hasCalculatedValidness.NotAvailable )
{
boolean isValid = s.isItemValid( is ) || s instanceof SlotOutput || s instanceof AppEngCraftingSlot || s instanceof SlotDisabled || s instanceof SlotInaccessible || s instanceof SlotFake || s instanceof SlotRestrictedInput || s instanceof SlotDisconnected;
boolean isValid = s.isItemValid(
is ) || s instanceof SlotOutput || s instanceof AppEngCraftingSlot || s instanceof SlotDisabled || s instanceof SlotInaccessible || s instanceof SlotFake || s instanceof SlotRestrictedInput || s instanceof SlotDisconnected;
if( isValid && s instanceof SlotRestrictedInput )
{
try
@@ -174,6 +174,9 @@ public class FacadeBuilder
builder.setDrawFaces( EnumSet.allOf( EnumFacing.class ) );
// Reset to no color multiplicator
builder.setColorRGB( 0xFFFFFF );
// We only render the stilt if we don't intersect with any part directly, and if there's no part on our side
if( renderStilt && busBounds == null && layer == BlockRenderLayer.CUTOUT )
{
@@ -97,7 +97,10 @@ public class SyncData
}
else if( val instanceof Long || val.getClass() == long.class )
{
NetworkHandler.instance.sendTo( new PacketProgressBar( this.channel, (Long) val ), (EntityPlayerMP) o );
if( o instanceof EntityPlayerMP )
{
NetworkHandler.instance.sendTo( new PacketProgressBar( this.channel, (Long) val ), (EntityPlayerMP) o );
}
}
else if( val instanceof Boolean || val.getClass() == boolean.class )
{
@@ -186,15 +186,18 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
if( sideLocal != sideRemote )
{
this.clientCM.putSetting( set, sideLocal );
for( final Object crafter : this.listeners )
for( final IContainerListener crafter : this.listeners )
{
try
if( crafter instanceof EntityPlayerMP )
{
NetworkHandler.instance.sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (EntityPlayerMP) crafter );
}
catch( final IOException e )
{
AELog.debug( e );
try
{
NetworkHandler.instance.sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (EntityPlayerMP) crafter );
}
catch( final IOException e )
{
AELog.debug( e );
}
}
}
}
@@ -258,6 +261,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
super.detectAndSendChanges();
}
}
protected void updatePowerStatus()
@@ -340,7 +344,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
}
}
}
@Override
public void removeListener( final IContainerListener c )
{
@@ -107,6 +107,10 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench /
{
return EnumActionResult.FAIL;
}
else if( player.isSneaking() )
{
return EnumActionResult.PASS;
}
}
}
else if( te instanceof INetworkToolAgent && !( (INetworkToolAgent) te ).showNetworkInfo( mop ) )
@@ -19,7 +19,7 @@
package appeng.items.tools.powered.powersink;
public abstract class AEBasePoweredItem extends AERootPoweredItem
public abstract class AEBasePoweredItem extends RedstoneFlux
{
public AEBasePoweredItem( final double powerCapacity )
{
@@ -146,6 +146,27 @@ public abstract class AERootPoweredItem extends AEBaseItem implements IAEItemPow
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 )
{
@@ -19,126 +19,107 @@
package appeng.items.tools.powered.powersink;
//import java.util.Optional;
//
//import net.minecraft.entity.EntityLivingBase;
//import net.minecraft.item.Item;
//import net.minecraft.item.ItemStack;
//
//import ic2.api.item.IElectricItemManager;
//import ic2.api.item.ISpecialElectricItem;
//
//import appeng.api.config.PowerUnits;
//import appeng.integration.IntegrationType;
//import appeng.transformer.annotations.Integration.Interface;
//import appeng.transformer.annotations.Integration.InterfaceList;
//import appeng.transformer.annotations.Integration.Method;
//
//
//@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, Optional<String> subName )
// {
// super( powerCapacity, subName );
// }
//
// @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 boolean canProvideEnergy( ItemStack itemStack )
// {
// return false;
// }
//
// @Override
// public Item getChargedItem( ItemStack itemStack )
// {
// return itemStack.getItem();
// }
//
// @Override
// public Item getEmptyItem( ItemStack itemStack )
// {
// return itemStack.getItem();
// }
//
// @Override
// public double getMaxCharge( ItemStack itemStack )
// {
// return PowerUnits.AE.convertTo( PowerUnits.EU, this.getAEMaxPower( itemStack ) );
// }
//
// @Override
// public int getTier( ItemStack itemStack )
// {
// return 1;
// }
//
// @Override
// public double getTransferLimit( ItemStack itemStack )
// {
// return Math.max( 32, this.getMaxCharge( itemStack ) / 200 );
// }
//
// @Override
// @Method( iname = IntegrationType.IC2 )
// public IElectricItemManager getManager( ItemStack itemStack )
// {
// return this;
// }
// }
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.integration.IntegrationType;
import appeng.transformer.annotations.Integration.Interface;
import appeng.transformer.annotations.Integration.InterfaceList;
import appeng.transformer.annotations.Integration.Method;
@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;
}
}
@@ -0,0 +1,62 @@
/*
* 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.item.ItemStack;
import cofh.api.energy.IEnergyContainerItem;
import appeng.api.config.PowerUnits;
import appeng.integration.IntegrationType;
import appeng.transformer.annotations.Integration.Interface;
@Interface( iface = "cofh.api.energy.IEnergyContainerItem", iname = IntegrationType.RFItem )
public abstract class RedstoneFlux extends IC2 implements IEnergyContainerItem
{
public RedstoneFlux( final double powerCapacity )
{
super( powerCapacity );
}
@Override
public int receiveEnergy( final ItemStack is, final int maxReceive, final boolean simulate )
{
return maxReceive - (int) this.injectExternalPower( PowerUnits.RF, is, maxReceive, simulate );
}
@Override
public int extractEnergy( final ItemStack container, final int maxExtract, final boolean simulate )
{
return 0;
}
@Override
public int getEnergyStored( final ItemStack is )
{
return (int) PowerUnits.AE.convertTo( PowerUnits.RF, this.getAECurrentPower( is ) );
}
@Override
public int getMaxEnergyStored( final ItemStack is )
{
return (int) PowerUnits.AE.convertTo( PowerUnits.RF, this.getAEMaxPower( is ) );
}
}
+2 -3
View File
@@ -185,9 +185,8 @@ public class NetworkEventBus
catch( final Throwable e1 )
{
AELog.error( "[AppEng] Network Event caused exception:" );
AELog.error( "Offending Class: " + obj.getClass().getName() );
AELog.error( "Offending Object: " + obj.toString() );
AELog.debug( e1 );
AELog.error( "Class: %1s, Object: %2s", obj.getClass().getName(), obj.toString() );
AELog.info( e1 );
throw new IllegalStateException( e1 );
}
@@ -447,7 +447,8 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
if( w.getBlockState( tePos ).getBlock().isReplaceable( w, tePos ) )
{
if( placeBlock == YesNo.YES && ( i instanceof ItemBlock || i instanceof IPlantable || i instanceof ItemSkull || i instanceof ItemFirework || i instanceof IPartItem || i == Item.getItemFromBlock( Blocks.REEDS ) ) )
if( placeBlock == YesNo.YES && ( i instanceof ItemBlock || i instanceof IPlantable || i instanceof ItemSkull || i instanceof ItemFirework || i instanceof IPartItem || i == Item.getItemFromBlock(
Blocks.REEDS ) ) )
{
final EntityPlayer player = Platform.getPlayer( (WorldServer) w );
Platform.configurePlayer( player, side, this.getTile() );
@@ -479,17 +480,20 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
if( side.xOffset == 0 && side.zOffset == 0 )
{
Worked = i.onItemUse( is, player, w, tePos.offset( side.getFacing() ), null, side.getFacing().getOpposite(), side.xOffset, side.yOffset, side.zOffset ) == EnumActionResult.SUCCESS;
Worked = i.onItemUse( is, player, w, tePos.offset( side.getFacing() ), null, side.getFacing().getOpposite(), side.xOffset,
side.yOffset, side.zOffset ) == EnumActionResult.SUCCESS;
}
if( !Worked && side.xOffset == 0 && side.zOffset == 0 )
{
Worked = i.onItemUse( is, player, w, tePos.offset( side.getFacing().getOpposite() ), null, side.getFacing(), side.xOffset, side.yOffset, side.zOffset ) == EnumActionResult.SUCCESS;
Worked = i.onItemUse( is, player, w, tePos.offset( side.getFacing().getOpposite() ), null, side.getFacing(), side.xOffset,
side.yOffset, side.zOffset ) == EnumActionResult.SUCCESS;
}
if( !Worked && side.yOffset == 0 )
{
Worked = i.onItemUse( is, player, w, tePos.offset( EnumFacing.DOWN ), null, EnumFacing.UP, side.xOffset, side.yOffset, side.zOffset ) == EnumActionResult.SUCCESS;
Worked = i.onItemUse( is, player, w, tePos.offset( EnumFacing.DOWN ), null, EnumFacing.UP, side.xOffset, side.yOffset,
side.zOffset ) == EnumActionResult.SUCCESS;
}
if( !Worked )
@@ -529,13 +533,12 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
{
if( type == Actionable.MODULATE )
{
is.stackSize = (int) maxStorage;
final EntityItem ei = new EntityItem( w, // w
( ( side.xOffset != 0 ? 0.0 : 0.7 ) * ( Platform.getRandomFloat() - 0.5f ) ) + 0.5 + side.xOffset * -0.3 + tePos.getX(), // spawn
( ( side.yOffset != 0 ? 0.0 : 0.7 ) * ( Platform.getRandomFloat() - 0.5f ) ) + 0.5 + side.yOffset * -0.3 + tePos.getY(), // spawn
( ( side.zOffset != 0 ? 0.0 : 0.7 ) * ( Platform.getRandomFloat() - 0.5f ) ) + 0.5 + side.zOffset * -0.3 + tePos.getZ(), // spawn
is.copy() );
final double x = ( side.xOffset != 0 ? 0 : .7 * ( Platform.getRandomFloat() - .5 ) ) + side.xOffset + .5 + te.getPos().getX();
final double y = ( side.yOffset != 0 ? 0 : .7 * ( Platform.getRandomFloat() - .5 ) ) + side.yOffset + .5 + te.getPos().getY();
final double z = ( side.zOffset != 0 ? 0 : .7 * ( Platform.getRandomFloat() - .5 ) ) + side.zOffset + .5 + te.getPos().getZ();
final EntityItem ei = new EntityItem( w, x, y, z, is.copy() );
Entity result = ei;
@@ -99,8 +99,8 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, BaseActionSource src )
{
ItemStack req = request.getItemStack();
int remainingSize = req.stackSize;
ItemStack requestedItemStack = request.getItemStack();
int remainingSize = requestedItemStack.stackSize;
// Use this to gather the requested items
ItemStack gathered = null;
@@ -109,28 +109,30 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
for( int i = 0; i < itemHandler.getSlots(); i++ )
{
ItemStack sub = itemHandler.getStackInSlot( i );
ItemStack stackInInventorySlot = itemHandler.getStackInSlot( i );
if( !Platform.itemComparisons().isSameItem( sub, req ) )
if( !Platform.itemComparisons().isSameItem( stackInInventorySlot, requestedItemStack ) )
{
continue;
}
ItemStack extracted;
int remainingCurrentSlot = Math.min( remainingSize, stackInInventorySlot.stackSize );
// We have to loop here because according to the docs, the handler shouldn't return a stack with size > maxSize, even if we
// request more. So even if it returns a valid stack, it might have more stuff.
// We have to loop here because according to the docs, the handler shouldn't return a stack with size >
// maxSize, even if we request more. So even if it returns a valid stack, it might have more stuff.
do
{
extracted = itemHandler.extractItem( i, remainingSize, simulate );
extracted = itemHandler.extractItem( i, remainingCurrentSlot, simulate );
if( extracted != null )
{
if( extracted.stackSize > remainingSize )
if( extracted.stackSize > remainingCurrentSlot )
{
// Something broke. It should never return more than we requested... We're going to silently eat the remainder
AELog.warn( "Mod that provided item handler {} is broken. Returned {} items, even though we requested {}.",
itemHandler.getClass().getSimpleName(), extracted.stackSize, remainingSize );
extracted.stackSize = remainingSize;
// Something broke. It should never return more than we requested...
// We're going to silently eat the remainder
AELog.warn( "Mod that provided item handler %1 is broken. Returned %2 items, even though we requested %3.",
itemHandler.getClass().getSimpleName(), extracted.stackSize, remainingCurrentSlot );
extracted.stackSize = remainingCurrentSlot;
}
// We're just gonna use the first stack we get our hands on as the template for the rest
@@ -142,10 +144,12 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
{
gathered.stackSize += extracted.stackSize;
}
remainingSize -= gathered.stackSize;
remainingCurrentSlot -= extracted.stackSize;
}
}
while( extracted != null && remainingSize > 0 );
while( extracted != null && remainingCurrentSlot > 0 );
remainingSize -= remainingCurrentSlot;
// Done?
if( remainingSize <= 0 )
@@ -290,27 +290,28 @@ public class PartCable extends AEBasePart implements IPartCable
boolean[] writeSide = new boolean[EnumFacing.values().length];
int[] channelsPerSide = new int[EnumFacing.values().length];
for( EnumFacing thisSide : EnumFacing.values() )
{
final IPart part = this.getHost().getPart( thisSide );
if( part != null )
{
writeSide[thisSide.ordinal()] = true;
int channels = 0;
if( part.getGridNode() != null )
{
final IReadOnlyCollection<IGridConnection> set = part.getGridNode().getConnections();
for( final IGridConnection gc : set )
{
channels = Math.max( channels, gc.getUsedChannels() );
}
}
channelsPerSide[thisSide.ordinal()] = channels;
}
}
IGridNode n = this.getGridNode();
if( n != null )
{
for( EnumFacing thisSide : EnumFacing.values() )
{
final IPart part = this.getHost().getPart( thisSide );
if( part != null )
{
if( part.getGridNode() != null )
{
writeSide[thisSide.ordinal()] = true;
final IReadOnlyCollection<IGridConnection> set = part.getGridNode().getConnections();
for( final IGridConnection gc : set )
{
channelsPerSide[thisSide.ordinal()] = gc.getUsedChannels();
}
}
}
}
for( final IGridConnection gc : n.getConnections() )
{
final AEPartLocation side = gc.getDirection( n );
@@ -19,7 +19,7 @@
package appeng.tile.powersink;
public abstract class AEBasePoweredTile extends AERootPoweredTile // extends MekJoules
public abstract class AEBasePoweredTile extends RedstoneFlux
{
}
@@ -0,0 +1,65 @@
/*
* 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;
import net.minecraft.util.EnumFacing;
import cofh.api.energy.IEnergyReceiver;
import appeng.api.config.PowerUnits;
import appeng.integration.IntegrationType;
import appeng.transformer.annotations.Integration.Interface;
@Interface( iname = IntegrationType.RF, iface = "cofh.api.energy.IEnergyReceiver" )
public abstract class RedstoneFlux extends AERootPoweredTile implements IEnergyReceiver
{
@Override
public final int receiveEnergy( final EnumFacing from, final int maxReceive, final boolean simulate )
{
final int networkRFDemand = (int) Math.floor( this.getExternalPowerDemand( PowerUnits.RF, maxReceive ) );
final int usedRF = Math.min( maxReceive, networkRFDemand );
if( !simulate )
{
this.injectExternalPower( PowerUnits.RF, usedRF );
}
return usedRF;
}
@Override
public final int getEnergyStored( final EnumFacing from )
{
return (int) Math.floor( PowerUnits.AE.convertTo( PowerUnits.RF, this.getAECurrentPower() ) );
}
@Override
public final int getMaxEnergyStored( final EnumFacing from )
{
return (int) Math.floor( PowerUnits.AE.convertTo( PowerUnits.RF, this.getAEMaxPower() ) );
}
@Override
public final boolean canConnectEnergy( final EnumFacing from )
{
return this.getPowerSides().contains( from );
}
}
+165
View File
@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
+11
View File
@@ -0,0 +1,11 @@
package cofh.api;
public class CoFHAPIProps {
private CoFHAPIProps() {
}
public static final String VERSION = "1.8.9R1.2.0B1";
}
+162
View File
@@ -0,0 +1,162 @@
package cofh.api.energy;
import net.minecraft.nbt.NBTTagCompound;
/**
* Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your own.
*
* @author King Lemming
*
*/
public class EnergyStorage implements IEnergyStorage {
protected int energy;
protected int capacity;
protected int maxReceive;
protected int maxExtract;
public EnergyStorage(int capacity) {
this(capacity, capacity, capacity);
}
public EnergyStorage(int capacity, int maxTransfer) {
this(capacity, maxTransfer, maxTransfer);
}
public EnergyStorage(int capacity, int maxReceive, int maxExtract) {
this.capacity = capacity;
this.maxReceive = maxReceive;
this.maxExtract = maxExtract;
}
public EnergyStorage readFromNBT(NBTTagCompound nbt) {
this.energy = nbt.getInteger("Energy");
if (energy > capacity) {
energy = capacity;
}
return this;
}
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
if (energy < 0) {
energy = 0;
}
nbt.setInteger("Energy", energy);
return nbt;
}
public EnergyStorage setCapacity(int capacity) {
this.capacity = capacity;
if (energy > capacity) {
energy = capacity;
}
return this;
}
public EnergyStorage setMaxTransfer(int maxTransfer) {
setMaxReceive(maxTransfer);
setMaxExtract(maxTransfer);
return this;
}
public EnergyStorage setMaxReceive(int maxReceive) {
this.maxReceive = maxReceive;
return this;
}
public EnergyStorage setMaxExtract(int maxExtract) {
this.maxExtract = maxExtract;
return this;
}
public int getMaxReceive() {
return maxReceive;
}
public int getMaxExtract() {
return maxExtract;
}
/**
* This function is included to allow for server to client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers
* are guaranteed to have it.
*
* @param energy
*/
public void setEnergyStored(int energy) {
this.energy = energy;
if (this.energy > capacity) {
this.energy = capacity;
} else if (this.energy < 0) {
this.energy = 0;
}
}
/**
* This function is included to allow the containing tile to directly and efficiently modify the energy contained in the EnergyStorage. Do not rely on this
* externally, as not all IEnergyHandlers are guaranteed to have it.
*
* @param energy
*/
public void modifyEnergyStored(int energy) {
this.energy += energy;
if (this.energy > capacity) {
this.energy = capacity;
} else if (this.energy < 0) {
this.energy = 0;
}
}
/* IEnergyStorage */
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
if (!simulate) {
energy += energyReceived;
}
return energyReceived;
}
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));
if (!simulate) {
energy -= energyExtracted;
}
return energyExtracted;
}
@Override
public int getEnergyStored() {
return energy;
}
@Override
public int getMaxEnergyStored() {
return capacity;
}
}
@@ -0,0 +1,22 @@
package cofh.api.energy;
import net.minecraft.util.EnumFacing;
/**
* Implement this interface on TileEntities which should connect to energy transportation blocks. This is intended for blocks which generate energy but do not
* accept it; otherwise just use IEnergyHandler.
* <p>
* Note that {@link IEnergyHandler} is an extension of this.
*
* @author King Lemming
*
*/
public interface IEnergyConnection {
/**
* Returns TRUE if the TileEntity can connect on a given side.
*/
boolean canConnectEnergy(EnumFacing from);
}
@@ -0,0 +1,52 @@
package cofh.api.energy;
import net.minecraft.item.ItemStack;
/**
* Implement this interface on Item classes that support external manipulation of their internal energy storages.
* <p>
* A reference implementation is provided {@link ItemEnergyContainer}.
*
* @author King Lemming
*
*/
public interface IEnergyContainerItem {
/**
* Adds energy to a container item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged.
*
* @param container
* ItemStack to be charged.
* @param maxReceive
* Maximum amount of energy to be sent into the item.
* @param simulate
* If TRUE, the charge will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) received by the item.
*/
int receiveEnergy(ItemStack container, int maxReceive, boolean simulate);
/**
* Removes energy from a container item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally
* discharged.
*
* @param container
* ItemStack to be discharged.
* @param maxExtract
* Maximum amount of energy to be extracted from the item.
* @param simulate
* If TRUE, the discharge will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) extracted from the item.
*/
int extractEnergy(ItemStack container, int maxExtract, boolean simulate);
/**
* Get the amount of energy currently stored in the container item.
*/
int getEnergyStored(ItemStack container);
/**
* Get the max amount of energy that can be stored in the container item.
*/
int getMaxEnergyStored(ItemStack container);
}
+27
View File
@@ -0,0 +1,27 @@
package cofh.api.energy;
import net.minecraft.util.EnumFacing;
/**
* Implement this interface on Tile Entities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
* <p>
* A reference implementation is provided {@link TileEnergyHandler}.
* <p>
* Note that {@link IEnergyReceiver} and {@link IEnergyProvider} are extensions of this.
*
* @author King Lemming
*
*/
public interface IEnergyHandler extends IEnergyConnection {
/**
* Returns the amount of energy currently stored.
*/
int getEnergyStored(EnumFacing from);
/**
* Returns the maximum amount of energy that can be stored.
*/
int getMaxEnergyStored(EnumFacing from);
}
@@ -0,0 +1,29 @@
package cofh.api.energy;
import net.minecraft.util.EnumFacing;
/**
* Implement this interface on Tile Entities which should provide energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
* <p>
* A reference implementation is provided {@link TileEnergyHandler}.
*
* @author King Lemming
*
*/
public interface IEnergyProvider extends IEnergyHandler {
/**
* Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider.
*
* @param from
* Orientation the energy is extracted from.
* @param maxExtract
* Maximum amount of energy to extract.
* @param simulate
* If TRUE, the extraction will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) extracted.
*/
int extractEnergy(EnumFacing from, int maxExtract, boolean simulate);
}
@@ -0,0 +1,29 @@
package cofh.api.energy;
import net.minecraft.util.EnumFacing;
/**
* Implement this interface on Tile Entities which should receive energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
* <p>
* A reference implementation is provided {@link TileEnergyHandler}.
*
* @author King Lemming
*
*/
public interface IEnergyReceiver extends IEnergyHandler {
/**
* Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver.
*
* @param from
* Orientation the energy is received from.
* @param maxReceive
* Maximum amount of energy to receive.
* @param simulate
* If TRUE, the charge will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) received.
*/
int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate);
}
+46
View File
@@ -0,0 +1,46 @@
package cofh.api.energy;
/**
* An energy storage is the unit of interaction with Energy inventories.<br>
* This is not to be implemented on TileEntities. This is for internal use only.
* <p>
* A reference implementation can be found at {@link EnergyStorage}.
*
* @author King Lemming
*
*/
public interface IEnergyStorage {
/**
* Adds energy to the storage. Returns quantity of energy that was accepted.
*
* @param maxReceive
* Maximum amount of energy to be inserted.
* @param simulate
* If TRUE, the insertion will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) accepted by the storage.
*/
int receiveEnergy(int maxReceive, boolean simulate);
/**
* Removes energy from the storage. Returns quantity of energy that was removed.
*
* @param maxExtract
* Maximum amount of energy to be extracted.
* @param simulate
* If TRUE, the extraction will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) extracted from the storage.
*/
int extractEnergy(int maxExtract, boolean simulate);
/**
* Returns the amount of energy currently stored.
*/
int getEnergyStored();
/**
* Returns the maximum amount of energy that can be stored.
*/
int getMaxEnergyStored();
}
@@ -0,0 +1,113 @@
package cofh.api.energy;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
/**
* Reference implementation of {@link IEnergyContainerItem}. Use/extend this or implement your own.
*
* @author King Lemming
*
*/
public class ItemEnergyContainer extends Item implements IEnergyContainerItem {
protected int capacity;
protected int maxReceive;
protected int maxExtract;
public ItemEnergyContainer() {
}
public ItemEnergyContainer(int capacity) {
this(capacity, capacity, capacity);
}
public ItemEnergyContainer(int capacity, int maxTransfer) {
this(capacity, maxTransfer, maxTransfer);
}
public ItemEnergyContainer(int capacity, int maxReceive, int maxExtract) {
this.capacity = capacity;
this.maxReceive = maxReceive;
this.maxExtract = maxExtract;
}
public ItemEnergyContainer setCapacity(int capacity) {
this.capacity = capacity;
return this;
}
public ItemEnergyContainer setMaxTransfer(int maxTransfer) {
setMaxReceive(maxTransfer);
setMaxExtract(maxTransfer);
return this;
}
public ItemEnergyContainer setMaxReceive(int maxReceive) {
this.maxReceive = maxReceive;
return this;
}
public ItemEnergyContainer setMaxExtract(int maxExtract) {
this.maxExtract = maxExtract;
return this;
}
/* IEnergyContainerItem */
@Override
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
if (!container.hasTagCompound()) {
container.setTagCompound(new NBTTagCompound());
}
int energy = container.getTagCompound().getInteger("Energy");
int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
if (!simulate) {
energy += energyReceived;
container.getTagCompound().setInteger("Energy", energy);
}
return energyReceived;
}
@Override
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
if (container.getTagCompound() == null || !container.getTagCompound().hasKey("Energy")) {
return 0;
}
int energy = container.getTagCompound().getInteger("Energy");
int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));
if (!simulate) {
energy -= energyExtracted;
container.getTagCompound().setInteger("Energy", energy);
}
return energyExtracted;
}
@Override
public int getEnergyStored(ItemStack container) {
if (container.getTagCompound() == null || !container.getTagCompound().hasKey("Energy")) {
return 0;
}
return container.getTagCompound().getInteger("Energy");
}
@Override
public int getMaxEnergyStored(ItemStack container) {
return capacity;
}
}
@@ -0,0 +1,68 @@
package cofh.api.energy;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
/**
* Reference implementation of {@link IEnergyReceiver} and {@link IEnergyProvider}. Use/extend this or implement your own.
*
* This class is really meant to summarize how each interface is properly used.
*
* @author King Lemming
*
*/
public class TileEnergyHandler extends TileEntity implements IEnergyReceiver, IEnergyProvider {
protected EnergyStorage storage = new EnergyStorage(32000);
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
storage.readFromNBT(nbt);
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
storage.writeToNBT(nbt);
return nbt;
}
/* IEnergyConnection */
@Override
public boolean canConnectEnergy(EnumFacing from) {
return true;
}
/* IEnergyReceiver */
@Override
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {
return storage.receiveEnergy(maxReceive, simulate);
}
/* IEnergyProvider */
@Override
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) {
return storage.extractEnergy(maxExtract, simulate);
}
/* IEnergyHandler */
@Override
public int getEnergyStored(EnumFacing from) {
return storage.getEnergyStored();
}
@Override
public int getMaxEnergyStored(EnumFacing from) {
return storage.getMaxEnergyStored();
}
}
+10
View File
@@ -0,0 +1,10 @@
/**
* (C) 2014-2016 Team CoFH / CoFH / Cult of the Full Hub
* http://www.teamcofh.com
*/
@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHAPI", provides = "CoFHAPI|energy")
package cofh.api.energy;
import net.minecraftforge.fml.common.API;
import cofh.api.CoFHAPIProps;
+9
View File
@@ -0,0 +1,9 @@
/**
* (C) 2014-2016 Team CoFH / CoFH / Cult of the Full Hub
* http://www.teamcofh.com
*/
@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHLib", provides = "CoFHAPI")
package cofh.api;
import net.minecraftforge.fml.common.API;