2013-12-27 23:59:59 +01:00
|
|
|
package appeng.facade;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2014-02-16 19:41:45 +01:00
|
|
|
import net.minecraft.block.Block;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.parts.IFacadeContainer;
|
|
|
|
import appeng.api.parts.IFacadePart;
|
|
|
|
import appeng.api.parts.IPartHost;
|
|
|
|
import appeng.core.AppEng;
|
2014-07-24 00:26:23 +02:00
|
|
|
import appeng.integration.IntegrationType;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.integration.abstraction.IBC;
|
|
|
|
import appeng.items.parts.ItemFacade;
|
|
|
|
|
|
|
|
public class FacadeContainer implements IFacadeContainer
|
|
|
|
{
|
|
|
|
|
|
|
|
final private IFacadePart facades[] = new FacadePart[6];
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
public void writeToStream(ByteBuf out) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
int facadeSides = 0;
|
|
|
|
for (int x = 0; x < facades.length; x++)
|
|
|
|
{
|
|
|
|
if ( getFacade( ForgeDirection.getOrientation( x ) ) != null )
|
|
|
|
facadeSides = facadeSides | (1 << x);
|
|
|
|
}
|
|
|
|
out.writeByte( (byte) facadeSides );
|
|
|
|
|
|
|
|
for (int x = 0; x < facades.length; x++)
|
|
|
|
{
|
|
|
|
IFacadePart part = getFacade( ForgeDirection.getOrientation( x ) );
|
|
|
|
if ( part != null )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
int itemID = Item.getIdFromItem( part.getItem() );
|
2013-12-27 23:59:59 +01:00
|
|
|
int dmgValue = part.getItemDamage();
|
|
|
|
out.writeInt( itemID * (part.isBC() ? -1 : 1) );
|
|
|
|
out.writeInt( dmgValue );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
public boolean readFromStream(ByteBuf out) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
int facadeSides = out.readByte();
|
|
|
|
|
2014-05-11 18:30:00 +02:00
|
|
|
boolean changed = false;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
int ids[] = new int[2];
|
|
|
|
for (int x = 0; x < facades.length; x++)
|
|
|
|
{
|
|
|
|
ForgeDirection side = ForgeDirection.getOrientation( x );
|
|
|
|
int ix = (1 << x);
|
|
|
|
if ( (facadeSides & ix) == ix )
|
|
|
|
{
|
|
|
|
ids[0] = out.readInt();
|
|
|
|
ids[1] = out.readInt();
|
|
|
|
boolean isBC = ids[0] < 0;
|
|
|
|
ids[0] = Math.abs( ids[0] );
|
|
|
|
|
2014-07-24 00:26:23 +02:00
|
|
|
if ( isBC && AppEng.instance.isIntegrationEnabled( IntegrationType.BC ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-07-24 00:26:23 +02:00
|
|
|
IBC bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC );
|
2014-05-11 18:30:00 +02:00
|
|
|
changed = changed || facades[x] == null;
|
2014-02-16 19:41:45 +01:00
|
|
|
facades[x] = bc.createFacadePart( (Block) Block.blockRegistry.getObjectById( ids[0] ), ids[1], side );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else if ( !isBC )
|
|
|
|
{
|
|
|
|
ItemFacade ifa = (ItemFacade) AEApi.instance().items().itemFacade.item();
|
|
|
|
ItemStack facade = ifa.createFromInts( ids );
|
|
|
|
if ( facade != null )
|
2014-05-11 18:30:00 +02:00
|
|
|
{
|
|
|
|
changed = changed || facades[x] == null;
|
2013-12-27 23:59:59 +01:00
|
|
|
facades[x] = ifa.createPartFromItemStack( facade, side );
|
2014-05-11 18:30:00 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2014-05-11 18:30:00 +02:00
|
|
|
{
|
|
|
|
changed = changed || facades[x] != null;
|
2013-12-27 23:59:59 +01:00
|
|
|
facades[x] = null;
|
2014-05-11 18:30:00 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-05-11 18:30:00 +02:00
|
|
|
|
|
|
|
return changed;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void readFromNBT(NBTTagCompound c)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < facades.length; x++)
|
|
|
|
{
|
|
|
|
facades[x] = null;
|
|
|
|
|
|
|
|
NBTTagCompound t = c.getCompoundTag( "facade:" + x );
|
|
|
|
if ( t != null )
|
|
|
|
{
|
|
|
|
ItemStack is = ItemStack.loadItemStackFromNBT( t );
|
|
|
|
if ( is != null )
|
|
|
|
{
|
|
|
|
Item i = is.getItem();
|
|
|
|
if ( i instanceof IFacadeItem )
|
|
|
|
facades[x] = ((IFacadeItem) i).createPartFromItemStack( is, ForgeDirection.getOrientation( x ) );
|
|
|
|
else
|
|
|
|
{
|
2014-07-24 00:26:23 +02:00
|
|
|
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.BC ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-07-24 00:26:23 +02:00
|
|
|
IBC bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC );
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( bc.isFacade( is ) )
|
|
|
|
facades[x] = bc.createFacadePart( is, ForgeDirection.getOrientation( x ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void writeToNBT(NBTTagCompound c)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < facades.length; x++)
|
|
|
|
{
|
|
|
|
if ( facades[x] != null )
|
|
|
|
{
|
|
|
|
NBTTagCompound data = new NBTTagCompound();
|
|
|
|
facades[x].getItemStack().writeToNBT( data );
|
2014-02-09 02:34:52 +01:00
|
|
|
c.setTag( "facade:" + x, data );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean addFacade(IFacadePart a)
|
|
|
|
{
|
|
|
|
if ( getFacade( a.getSide() ) == null )
|
|
|
|
{
|
|
|
|
facades[a.getSide().ordinal()] = a;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removeFacade(IPartHost host, ForgeDirection side)
|
|
|
|
{
|
|
|
|
if ( side != null && side != ForgeDirection.UNKNOWN )
|
|
|
|
{
|
|
|
|
if ( facades[side.ordinal()] != null )
|
|
|
|
{
|
|
|
|
facades[side.ordinal()] = null;
|
|
|
|
if ( host != null )
|
|
|
|
host.markForUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IFacadePart getFacade(ForgeDirection s)
|
|
|
|
{
|
|
|
|
return facades[s.ordinal()];
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isEmpty()
|
|
|
|
{
|
|
|
|
for (int x = 0; x < facades.length; x++)
|
|
|
|
if ( facades[x] != null )
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2014-05-11 18:30:00 +02:00
|
|
|
|
|
|
|
public void rotateLeft()
|
|
|
|
{
|
|
|
|
IFacadePart newfacades[] = new FacadePart[6];
|
|
|
|
|
|
|
|
newfacades[ForgeDirection.UP.ordinal()] = facades[ForgeDirection.UP.ordinal()];
|
|
|
|
newfacades[ForgeDirection.DOWN.ordinal()] = facades[ForgeDirection.DOWN.ordinal()];
|
|
|
|
|
|
|
|
newfacades[ForgeDirection.EAST.ordinal()] = facades[ForgeDirection.NORTH.ordinal()];
|
|
|
|
newfacades[ForgeDirection.SOUTH.ordinal()] = facades[ForgeDirection.EAST.ordinal()];
|
|
|
|
newfacades[ForgeDirection.WEST.ordinal()] = facades[ForgeDirection.SOUTH.ordinal()];
|
|
|
|
newfacades[ForgeDirection.NORTH.ordinal()] = facades[ForgeDirection.WEST.ordinal()];
|
|
|
|
|
|
|
|
for (int x = 0; x < facades.length; x++)
|
|
|
|
facades[x] = newfacades[x];
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|