2013-12-27 23:59:59 +01:00
|
|
|
package appeng.parts.networking;
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
2014-01-27 05:00:36 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.util.IIcon;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import appeng.api.config.Actionable;
|
|
|
|
import appeng.api.networking.GridFlags;
|
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.networking.energy.IEnergyGrid;
|
|
|
|
import appeng.api.networking.energy.IEnergyGridProvider;
|
2014-09-20 22:20:53 +02:00
|
|
|
import appeng.api.parts.IPartCollisionHelper;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.parts.IPartHost;
|
|
|
|
import appeng.api.parts.IPartRenderHelper;
|
|
|
|
import appeng.api.util.AECableType;
|
|
|
|
import appeng.me.GridAccessException;
|
|
|
|
import appeng.me.helpers.AENetworkProxy;
|
|
|
|
import appeng.parts.AEBasePart;
|
2014-02-07 06:51:19 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
public class PartQuartzFiber extends AEBasePart implements IEnergyGridProvider
|
|
|
|
{
|
|
|
|
|
2014-01-23 17:28:12 +01:00
|
|
|
AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", proxy.getMachineRepresentation(), true );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
public PartQuartzFiber(ItemStack is) {
|
|
|
|
super( PartQuartzFiber.class, is );
|
2014-01-24 17:30:57 +01:00
|
|
|
proxy.setIdlePowerUsage( 0 );
|
2013-12-27 23:59:59 +01:00
|
|
|
proxy.setFlags( GridFlags.CANNOT_CARRY );
|
2014-04-27 04:53:30 +02:00
|
|
|
outerProxy.setIdlePowerUsage( 0 );
|
|
|
|
outerProxy.setFlags( GridFlags.CANNOT_CARRY );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
@Override
|
|
|
|
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
|
|
|
|
{
|
|
|
|
super.onPlacement( player, held, side );
|
|
|
|
outerProxy.setOwner( player );
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public void setPartHostInfo(ForgeDirection side, IPartHost host, TileEntity tile)
|
|
|
|
{
|
|
|
|
super.setPartHostInfo( side, host, tile );
|
|
|
|
outerProxy.setValidSides( EnumSet.of( side ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound extra)
|
|
|
|
{
|
|
|
|
super.readFromNBT( extra );
|
|
|
|
outerProxy.readFromNBT( extra );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound extra)
|
|
|
|
{
|
|
|
|
super.writeToNBT( extra );
|
|
|
|
outerProxy.writeToNBT( extra );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addToWorld()
|
|
|
|
{
|
|
|
|
super.addToWorld();
|
|
|
|
outerProxy.onReady();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removeFromWorld()
|
|
|
|
{
|
|
|
|
super.removeFromWorld();
|
|
|
|
outerProxy.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGridNode getExternalFacingNode()
|
|
|
|
{
|
|
|
|
return outerProxy.getNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AECableType getCableConnectionType(ForgeDirection dir)
|
|
|
|
{
|
|
|
|
return AECableType.GLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-07 06:51:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-27 23:59:59 +01:00
|
|
|
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
IIcon myIcon = is.getIconIndex();
|
2013-12-27 23:59:59 +01:00
|
|
|
rh.setTexture( myIcon );
|
|
|
|
rh.setBounds( 6, 6, 10, 10, 10, 16 );
|
|
|
|
rh.renderBlock( x, y, z, renderer );
|
|
|
|
rh.setTexture( null );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-20 22:20:53 +02:00
|
|
|
public void getBoxes(IPartCollisionHelper bch)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
bch.addBox( 6, 6, 10, 10, 10, 16 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-07 06:51:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-27 23:59:59 +01:00
|
|
|
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
|
|
|
{
|
|
|
|
GL11.glTranslated( -0.2, -0.3, 0.0 );
|
|
|
|
|
|
|
|
rh.setTexture( is.getIconIndex() );
|
|
|
|
rh.setBounds( 6.0f, 6.0f, 5.0f, 10.0f, 10.0f, 11.0f );
|
|
|
|
rh.renderInventoryBox( renderer );
|
|
|
|
rh.setTexture( null );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double extractAEPower(double amt, Actionable mode, Set<IEnergyGrid> seen)
|
|
|
|
{
|
2014-09-21 01:22:05 +02:00
|
|
|
double acquiredPower = 0;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IEnergyGrid eg = proxy.getEnergy();
|
2014-09-21 01:22:05 +02:00
|
|
|
acquiredPower += eg.extractAEPower( amt - acquiredPower, mode, seen );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IEnergyGrid eg = outerProxy.getEnergy();
|
2014-09-21 01:22:05 +02:00
|
|
|
acquiredPower += eg.extractAEPower( amt - acquiredPower, mode, seen );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
2014-09-21 01:22:05 +02:00
|
|
|
return acquiredPower;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-07-20 00:48:57 +02:00
|
|
|
@Override
|
|
|
|
public double injectAEPower(double amt, Actionable mode, Set<IEnergyGrid> seen)
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IEnergyGrid eg = proxy.getEnergy();
|
|
|
|
if ( !seen.contains( eg ) )
|
|
|
|
return eg.injectAEPower( amt, mode, seen );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IEnergyGrid eg = outerProxy.getEnergy();
|
|
|
|
if ( !seen.contains( eg ) )
|
|
|
|
return eg.injectAEPower( amt, mode, seen );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
return amt;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public int cableConnectionRenderTo()
|
|
|
|
{
|
|
|
|
return 16;
|
|
|
|
}
|
|
|
|
|
2014-07-20 00:48:57 +02:00
|
|
|
@Override
|
|
|
|
public double getEnergyDemand(double amt, Set<IEnergyGrid> seen)
|
|
|
|
{
|
|
|
|
double demand = 0;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IEnergyGrid eg = proxy.getEnergy();
|
|
|
|
demand += eg.getEnergyDemand( amt - demand, seen );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IEnergyGrid eg = outerProxy.getEnergy();
|
|
|
|
demand += eg.getEnergyDemand( amt - demand, seen );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
return demand;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|