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