2013-12-27 23:59:59 +01:00
|
|
|
package appeng.parts.misc;
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
import java.util.ArrayList;
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.EnumSet;
|
2014-01-27 05:00:36 +01:00
|
|
|
import java.util.List;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
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-06-11 07:14:37 +02:00
|
|
|
import net.minecraft.util.IIcon;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import appeng.api.AEApi;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.exceptions.FailedConnection;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.IGridConnection;
|
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.parts.IPartCollsionHelper;
|
|
|
|
import appeng.api.parts.IPartHost;
|
|
|
|
import appeng.api.parts.IPartRenderHelper;
|
|
|
|
import appeng.api.util.AECableType;
|
|
|
|
import appeng.client.texture.CableBusTextures;
|
|
|
|
import appeng.me.helpers.AENetworkProxy;
|
|
|
|
import appeng.parts.PartBasicState;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.util.Platform;
|
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 PartToggleBus extends PartBasicState
|
|
|
|
{
|
|
|
|
|
2014-02-11 06:51:48 +01:00
|
|
|
AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", null, true );
|
2013-12-27 23:59:59 +01:00
|
|
|
IGridConnection connection;
|
|
|
|
|
|
|
|
protected final int REDSTONE_FLAG = 4;
|
|
|
|
|
|
|
|
boolean hasRedstone = false;
|
|
|
|
|
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
|
|
|
|
protected int populateFlags(int cf)
|
|
|
|
{
|
|
|
|
return cf | (getIntention() ? REDSTONE_FLAG : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNeighborChanged()
|
|
|
|
{
|
|
|
|
boolean oldHasRedstone = hasRedstone;
|
|
|
|
hasRedstone = getHost().hasRedstone( side );
|
|
|
|
|
|
|
|
if ( hasRedstone != oldHasRedstone )
|
|
|
|
{
|
|
|
|
updateInternalState();
|
|
|
|
getHost().markForUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public PartToggleBus(ItemStack is) {
|
|
|
|
this( PartToggleBus.class, is );
|
2014-02-11 06:51:48 +01:00
|
|
|
proxy.setIdlePowerUsage( 0.0 );
|
|
|
|
outerProxy.setIdlePowerUsage( 0.0 );
|
2014-04-07 18:27:00 +02:00
|
|
|
proxy.setFlags();
|
|
|
|
outerProxy.setFlags();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public PartToggleBus(Class cls, ItemStack is) {
|
|
|
|
super( cls, is );
|
|
|
|
}
|
|
|
|
|
|
|
|
@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();
|
2014-08-23 08:25:06 +02:00
|
|
|
hasRedstone = getHost().hasRedstone( side );
|
2013-12-27 23:59:59 +01:00
|
|
|
updateInternalState();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateInternalState()
|
|
|
|
{
|
|
|
|
boolean intention = getIntention();
|
|
|
|
if ( intention != (connection != null) )
|
|
|
|
{
|
|
|
|
if ( proxy.getNode() != null && outerProxy.getNode() != null )
|
|
|
|
{
|
|
|
|
if ( intention )
|
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
connection = AEApi.instance().createGridConnection( proxy.getNode(), outerProxy.getNode() );
|
|
|
|
}
|
|
|
|
catch (FailedConnection e)
|
|
|
|
{
|
|
|
|
// :(
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
connection.destroy();
|
|
|
|
connection = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean getIntention()
|
|
|
|
{
|
|
|
|
return getHost().hasRedstone( side );
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
|
public void setColors(boolean hasChan, boolean hasPower)
|
|
|
|
{
|
|
|
|
hasRedstone = (clientFlags & REDSTONE_FLAG) == REDSTONE_FLAG;
|
|
|
|
super.setColors( hasChan && hasRedstone, hasPower && hasRedstone );
|
|
|
|
}
|
|
|
|
|
|
|
|
@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-15 07:30:06 +01:00
|
|
|
renderCache = rh.useSimpliedRendering( x, y, z, this, renderCache );
|
2013-12-27 23:59:59 +01:00
|
|
|
rh.setTexture( is.getIconIndex() );
|
|
|
|
|
|
|
|
rh.setBounds( 6, 6, 14, 10, 10, 16 );
|
|
|
|
rh.renderBlock( x, y, z, renderer );
|
|
|
|
|
|
|
|
rh.setBounds( 6, 6, 11, 10, 10, 13 );
|
|
|
|
rh.renderBlock( x, y, z, renderer );
|
|
|
|
|
|
|
|
rh.setTexture( CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
|
|
|
CableBusTextures.PartMonitorBack.getIcon(), is.getIconIndex(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
|
|
|
CableBusTextures.PartMonitorSidesStatus.getIcon() );
|
|
|
|
|
|
|
|
rh.setBounds( 6, 6, 13, 10, 10, 14 );
|
|
|
|
rh.renderBlock( x, y, z, renderer );
|
|
|
|
|
|
|
|
renderLights( x, y, z, rh, renderer );
|
|
|
|
}
|
|
|
|
|
2014-06-11 07:14:37 +02:00
|
|
|
@Override
|
|
|
|
public IIcon getBreakingTexture()
|
|
|
|
{
|
|
|
|
return is.getIconIndex();
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public void getBoxes(IPartCollsionHelper bch)
|
|
|
|
{
|
|
|
|
bch.addBox( 6, 6, 11, 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, 6, 14 - 4, 10, 10, 16 - 4 );
|
|
|
|
rh.renderInventoryBox( renderer );
|
|
|
|
|
|
|
|
rh.setBounds( 6, 6, 11 - 4, 10, 10, 13 - 4 );
|
|
|
|
rh.renderInventoryBox( renderer );
|
|
|
|
|
|
|
|
rh.setBounds( 6, 6, 13 - 4, 10, 10, 14 - 4 );
|
|
|
|
rh.setTexture( CableBusTextures.PartMonitorSidesStatus.getIcon() );
|
|
|
|
rh.renderInventoryBox( renderer );
|
|
|
|
|
|
|
|
rh.setTexture( CableBusTextures.PartMonitorSidesStatusLights.getIcon() );
|
|
|
|
rh.setInvColor( 0x000000 );
|
|
|
|
rh.renderInventoryBox( renderer );
|
|
|
|
rh.setInvColor( 0xffffff );
|
|
|
|
|
|
|
|
rh.setTexture( null );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int cableConnectionRenderTo()
|
|
|
|
{
|
|
|
|
return 5;
|
|
|
|
}
|
2014-01-27 05:00:36 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void securityBreak()
|
|
|
|
{
|
|
|
|
if ( is.stackSize > 0 )
|
|
|
|
{
|
|
|
|
List<ItemStack> items = new ArrayList();
|
|
|
|
items.add( is.copy() );
|
|
|
|
host.removePart( side, false );
|
2014-02-09 02:34:52 +01:00
|
|
|
Platform.spawnDrops( tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, items );
|
2014-01-27 05:00:36 +01:00
|
|
|
is.stackSize = 0;
|
|
|
|
}
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|