Applied-Energistics-2-tiler.../src/main/java/appeng/parts/networking/PartQuartzFiber.java

244 lines
5.8 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +01:00
/*
* 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>.
*/
2014-09-24 02:26:27 +02:00
package appeng.parts.networking;
2014-09-24 02:26:27 +02:00
import java.util.EnumSet;
import java.util.Set;
2015-12-24 02:07:03 +01:00
import org.lwjgl.opengl.GL11;
2014-09-24 02:26:27 +02:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
2015-06-16 02:44:59 +02:00
import net.minecraft.util.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2014-09-24 02:26:27 +02:00
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;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartRenderHelper;
import appeng.api.util.AECableType;
2015-06-16 02:44:59 +02:00
import appeng.api.util.AEPartLocation;
import appeng.api.util.IAESprite;
import appeng.api.util.ModelGenerator;
2014-09-24 02:26:27 +02:00
import appeng.me.GridAccessException;
import appeng.me.helpers.AENetworkProxy;
import appeng.parts.AEBasePart;
2014-09-24 02:26:27 +02:00
public class PartQuartzFiber extends AEBasePart implements IEnergyGridProvider
{
private final AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", this.getProxy().getMachineRepresentation(), true );
2014-09-24 02:26:27 +02:00
2015-09-30 14:24:40 +02:00
public PartQuartzFiber( final ItemStack is )
{
super( is );
this.getProxy().setIdlePowerUsage( 0 );
this.getProxy().setFlags( GridFlags.CANNOT_CARRY );
2014-12-29 15:13:47 +01:00
this.outerProxy.setIdlePowerUsage( 0 );
this.outerProxy.setFlags( GridFlags.CANNOT_CARRY );
2014-09-24 02:26:27 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public AECableType getCableConnectionType( final AEPartLocation dir )
2014-09-24 02:26:27 +02:00
{
return AECableType.GLASS;
2014-09-24 02:26:27 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public void getBoxes( final IPartCollisionHelper bch )
2014-09-24 02:26:27 +02:00
{
bch.addBox( 6, 6, 10, 10, 10, 16 );
2014-09-24 02:26:27 +02:00
}
@Override
@SideOnly( Side.CLIENT )
2015-09-30 14:24:40 +02:00
public void renderInventory( final IPartRenderHelper rh, final ModelGenerator renderer )
2014-09-24 02:26:27 +02:00
{
GL11.glTranslated( -0.2, -0.3, 0.0 );
rh.setTexture( renderer.getIcon( this.getItemStack() ) );
rh.setBounds( 6.0f, 6.0f, 5.0f, 10.0f, 10.0f, 11.0f );
rh.renderInventoryBox( renderer );
rh.setTexture( null );
2014-09-24 02:26:27 +02:00
}
@Override
@SideOnly( Side.CLIENT )
2015-09-30 14:24:40 +02:00
public void renderStatic( final BlockPos pos, final IPartRenderHelper rh, final ModelGenerator renderer )
2014-09-24 02:26:27 +02:00
{
final IAESprite myIcon = renderer.getIcon( this.getItemStack() );
rh.setTexture( myIcon );
rh.setBounds( 6, 6, 10, 10, 10, 16 );
2015-06-16 02:44:59 +02:00
rh.renderBlock( pos, renderer );
rh.setTexture( null );
2014-09-24 02:26:27 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public void readFromNBT( final NBTTagCompound extra )
2014-09-24 02:26:27 +02:00
{
super.readFromNBT( extra );
this.outerProxy.readFromNBT( extra );
}
@Override
2015-09-30 14:24:40 +02:00
public void writeToNBT( final NBTTagCompound extra )
{
super.writeToNBT( extra );
this.outerProxy.writeToNBT( extra );
2014-09-24 02:26:27 +02:00
}
@Override
public void removeFromWorld()
{
super.removeFromWorld();
2014-12-29 15:13:47 +01:00
this.outerProxy.invalidate();
2014-09-24 02:26:27 +02:00
}
@Override
public void addToWorld()
2014-09-24 02:26:27 +02:00
{
super.addToWorld();
this.outerProxy.onReady();
2014-09-24 02:26:27 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public void setPartHostInfo( final AEPartLocation side, final IPartHost host, final TileEntity tile )
2014-09-24 02:26:27 +02:00
{
super.setPartHostInfo( side, host, tile );
2015-06-16 02:44:59 +02:00
this.outerProxy.setValidSides( EnumSet.of( side.getFacing() ) );
2014-09-24 02:26:27 +02:00
}
@Override
public IGridNode getExternalFacingNode()
2014-09-24 02:26:27 +02:00
{
return this.outerProxy.getNode();
2014-09-24 02:26:27 +02:00
}
@Override
public int cableConnectionRenderTo()
2014-09-24 02:26:27 +02:00
{
return 16;
2014-09-24 02:26:27 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public void onPlacement( final EntityPlayer player, final ItemStack held, final AEPartLocation side )
2014-09-24 02:26:27 +02:00
{
super.onPlacement( player, held, side );
this.outerProxy.setOwner( player );
2014-09-24 02:26:27 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public double extractAEPower( final double amt, final Actionable mode, final Set<IEnergyGrid> seen )
2014-09-24 02:26:27 +02:00
{
double acquiredPower = 0;
try
{
final IEnergyGrid eg = this.getProxy().getEnergy();
2014-09-24 02:26:27 +02:00
acquiredPower += eg.extractAEPower( amt - acquiredPower, mode, seen );
}
2015-09-30 14:24:40 +02:00
catch( final GridAccessException e )
2014-09-24 02:26:27 +02:00
{
// :P
}
try
{
2015-09-30 14:24:40 +02:00
final IEnergyGrid eg = this.outerProxy.getEnergy();
2014-09-24 02:26:27 +02:00
acquiredPower += eg.extractAEPower( amt - acquiredPower, mode, seen );
}
2015-09-30 14:24:40 +02:00
catch( final GridAccessException e )
2014-09-24 02:26:27 +02:00
{
// :P
}
return acquiredPower;
}
@Override
2015-09-30 14:24:40 +02:00
public double injectAEPower( final double amt, final Actionable mode, final Set<IEnergyGrid> seen )
2014-09-24 02:26:27 +02:00
{
try
{
final IEnergyGrid eg = this.getProxy().getEnergy();
if( !seen.contains( eg ) )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
return eg.injectAEPower( amt, mode, seen );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
2015-09-30 14:24:40 +02:00
catch( final GridAccessException e )
2014-09-24 02:26:27 +02:00
{
// :P
}
try
{
2015-09-30 14:24:40 +02:00
final IEnergyGrid eg = this.outerProxy.getEnergy();
if( !seen.contains( eg ) )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
return eg.injectAEPower( amt, mode, seen );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
2015-09-30 14:24:40 +02:00
catch( final GridAccessException e )
2014-09-24 02:26:27 +02:00
{
// :P
}
return amt;
}
@Override
2015-09-30 14:24:40 +02:00
public double getEnergyDemand( final double amt, final Set<IEnergyGrid> seen )
2014-09-24 02:26:27 +02:00
{
double demand = 0;
try
{
final IEnergyGrid eg = this.getProxy().getEnergy();
2014-09-24 02:26:27 +02:00
demand += eg.getEnergyDemand( amt - demand, seen );
}
2015-09-30 14:24:40 +02:00
catch( final GridAccessException e )
2014-09-24 02:26:27 +02:00
{
// :P
}
try
{
2015-09-30 14:24:40 +02:00
final IEnergyGrid eg = this.outerProxy.getEnergy();
2014-09-24 02:26:27 +02:00
demand += eg.getEnergyDemand( amt - demand, seen );
}
2015-09-30 14:24:40 +02:00
catch( final GridAccessException e )
2014-09-24 02:26:27 +02:00
{
// :P
}
return demand;
}
}