2013-12-27 23:59:59 +01:00
|
|
|
package appeng.parts;
|
|
|
|
|
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;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
2014-02-23 23:50:53 +01:00
|
|
|
import java.util.Set;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
2013-12-28 21:54:05 +01:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.Vec3;
|
|
|
|
import net.minecraft.world.World;
|
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;
|
2014-08-23 08:25:06 +02:00
|
|
|
import appeng.api.config.YesNo;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.exceptions.FailedConnection;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.parts.IPartCable;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.networking.IGridHost;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.parts.IFacadeContainer;
|
|
|
|
import appeng.api.parts.IFacadePart;
|
|
|
|
import appeng.api.parts.IPart;
|
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.IPartItem;
|
2014-02-23 23:50:53 +01:00
|
|
|
import appeng.api.parts.LayerFlags;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.parts.PartItemStack;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.parts.SelectedPart;
|
|
|
|
import appeng.api.util.AECableType;
|
|
|
|
import appeng.api.util.AEColor;
|
|
|
|
import appeng.api.util.DimensionalCoord;
|
2014-02-07 06:51:19 +01:00
|
|
|
import appeng.client.render.CableRenderHelper;
|
2014-05-27 23:02:15 +02:00
|
|
|
import appeng.core.AELog;
|
2014-05-16 04:18:30 +02:00
|
|
|
import appeng.core.AppEng;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.facade.FacadeContainer;
|
|
|
|
import appeng.helpers.AEMultiTile;
|
2014-07-24 00:26:23 +02:00
|
|
|
import appeng.integration.IntegrationType;
|
2014-05-16 04:18:30 +02:00
|
|
|
import appeng.integration.abstraction.ICLApi;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.me.GridConnection;
|
|
|
|
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
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
public class CableBusContainer extends CableBusStorage implements AEMultiTile, ICableBusContainer
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2014-02-23 23:50:53 +01:00
|
|
|
private EnumSet<LayerFlags> myLayerFlags = EnumSet.noneOf( LayerFlags.class );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-08-23 08:25:06 +02:00
|
|
|
public YesNo hasRedstone = YesNo.UNDECIDED;
|
2013-12-27 23:59:59 +01:00
|
|
|
public IPartHost tcb;
|
|
|
|
|
|
|
|
boolean inWorld = false;
|
2014-02-06 05:36:10 +01:00
|
|
|
public boolean requiresDynamicRender = false;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-06-09 01:10:19 +02:00
|
|
|
@Override
|
|
|
|
public boolean isInWorld()
|
|
|
|
{
|
|
|
|
return inWorld;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public void setHost(IPartHost host)
|
|
|
|
{
|
|
|
|
tcb.clearContainer();
|
|
|
|
tcb = host;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CableBusContainer(IPartHost host) {
|
|
|
|
tcb = host;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IPart getPart(ForgeDirection side)
|
|
|
|
{
|
|
|
|
if ( side == ForgeDirection.UNKNOWN )
|
2014-08-27 07:57:37 +02:00
|
|
|
return getCenter();
|
|
|
|
return getSide( side );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-05-11 18:30:00 +02:00
|
|
|
public void rotateLeft()
|
|
|
|
{
|
|
|
|
IPart newSides[] = new IPart[6];
|
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
newSides[ForgeDirection.UP.ordinal()] = getSide( ForgeDirection.UP );
|
|
|
|
newSides[ForgeDirection.DOWN.ordinal()] = getSide( ForgeDirection.DOWN );
|
2014-05-11 18:30:00 +02:00
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
newSides[ForgeDirection.EAST.ordinal()] = getSide( ForgeDirection.NORTH );
|
|
|
|
newSides[ForgeDirection.SOUTH.ordinal()] = getSide( ForgeDirection.EAST );
|
|
|
|
newSides[ForgeDirection.WEST.ordinal()] = getSide( ForgeDirection.SOUTH );
|
|
|
|
newSides[ForgeDirection.NORTH.ordinal()] = getSide( ForgeDirection.WEST );
|
2014-05-11 18:30:00 +02:00
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
setSide( dir, newSides[dir.ordinal()] );
|
2014-05-11 18:30:00 +02:00
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
getFacadeContainer().rotateLeft();
|
2014-05-11 18:30:00 +02:00
|
|
|
}
|
|
|
|
|
2014-02-06 05:36:10 +01:00
|
|
|
public void updateDynamicRender()
|
|
|
|
{
|
|
|
|
requiresDynamicRender = false;
|
|
|
|
for (ForgeDirection s : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
{
|
|
|
|
IPart p = getPart( s );
|
|
|
|
if ( p != null )
|
|
|
|
requiresDynamicRender = requiresDynamicRender || p.requireDynamicRender();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
2014-01-27 05:00:36 +01:00
|
|
|
public void removePart(ForgeDirection side, boolean supressUpdate)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( side == ForgeDirection.UNKNOWN )
|
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
if ( getCenter() != null )
|
|
|
|
getCenter().removeFromWorld();
|
|
|
|
setCenter( null );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
if ( getSide( side ) != null )
|
|
|
|
getSide( side ).removeFromWorld();
|
|
|
|
setSide( side, null );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
if ( !supressUpdate )
|
|
|
|
{
|
2014-02-06 05:36:10 +01:00
|
|
|
updateDynamicRender();
|
2014-01-27 05:00:36 +01:00
|
|
|
updateConnections();
|
|
|
|
markForUpdate();
|
2014-09-06 08:25:58 +02:00
|
|
|
markForSave();
|
2014-02-26 16:17:39 +01:00
|
|
|
partChanged();
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* use for FMP
|
|
|
|
*/
|
|
|
|
public void updateConnections()
|
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
if ( getCenter() != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
EnumSet<ForgeDirection> sides = EnumSet.allOf( ForgeDirection.class );
|
|
|
|
|
|
|
|
for (ForgeDirection s : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
{
|
|
|
|
if ( getPart( s ) != null || isBlocked( s ) )
|
|
|
|
sides.remove( s );
|
|
|
|
}
|
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
getCenter().setValidSides( sides );
|
|
|
|
IGridNode n = getCenter().getGridNode();
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( n != null )
|
|
|
|
n.updateState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canAddPart(ItemStack is, ForgeDirection side)
|
|
|
|
{
|
2014-05-05 02:39:29 +02:00
|
|
|
if ( PartPlacement.isFacade( is, side ) != null )
|
2014-04-20 06:35:48 +02:00
|
|
|
return true;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( is.getItem() instanceof IPartItem )
|
|
|
|
{
|
|
|
|
IPartItem bi = (IPartItem) is.getItem();
|
|
|
|
|
|
|
|
is = is.copy();
|
|
|
|
is.stackSize = 1;
|
|
|
|
|
|
|
|
IPart bp = bi.createPartFromItemStack( is );
|
2014-05-24 18:02:24 +02:00
|
|
|
if ( bp != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-05-24 18:02:24 +02:00
|
|
|
if ( bp instanceof IPartCable )
|
|
|
|
{
|
|
|
|
boolean canPlace = true;
|
|
|
|
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
if ( getPart( d ) != null && !getPart( d ).canBePlacedOn( ((IPartCable) bp).supportsBuses() ) )
|
|
|
|
canPlace = false;
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-05-24 18:02:24 +02:00
|
|
|
if ( !canPlace )
|
|
|
|
return false;
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-05-24 18:02:24 +02:00
|
|
|
return getPart( ForgeDirection.UNKNOWN ) == null;
|
|
|
|
}
|
|
|
|
else if ( !(bp instanceof IPartCable) && side != ForgeDirection.UNKNOWN )
|
|
|
|
{
|
|
|
|
IPart cable = getPart( ForgeDirection.UNKNOWN );
|
|
|
|
if ( cable != null && !bp.canBePlacedOn( ((IPartCable) cable).supportsBuses() ) )
|
|
|
|
return false;
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-05-24 18:02:24 +02:00
|
|
|
return getPart( side ) == null;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-27 05:00:36 +01:00
|
|
|
public ForgeDirection addPart(ItemStack is, ForgeDirection side, EntityPlayer player)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( canAddPart( is, side ) )
|
|
|
|
{
|
|
|
|
if ( is.getItem() instanceof IPartItem )
|
|
|
|
{
|
|
|
|
IPartItem bi = (IPartItem) is.getItem();
|
|
|
|
|
|
|
|
is = is.copy();
|
|
|
|
is.stackSize = 1;
|
|
|
|
|
|
|
|
IPart bp = bi.createPartFromItemStack( is );
|
|
|
|
if ( bp instanceof IPartCable )
|
|
|
|
{
|
2014-01-30 19:54:09 +01:00
|
|
|
boolean canPlace = true;
|
2014-01-20 17:41:37 +01:00
|
|
|
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
|
2014-01-30 19:54:09 +01:00
|
|
|
if ( getPart( d ) != null && !getPart( d ).canBePlacedOn( ((IPartCable) bp).supportsBuses() ) )
|
|
|
|
canPlace = false;
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-01-30 19:54:09 +01:00
|
|
|
if ( !canPlace )
|
2014-01-20 17:41:37 +01:00
|
|
|
return null;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( getPart( ForgeDirection.UNKNOWN ) != null )
|
|
|
|
return null;
|
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
setCenter( (IPartCable) bp );
|
2013-12-27 23:59:59 +01:00
|
|
|
bp.setPartHostInfo( ForgeDirection.UNKNOWN, this, tcb.getTile() );
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
if ( player != null )
|
|
|
|
bp.onPlacement( player, is, side );
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( inWorld )
|
|
|
|
bp.addToWorld();
|
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
IGridNode cn = getCenter().getGridNode();
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( cn != null )
|
|
|
|
{
|
|
|
|
for (ForgeDirection ins : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
{
|
|
|
|
IPart sbp = getPart( ins );
|
|
|
|
if ( sbp != null )
|
|
|
|
{
|
|
|
|
IGridNode sn = sbp.getGridNode();
|
|
|
|
if ( sn != null && cn != null )
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
new GridConnection( (IGridNode) cn, (IGridNode) sn, ForgeDirection.UNKNOWN );
|
|
|
|
}
|
|
|
|
catch (FailedConnection e)
|
|
|
|
{
|
|
|
|
// ekk!
|
|
|
|
|
|
|
|
bp.removeFromWorld();
|
2014-08-27 07:57:37 +02:00
|
|
|
setCenter( null );
|
2014-01-27 05:00:36 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateConnections();
|
|
|
|
markForUpdate();
|
2014-09-06 08:25:58 +02:00
|
|
|
markForSave();
|
2014-02-26 16:17:39 +01:00
|
|
|
partChanged();
|
2013-12-27 23:59:59 +01:00
|
|
|
return ForgeDirection.UNKNOWN;
|
|
|
|
}
|
2014-04-28 20:19:41 +02:00
|
|
|
else if ( bp != null && !(bp instanceof IPartCable) && side != ForgeDirection.UNKNOWN )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
IPart cable = getPart( ForgeDirection.UNKNOWN );
|
2014-01-30 19:54:09 +01:00
|
|
|
if ( cable != null && !bp.canBePlacedOn( ((IPartCable) cable).supportsBuses() ) )
|
2014-01-20 17:41:37 +01:00
|
|
|
return null;
|
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
setSide( side, bp );
|
2013-12-27 23:59:59 +01:00
|
|
|
bp.setPartHostInfo( side, this, this.getTile() );
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
if ( player != null )
|
|
|
|
bp.onPlacement( player, is, side );
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( inWorld )
|
|
|
|
bp.addToWorld();
|
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
if ( getCenter() != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
IGridNode cn = getCenter().getGridNode();
|
2013-12-27 23:59:59 +01:00
|
|
|
IGridNode sn = bp.getGridNode();
|
|
|
|
|
|
|
|
if ( cn != null && sn != null )
|
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
new GridConnection( (IGridNode) cn, (IGridNode) sn, ForgeDirection.UNKNOWN );
|
|
|
|
}
|
|
|
|
catch (FailedConnection e)
|
|
|
|
{
|
|
|
|
// ekk!
|
|
|
|
|
|
|
|
bp.removeFromWorld();
|
2014-08-27 07:57:37 +02:00
|
|
|
setSide( side, null );
|
2014-01-27 05:00:36 +01:00
|
|
|
return null;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-06 05:36:10 +01:00
|
|
|
updateDynamicRender();
|
2013-12-27 23:59:59 +01:00
|
|
|
updateConnections();
|
|
|
|
markForUpdate();
|
2014-09-06 08:25:58 +02:00
|
|
|
markForSave();
|
2014-02-26 16:17:39 +01:00
|
|
|
partChanged();
|
2013-12-27 23:59:59 +01:00
|
|
|
return side;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-06-20 19:12:48 +02:00
|
|
|
private static final ThreadLocal<Boolean> isLoading = new ThreadLocal();
|
2014-06-26 04:19:20 +02:00
|
|
|
|
|
|
|
public static boolean isLoading()
|
|
|
|
{
|
2014-06-20 19:12:48 +02:00
|
|
|
Boolean is = isLoading.get();
|
|
|
|
return is != null && is == true;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public void addToWorld()
|
|
|
|
{
|
2014-01-29 04:10:23 +01:00
|
|
|
if ( inWorld )
|
|
|
|
return;
|
2014-06-26 04:19:20 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
inWorld = true;
|
2014-06-20 19:12:48 +02:00
|
|
|
isLoading.set( true );
|
2014-06-26 04:19:20 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
TileEntity te = getTile();
|
|
|
|
|
|
|
|
// start with the center, then install the side parts into the grid.
|
|
|
|
for (int x = 6; x >= 0; x--)
|
|
|
|
{
|
|
|
|
ForgeDirection s = ForgeDirection.getOrientation( x );
|
|
|
|
IPart part = getPart( s );
|
|
|
|
|
|
|
|
if ( part != null )
|
|
|
|
{
|
|
|
|
part.setPartHostInfo( s, this, te );
|
|
|
|
part.addToWorld();
|
|
|
|
|
|
|
|
if ( s != ForgeDirection.UNKNOWN )
|
|
|
|
{
|
|
|
|
IGridNode sn = part.getGridNode();
|
|
|
|
if ( sn != null )
|
|
|
|
{
|
2014-01-30 19:54:09 +01:00
|
|
|
// this is a really stupid if statement, why was this
|
|
|
|
// here?
|
2013-12-27 23:59:59 +01:00
|
|
|
// if ( !sn.getConnections().iterator().hasNext() )
|
|
|
|
|
|
|
|
IPart center = getPart( ForgeDirection.UNKNOWN );
|
|
|
|
if ( center != null )
|
|
|
|
{
|
|
|
|
IGridNode cn = center.getGridNode();
|
|
|
|
if ( cn != null )
|
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
AEApi.instance().createGridConnection( cn, sn );
|
|
|
|
}
|
|
|
|
catch (FailedConnection e)
|
|
|
|
{
|
|
|
|
// ekk
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-09 01:10:19 +02:00
|
|
|
|
|
|
|
partChanged();
|
2014-06-26 04:19:20 +02:00
|
|
|
|
|
|
|
isLoading.set( false );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void removeFromWorld()
|
|
|
|
{
|
2014-01-29 04:10:23 +01:00
|
|
|
if ( !inWorld )
|
|
|
|
return;
|
2014-06-09 01:10:19 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
inWorld = false;
|
|
|
|
|
|
|
|
for (ForgeDirection s : ForgeDirection.values())
|
|
|
|
{
|
|
|
|
IPart part = getPart( s );
|
|
|
|
if ( part != null )
|
|
|
|
part.removeFromWorld();
|
|
|
|
}
|
2014-06-09 01:10:19 +02:00
|
|
|
|
|
|
|
partChanged();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-06 07:54:25 +01:00
|
|
|
public boolean canConnectRedstone(EnumSet<ForgeDirection> enumSet)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-06 07:54:25 +01:00
|
|
|
for (ForgeDirection dir : enumSet)
|
|
|
|
{
|
|
|
|
IPart part = getPart( dir );
|
|
|
|
if ( part != null && part.canConnectRedstone() )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGridNode getGridNode(ForgeDirection side)
|
|
|
|
{
|
|
|
|
IPart part = getPart( side );
|
|
|
|
if ( part != null )
|
|
|
|
{
|
|
|
|
IGridNode n = part.getExternalFacingNode();
|
|
|
|
if ( n != null )
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
if ( getCenter() != null )
|
|
|
|
return getCenter().getGridNode();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-04-29 08:44:13 +02:00
|
|
|
public Iterable<AxisAlignedBB> getSelectedBoundingBoxsFromPool(boolean ignoreCableConnections, boolean includeFacades, Entity e, boolean visual)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
List<AxisAlignedBB> boxes = new LinkedList<AxisAlignedBB>();
|
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
IFacadeContainer fc = getFacadeContainer();
|
2013-12-27 23:59:59 +01:00
|
|
|
for (ForgeDirection s : ForgeDirection.values())
|
|
|
|
{
|
2014-09-20 22:20:53 +02:00
|
|
|
IPartCollisionHelper bch = new BusCollisionHelper( boxes, s, e, visual );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
IPart part = getPart( s );
|
|
|
|
if ( part != null )
|
|
|
|
{
|
|
|
|
if ( ignoreCableConnections && part instanceof IPartCable )
|
|
|
|
bch.addBox( 6.0, 6.0, 6.0, 10.0, 10.0, 10.0 );
|
|
|
|
else
|
|
|
|
part.getBoxes( bch );
|
|
|
|
}
|
|
|
|
|
2014-08-03 06:53:34 +02:00
|
|
|
if ( AEApi.instance().partHelper().getCableRenderMode().opaqueFacades || !visual )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-08-03 06:53:34 +02:00
|
|
|
if ( includeFacades && s != null && s != ForgeDirection.UNKNOWN )
|
|
|
|
{
|
|
|
|
IFacadePart fp = fc.getFacade( s );
|
|
|
|
if ( fp != null )
|
|
|
|
fp.getBoxes( bch, e );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return boxes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onEntityCollision(Entity entity)
|
|
|
|
{
|
|
|
|
for (ForgeDirection s : ForgeDirection.values())
|
|
|
|
{
|
|
|
|
IPart part = getPart( s );
|
|
|
|
if ( part != null )
|
|
|
|
part.onEntityCollision( entity );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isEmpty()
|
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
IFacadeContainer fc = getFacadeContainer();
|
2013-12-27 23:59:59 +01:00
|
|
|
for (ForgeDirection s : ForgeDirection.values())
|
|
|
|
{
|
|
|
|
IPart part = getPart( s );
|
|
|
|
if ( part != null )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( s != ForgeDirection.UNKNOWN )
|
|
|
|
{
|
|
|
|
IFacadePart fp = fc.getFacade( s );
|
|
|
|
if ( fp != null )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onNeighborChanged()
|
|
|
|
{
|
2014-08-23 08:25:06 +02:00
|
|
|
hasRedstone = YesNo.UNDECIDED;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
for (ForgeDirection s : ForgeDirection.values())
|
|
|
|
{
|
|
|
|
IPart part = getPart( s );
|
|
|
|
if ( part != null )
|
|
|
|
part.onNeighborChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-23 08:25:06 +02:00
|
|
|
private void updateRedstone()
|
|
|
|
{
|
|
|
|
TileEntity te = getTile();
|
|
|
|
hasRedstone = te.getWorldObj().isBlockIndirectlyGettingPowered( te.xCoord, te.yCoord, te.zCoord ) ? YesNo.YES : YesNo.NO;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public boolean isSolidOnSide(ForgeDirection side)
|
|
|
|
{
|
|
|
|
if ( side == null || side == ForgeDirection.UNKNOWN )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// facades are solid..
|
2014-08-27 07:57:37 +02:00
|
|
|
IFacadePart fp = getFacadeContainer().getFacade( side );
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( fp != null )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// buses can be too.
|
|
|
|
IPart part = getPart( side );
|
|
|
|
return part != null && part.isSolid();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int isProvidingWeakPower(ForgeDirection side)
|
|
|
|
{
|
|
|
|
IPart part = getPart( side );
|
|
|
|
return part != null ? part.isProvidingWeakPower() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int isProvidingStrongPower(ForgeDirection side)
|
|
|
|
{
|
|
|
|
IPart part = getPart( side );
|
|
|
|
return part != null ? part.isProvidingStrongPower() : 0;
|
|
|
|
}
|
|
|
|
|
2014-02-07 06:51:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-27 23:59:59 +01:00
|
|
|
public void renderStatic(double x, double y, double z)
|
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
CableRenderHelper.getInstance().renderStatic( this, getFacadeContainer() );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 06:51:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-27 23:59:59 +01:00
|
|
|
public void renderDynamic(double x, double y, double z)
|
|
|
|
{
|
2014-02-07 06:51:19 +01:00
|
|
|
CableRenderHelper.getInstance().renderDynamic( this, x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
public void writeToStream(ByteBuf data) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
int sides = 0;
|
|
|
|
for (int x = 0; x < 7; x++)
|
|
|
|
{
|
|
|
|
IPart p = getPart( ForgeDirection.getOrientation( x ) );
|
|
|
|
if ( p != null )
|
|
|
|
{
|
|
|
|
sides = sides | (1 << x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data.writeByte( (byte) sides );
|
|
|
|
|
|
|
|
for (int x = 0; x < 7; x++)
|
|
|
|
{
|
|
|
|
ItemStack is = null;
|
|
|
|
IPart p = getPart( ForgeDirection.getOrientation( x ) );
|
|
|
|
if ( p != null )
|
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
is = p.getItemStack( PartItemStack.Network );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
data.writeShort( Item.getIdFromItem( is.getItem() ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
data.writeShort( is.getItemDamage() );
|
|
|
|
|
|
|
|
if ( p != null )
|
|
|
|
p.writeToStream( data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
getFacadeContainer().writeToStream( data );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
public boolean readFromStream(ByteBuf data) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
byte sides = data.readByte();
|
|
|
|
|
2014-05-10 20:27:48 +02:00
|
|
|
boolean updateBlock = false;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
for (int x = 0; x < 7; x++)
|
|
|
|
{
|
|
|
|
ForgeDirection side = ForgeDirection.getOrientation( x );
|
|
|
|
if ( ((sides & (1 << x)) == (1 << x)) )
|
|
|
|
{
|
|
|
|
IPart p = getPart( side );
|
|
|
|
|
|
|
|
short itemID = data.readShort();
|
|
|
|
short dmgValue = data.readShort();
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
Item myItem = Item.getItemById( itemID );
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
ItemStack current = p != null ? p.getItemStack( PartItemStack.Network ) : null;
|
2014-02-09 02:34:52 +01:00
|
|
|
if ( current != null && current.getItem() == myItem && current.getItemDamage() == dmgValue )
|
2014-05-10 20:27:48 +02:00
|
|
|
{
|
|
|
|
if ( p.readFromStream( data ) )
|
|
|
|
updateBlock = true;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
else
|
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
removePart( side, false );
|
2014-02-09 02:34:52 +01:00
|
|
|
side = addPart( new ItemStack( myItem, 1, dmgValue ), side, null );
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( side != null )
|
|
|
|
{
|
|
|
|
p = getPart( side );
|
|
|
|
p.readFromStream( data );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw new RuntimeException( "Invalid Stream For CableBus Container." );
|
|
|
|
}
|
|
|
|
}
|
2014-05-08 08:00:29 +02:00
|
|
|
else if ( getPart( side ) != null )
|
2014-01-27 05:00:36 +01:00
|
|
|
removePart( side, false );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
if ( getFacadeContainer().readFromStream( data ) )
|
2014-05-10 20:27:48 +02:00
|
|
|
return true;
|
2014-08-27 07:57:37 +02:00
|
|
|
|
2014-05-10 20:27:48 +02:00
|
|
|
return updateBlock;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ForgeDirection getSide(IPart part)
|
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
if ( getCenter() == part )
|
2013-12-27 23:59:59 +01:00
|
|
|
return ForgeDirection.UNKNOWN;
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
if ( getSide( side ) == part )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
return side;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new RuntimeException( "Uhh Bad Part on Side." );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void writeToNBT(NBTTagCompound data)
|
|
|
|
{
|
2014-08-23 08:25:06 +02:00
|
|
|
data.setInteger( "hasRedstone", hasRedstone.ordinal() );
|
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
IFacadeContainer fc = getFacadeContainer();
|
2013-12-27 23:59:59 +01:00
|
|
|
for (ForgeDirection s : ForgeDirection.values())
|
|
|
|
{
|
|
|
|
fc.writeToNBT( data );
|
|
|
|
|
|
|
|
IPart part = getPart( s );
|
|
|
|
if ( part != null )
|
|
|
|
{
|
|
|
|
NBTTagCompound def = new NBTTagCompound();
|
2014-01-20 17:41:37 +01:00
|
|
|
part.getItemStack( PartItemStack.World ).writeToNBT( def );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
NBTTagCompound extra = new NBTTagCompound();
|
|
|
|
part.writeToNBT( extra );
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
data.setTag( "def:" + getSide( part ).ordinal(), def );
|
|
|
|
data.setTag( "extra:" + getSide( part ).ordinal(), extra );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void readFromNBT(NBTTagCompound data)
|
|
|
|
{
|
2014-08-23 08:25:06 +02:00
|
|
|
if ( data.hasKey( "hasRedstone" ) )
|
|
|
|
hasRedstone = YesNo.values()[data.getInteger( "hasRedstone" )];
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
for (int x = 0; x < 7; x++)
|
|
|
|
{
|
|
|
|
ForgeDirection side = ForgeDirection.getOrientation( x );
|
|
|
|
|
|
|
|
NBTTagCompound def = data.getCompoundTag( "def:" + side.ordinal() );
|
|
|
|
NBTTagCompound extra = data.getCompoundTag( "extra:" + side.ordinal() );
|
|
|
|
if ( def != null && extra != null )
|
|
|
|
{
|
|
|
|
IPart p = getPart( side );
|
|
|
|
ItemStack iss = ItemStack.loadItemStackFromNBT( def );
|
|
|
|
if ( iss == null )
|
|
|
|
continue;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
ItemStack current = p == null ? null : p.getItemStack( PartItemStack.World );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
if ( Platform.isSameItemType( iss, current ) )
|
|
|
|
p.readFromNBT( extra );
|
|
|
|
else
|
|
|
|
{
|
2014-02-12 07:17:44 +01:00
|
|
|
removePart( side, true );
|
2014-01-27 05:00:36 +01:00
|
|
|
side = addPart( iss, side, null );
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( side != null )
|
|
|
|
{
|
|
|
|
p = getPart( side );
|
|
|
|
p.readFromNBT( extra );
|
|
|
|
}
|
|
|
|
else
|
2014-05-27 23:02:15 +02:00
|
|
|
{
|
|
|
|
AELog.warning( "Invalid NBT For CableBus Container: " + iss.getItem().getClass().getName() + " is not a valid part; it was ignored." );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2014-01-27 05:00:36 +01:00
|
|
|
removePart( side, false );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-02-14 03:27:04 +01:00
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
getFacadeContainer().readFromNBT( data );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public List getDrops(List drops)
|
|
|
|
{
|
|
|
|
for (ForgeDirection s : ForgeDirection.values())
|
|
|
|
{
|
|
|
|
IPart part = getPart( s );
|
|
|
|
if ( part != null )
|
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
drops.add( part.getItemStack( PartItemStack.Break ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
part.getDrops( drops, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( s != ForgeDirection.UNKNOWN )
|
|
|
|
{
|
|
|
|
IFacadePart fp = getFacadeContainer().getFacade( s );
|
|
|
|
if ( fp != null )
|
|
|
|
drops.add( fp.getItemStack() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return drops;
|
|
|
|
}
|
|
|
|
|
2014-09-05 05:42:48 +02:00
|
|
|
public List getNoDrops(List drops)
|
|
|
|
{
|
|
|
|
for (ForgeDirection s : ForgeDirection.values())
|
|
|
|
{
|
|
|
|
IPart part = getPart( s );
|
|
|
|
if ( part != null )
|
|
|
|
{
|
|
|
|
part.getDrops( drops, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return drops;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public void markForUpdate()
|
|
|
|
{
|
|
|
|
tcb.markForUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DimensionalCoord getLocation()
|
|
|
|
{
|
|
|
|
return tcb.getLocation();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TileEntity getTile()
|
|
|
|
{
|
|
|
|
return tcb.getTile();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AECableType getCableConnectionType(ForgeDirection dir)
|
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
IPart part = getPart( dir );
|
|
|
|
if ( part != null && part instanceof IGridHost )
|
|
|
|
{
|
|
|
|
AECableType t = ((IGridHost) part).getCableConnectionType( dir );
|
|
|
|
if ( t != null && t != AECableType.NONE )
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
if ( getCenter() != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
IPartCable c = getCenter();
|
2013-12-27 23:59:59 +01:00
|
|
|
return c.getCableConnectionType();
|
|
|
|
}
|
|
|
|
return AECableType.NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AEColor getColor()
|
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
if ( getCenter() != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
IPartCable c = getCenter();
|
2013-12-27 23:59:59 +01:00
|
|
|
return c.getCableColor();
|
|
|
|
}
|
|
|
|
return AEColor.Transparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IFacadeContainer getFacadeContainer()
|
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
return new FacadeContainer( this );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clearContainer()
|
|
|
|
{
|
|
|
|
throw new RuntimeException( "Now thats silly!" );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isBlocked(ForgeDirection side)
|
|
|
|
{
|
|
|
|
return tcb.isBlocked( side );
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getLightValue()
|
|
|
|
{
|
|
|
|
int light = 0;
|
2014-05-16 04:18:30 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
for (ForgeDirection d : ForgeDirection.values())
|
|
|
|
{
|
|
|
|
IPart p = getPart( d );
|
|
|
|
if ( p != null )
|
|
|
|
light = Math.max( p.getLightLevel(), light );
|
|
|
|
}
|
2014-05-16 04:18:30 +02:00
|
|
|
|
2014-07-24 00:26:23 +02:00
|
|
|
if ( light > 0 && AppEng.instance.isIntegrationEnabled( IntegrationType.CLApi ) )
|
|
|
|
return ((ICLApi) AppEng.instance.getIntegration( IntegrationType.CLApi )).colorLight( getColor(), light );
|
2014-05-16 04:18:30 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
return light;
|
|
|
|
}
|
|
|
|
|
2014-03-27 04:27:14 +01:00
|
|
|
@Override
|
2014-07-21 05:45:08 +02:00
|
|
|
public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
IPart cable = getPart( ForgeDirection.UNKNOWN );
|
|
|
|
if ( cable != null )
|
|
|
|
{
|
|
|
|
IPartCable pc = (IPartCable) cable;
|
2014-07-21 05:45:08 +02:00
|
|
|
return pc.changeColor( colour, who );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean activate(EntityPlayer player, Vec3 pos)
|
|
|
|
{
|
|
|
|
SelectedPart p = selectPart( pos );
|
|
|
|
if ( p != null && p.part != null )
|
|
|
|
{
|
|
|
|
return p.part.onActivate( player, pos );
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SelectedPart selectPart(Vec3 pos)
|
|
|
|
{
|
|
|
|
for (ForgeDirection side : ForgeDirection.values())
|
|
|
|
{
|
|
|
|
IPart p = getPart( side );
|
|
|
|
if ( p != null )
|
|
|
|
{
|
|
|
|
List<AxisAlignedBB> boxes = new LinkedList<AxisAlignedBB>();
|
|
|
|
|
2014-09-20 22:20:53 +02:00
|
|
|
IPartCollisionHelper bch = new BusCollisionHelper( boxes, side, null, true );
|
2013-12-27 23:59:59 +01:00
|
|
|
p.getBoxes( bch );
|
|
|
|
for (AxisAlignedBB bb : boxes)
|
|
|
|
{
|
|
|
|
bb = bb.expand( 0.002, 0.002, 0.002 );
|
|
|
|
if ( bb.isVecInside( pos ) )
|
|
|
|
{
|
|
|
|
return new SelectedPart( p, side );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-03 06:53:34 +02:00
|
|
|
if ( AEApi.instance().partHelper().getCableRenderMode().opaqueFacades )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
IFacadeContainer fc = getFacadeContainer();
|
2014-08-03 06:53:34 +02:00
|
|
|
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-08-03 06:53:34 +02:00
|
|
|
IFacadePart p = fc.getFacade( side );
|
|
|
|
if ( p != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-08-03 06:53:34 +02:00
|
|
|
List<AxisAlignedBB> boxes = new LinkedList<AxisAlignedBB>();
|
|
|
|
|
2014-09-20 22:20:53 +02:00
|
|
|
IPartCollisionHelper bch = new BusCollisionHelper( boxes, side, null, true );
|
2014-08-03 06:53:34 +02:00
|
|
|
p.getBoxes( bch, null );
|
|
|
|
for (AxisAlignedBB bb : boxes)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-08-03 06:53:34 +02:00
|
|
|
bb = bb.expand( 0.01, 0.01, 0.01 );
|
|
|
|
if ( bb.isVecInside( pos ) )
|
|
|
|
{
|
|
|
|
return new SelectedPart( p, side );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new SelectedPart();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-26 16:17:39 +01:00
|
|
|
public void partChanged()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-08-27 07:57:37 +02:00
|
|
|
if ( getCenter() == null )
|
2014-02-10 02:03:19 +01:00
|
|
|
{
|
|
|
|
List<ItemStack> facades = new LinkedList();
|
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
IFacadeContainer fc = getFacadeContainer();
|
2014-02-10 02:03:19 +01:00
|
|
|
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
{
|
|
|
|
IFacadePart fp = fc.getFacade( d );
|
|
|
|
if ( fp != null )
|
|
|
|
{
|
|
|
|
facades.add( fp.getItemStack() );
|
|
|
|
fc.removeFacade( tcb, d );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( facades != null && !facades.isEmpty() )
|
|
|
|
{
|
|
|
|
TileEntity te = tcb.getTile();
|
|
|
|
Platform.spawnDrops( te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, facades );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 16:17:39 +01:00
|
|
|
tcb.partChanged();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markForSave()
|
|
|
|
{
|
|
|
|
tcb.markForSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void randomDisplayTick(World world, int x, int y, int z, Random r)
|
|
|
|
{
|
|
|
|
for (ForgeDirection side : ForgeDirection.values())
|
|
|
|
{
|
|
|
|
IPart p = getPart( side );
|
|
|
|
if ( p != null )
|
|
|
|
{
|
|
|
|
p.randomDisplayTick( world, x, y, z, r );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasRedstone(ForgeDirection side)
|
|
|
|
{
|
2014-08-23 08:25:06 +02:00
|
|
|
if ( hasRedstone == YesNo.UNDECIDED )
|
|
|
|
updateRedstone();
|
|
|
|
|
|
|
|
return hasRedstone == YesNo.YES;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2013-12-28 21:54:05 +01:00
|
|
|
public boolean isLadder(EntityLivingBase entity)
|
|
|
|
{
|
|
|
|
for (ForgeDirection side : ForgeDirection.values())
|
|
|
|
{
|
|
|
|
IPart p = getPart( side );
|
|
|
|
if ( p != null )
|
|
|
|
{
|
|
|
|
if ( p.isLadder( entity ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
@Override
|
|
|
|
public void securityBreak()
|
|
|
|
{
|
|
|
|
for (ForgeDirection d : ForgeDirection.values())
|
|
|
|
{
|
|
|
|
IPart p = getPart( d );
|
|
|
|
if ( p != null && p instanceof IGridHost )
|
|
|
|
((IGridHost) p).securityBreak();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-23 23:50:53 +01:00
|
|
|
@Override
|
|
|
|
public Set<LayerFlags> getLayerFlags()
|
|
|
|
{
|
|
|
|
return myLayerFlags;
|
|
|
|
}
|
|
|
|
|
2014-04-10 22:01:04 +02:00
|
|
|
@Override
|
2014-04-20 06:35:48 +02:00
|
|
|
public void cleanup()
|
|
|
|
{
|
2014-04-10 22:01:04 +02:00
|
|
|
tcb.cleanup();
|
|
|
|
}
|
|
|
|
|
2014-06-09 01:10:19 +02:00
|
|
|
@Override
|
|
|
|
public void notifyNeighbors()
|
|
|
|
{
|
|
|
|
tcb.notifyNeighbors();
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|