2013-12-27 23:59:59 +01:00
|
|
|
package appeng.tile.networking;
|
|
|
|
|
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.ArrayList;
|
|
|
|
import java.util.List;
|
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;
|
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;
|
|
|
|
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.networking.IGridNode;
|
|
|
|
import appeng.api.parts.IFacadeContainer;
|
|
|
|
import appeng.api.parts.IPart;
|
2014-02-23 23:50:53 +01:00
|
|
|
import appeng.api.parts.LayerFlags;
|
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-05-05 02:51:05 +02:00
|
|
|
import appeng.block.networking.BlockCableBus;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.helpers.AEMultiTile;
|
|
|
|
import appeng.helpers.ICustomCollision;
|
2014-03-02 09:35:11 +01:00
|
|
|
import appeng.hooks.TickHandler;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.parts.CableBusContainer;
|
|
|
|
import appeng.tile.AEBaseTile;
|
|
|
|
import appeng.tile.events.AETileEventHandler;
|
|
|
|
import appeng.tile.events.TileEventType;
|
2014-03-18 04:58:03 +01:00
|
|
|
import appeng.util.Platform;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomCollision
|
|
|
|
{
|
|
|
|
|
|
|
|
public CableBusContainer cb = new CableBusContainer( this );
|
|
|
|
private int oldLV = -1; // on re-calculate light when it changes
|
2014-04-29 08:44:13 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
class CableBusHandler extends AETileEventHandler
|
|
|
|
{
|
|
|
|
|
|
|
|
public CableBusHandler() {
|
2014-01-26 07:46:16 +01:00
|
|
|
super( TileEventType.NETWORK, TileEventType.WORLD_NBT );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound data)
|
|
|
|
{
|
|
|
|
cb.readFromNBT( data );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound data)
|
|
|
|
{
|
|
|
|
cb.writeToNBT( data );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public boolean readFromStream(ByteBuf data) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
boolean ret = cb.readFromStream( data );
|
|
|
|
|
|
|
|
int newLV = cb.getLightValue();
|
|
|
|
if ( newLV != oldLV )
|
|
|
|
{
|
|
|
|
oldLV = newLV;
|
2014-02-09 02:34:52 +01:00
|
|
|
worldObj.func_147451_t( xCoord, yCoord, zCoord );
|
|
|
|
// worldObj.updateAllLightTypes( xCoord, yCoord, zCoord );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-05-05 02:51:05 +02:00
|
|
|
updateTileSetting();
|
2013-12-27 23:59:59 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void writeToStream(ByteBuf data) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
cb.writeToStream( data );
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-06-09 01:10:19 +02:00
|
|
|
@Override
|
|
|
|
public boolean isInWorld()
|
|
|
|
{
|
|
|
|
return cb.isInWorld();
|
|
|
|
}
|
|
|
|
|
2014-05-05 02:51:05 +02:00
|
|
|
protected void updateTileSetting()
|
|
|
|
{
|
|
|
|
if ( cb.requiresDynamicRender )
|
|
|
|
{
|
|
|
|
TileCableBus tcb;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
tcb = (TileCableBus) BlockCableBus.tesrTile.newInstance();
|
|
|
|
tcb.copyFrom( this );
|
|
|
|
getWorldObj().setTileEntity( xCoord, yCoord, zCoord, tcb );
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void copyFrom(TileCableBus oldTile)
|
|
|
|
{
|
|
|
|
CableBusContainer tmpCB = cb;
|
|
|
|
cb = oldTile.cb;
|
|
|
|
oldLV = oldTile.oldLV;
|
|
|
|
oldTile.cb = tmpCB;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public void onReady()
|
|
|
|
{
|
|
|
|
super.onReady();
|
|
|
|
if ( cb.isEmpty() )
|
2014-01-01 10:04:03 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
if ( worldObj.getTileEntity( xCoord, yCoord, zCoord ) == this )
|
|
|
|
worldObj.func_147480_a( xCoord, yCoord, zCoord, true );
|
2014-01-01 10:04:03 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
else
|
|
|
|
cb.addToWorld();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChunkUnload()
|
|
|
|
{
|
|
|
|
super.onChunkUnload();
|
|
|
|
cb.removeFromWorld();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void validate()
|
|
|
|
{
|
|
|
|
super.validate();
|
|
|
|
TickHandler.instance.addInit( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void invalidate()
|
|
|
|
{
|
|
|
|
super.invalidate();
|
|
|
|
cb.removeFromWorld();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canBeRotated()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-05 00:53:32 +02:00
|
|
|
@Override
|
|
|
|
public double getMaxRenderDistanceSquared()
|
|
|
|
{
|
|
|
|
return 900.0;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public void getDrops(World w, int x, int y, int z, ArrayList drops)
|
|
|
|
{
|
|
|
|
cb.getDrops( drops );
|
|
|
|
}
|
|
|
|
|
|
|
|
public TileCableBus() {
|
|
|
|
addNewHandler( new CableBusHandler() );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGridNode getGridNode(ForgeDirection dir)
|
|
|
|
{
|
|
|
|
return cb.getGridNode( dir );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canAddPart(ItemStack is, ForgeDirection side)
|
|
|
|
{
|
|
|
|
return cb.canAddPart( is, side );
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
return cb.addPart( is, side, player );
|
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
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
cb.removePart( side, supressUpdate );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IPart getPart(ForgeDirection side)
|
|
|
|
{
|
|
|
|
return cb.getPart( side );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DimensionalCoord getLocation()
|
|
|
|
{
|
|
|
|
return new DimensionalCoord( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TileEntity getTile()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-31 18:11:50 +01:00
|
|
|
public Iterable<AxisAlignedBB> getSelectedBoundingBoxsFromPool(World w, int x, int y, int z, Entity e, boolean visual)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-04-29 08:44:13 +02:00
|
|
|
return cb.getSelectedBoundingBoxsFromPool( false, true, e, visual );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e)
|
|
|
|
{
|
2014-01-31 18:11:50 +01:00
|
|
|
for (AxisAlignedBB bx : getSelectedBoundingBoxsFromPool( w, x, y, z, e, false ))
|
2014-06-05 05:59:56 +02:00
|
|
|
out.add( AxisAlignedBB.getBoundingBox( bx.minX, bx.minY, bx.minZ, bx.maxX, bx.maxY, bx.maxZ ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AECableType getCableConnectionType(ForgeDirection side)
|
|
|
|
{
|
|
|
|
return cb.getCableConnectionType( side );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AEColor getColor()
|
|
|
|
{
|
|
|
|
return cb.getColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IFacadeContainer getFacadeContainer()
|
|
|
|
{
|
|
|
|
return cb.getFacadeContainer();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clearContainer()
|
|
|
|
{
|
|
|
|
cb = new CableBusContainer( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isBlocked(ForgeDirection side)
|
|
|
|
{
|
2014-03-22 22:51:37 +01:00
|
|
|
return !ImmibisMicroblocks_isSideOpen( side.ordinal() );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markForUpdate()
|
|
|
|
{
|
|
|
|
if ( worldObj == null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int newLV = cb.getLightValue();
|
|
|
|
if ( newLV != oldLV )
|
|
|
|
{
|
|
|
|
oldLV = newLV;
|
2014-02-09 02:34:52 +01:00
|
|
|
worldObj.func_147451_t( xCoord, yCoord, zCoord );
|
|
|
|
// worldObj.updateAllLightTypes( xCoord, yCoord, zCoord );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
super.markForUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SelectedPart selectPart(Vec3 pos)
|
|
|
|
{
|
|
|
|
return cb.selectPart( pos );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-26 16:17:39 +01:00
|
|
|
public void partChanged()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-06-09 01:10:19 +02:00
|
|
|
notifyNeighbors();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyNeighbors()
|
|
|
|
{
|
2014-06-26 04:19:20 +02:00
|
|
|
if ( worldObj != null && worldObj.blockExists( xCoord, yCoord, zCoord ) && !CableBusContainer.isLoading() )
|
2014-07-08 06:54:28 +02:00
|
|
|
Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markForSave()
|
|
|
|
{
|
2014-02-26 05:34:05 +01:00
|
|
|
super.markDirty();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasRedstone(ForgeDirection side)
|
|
|
|
{
|
|
|
|
return cb.hasRedstone( side );
|
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-01-23 17:28:12 +01:00
|
|
|
@Override
|
|
|
|
public boolean isEmpty()
|
|
|
|
{
|
|
|
|
return cb.isEmpty();
|
|
|
|
}
|
2014-02-06 05:36:10 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean requiresTESR()
|
|
|
|
{
|
|
|
|
return cb.requiresDynamicRender;
|
|
|
|
}
|
|
|
|
|
2014-02-23 23:50:53 +01:00
|
|
|
@Override
|
|
|
|
public Set<LayerFlags> getLayerFlags()
|
|
|
|
{
|
|
|
|
return cb.getLayerFlags();
|
|
|
|
}
|
2014-04-29 08:44:13 +02:00
|
|
|
|
2014-04-10 22:01:04 +02:00
|
|
|
@Override
|
2014-04-29 08:44:13 +02:00
|
|
|
public void cleanup()
|
|
|
|
{
|
2014-04-10 22:01:04 +02:00
|
|
|
getWorldObj().setBlock( xCoord, yCoord, zCoord, Platform.air );
|
|
|
|
}
|
2014-02-23 23:50:53 +01:00
|
|
|
|
2014-03-22 22:51:37 +01:00
|
|
|
/**
|
|
|
|
* Immibis MB Support
|
|
|
|
*/
|
|
|
|
|
|
|
|
boolean ImmibisMicroblocks_TransformableTileEntityMarker = true;
|
|
|
|
|
|
|
|
public boolean ImmibisMicroblocks_isSideOpen(int side)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ImmibisMicroblocks_onMicroblocksChanged()
|
|
|
|
{
|
|
|
|
cb.updateConnections();
|
|
|
|
}
|
|
|
|
|
2014-07-21 05:45:08 +02:00
|
|
|
@Override
|
|
|
|
public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who)
|
|
|
|
{
|
|
|
|
return cb.recolourBlock( side, colour, who );
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|