2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
2015-06-11 21:34:58 +02:00
|
|
|
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
2014-11-14 12:02:52 +01:00
|
|
|
*
|
|
|
|
* 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.fmp;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.implementations.parts.IPartCable;
|
|
|
|
import appeng.api.networking.IGridNode;
|
2017-04-12 16:10:13 +02:00
|
|
|
import appeng.api.parts.*;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.util.AECableType;
|
|
|
|
import appeng.api.util.AEColor;
|
|
|
|
import appeng.api.util.DimensionalCoord;
|
|
|
|
import appeng.client.render.BusRenderHelper;
|
|
|
|
import appeng.client.render.BusRenderer;
|
|
|
|
import appeng.core.AEConfig;
|
|
|
|
import appeng.core.AELog;
|
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.helpers.AEMultiTile;
|
|
|
|
import appeng.parts.BusCollisionHelper;
|
|
|
|
import appeng.parts.CableBusContainer;
|
|
|
|
import appeng.parts.PartPlacement;
|
|
|
|
import appeng.tile.networking.TileCableBus;
|
|
|
|
import appeng.util.Platform;
|
2017-04-12 16:10:13 +02:00
|
|
|
import codechicken.lib.data.MCDataInput;
|
|
|
|
import codechicken.lib.data.MCDataOutput;
|
|
|
|
import codechicken.lib.raytracer.IndexedCuboid6;
|
|
|
|
import codechicken.lib.vec.Cuboid6;
|
|
|
|
import codechicken.lib.vec.Vector3;
|
|
|
|
import codechicken.multipart.*;
|
|
|
|
import codechicken.multipart.scalatraits.TIInventoryTile;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import net.minecraft.util.Vec3;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.*;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
/**
|
|
|
|
* Implementing these might help improve visuals for hollow covers
|
2017-04-12 16:10:13 +02:00
|
|
|
* <p>
|
2014-09-24 02:26:27 +02:00
|
|
|
* TSlottedPart,ISidedHollowConnect
|
|
|
|
*/
|
2015-06-11 21:34:58 +02:00
|
|
|
public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IMaskedRedstonePart, AEMultiTile
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
private static final ThreadLocal<Boolean> DISABLE_FACADE_OCCLUSION = new ThreadLocal<Boolean>();
|
2015-06-11 21:34:58 +02:00
|
|
|
private static final double SHORTER = 6.0 / 16.0;
|
|
|
|
private static final double LONGER = 10.0 / 16.0;
|
|
|
|
private static final double MIN_DIRECTION = 0;
|
|
|
|
private static final double MAX_DIRECTION = 1.0;
|
2015-09-25 23:04:36 +02:00
|
|
|
private static final Cuboid6[] SIDE_TESTS = {
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-06-11 21:34:58 +02:00
|
|
|
// DOWN(0, -1, 0),
|
|
|
|
new Cuboid6( SHORTER, MIN_DIRECTION, SHORTER, LONGER, SHORTER, LONGER ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-06-11 21:34:58 +02:00
|
|
|
// UP(0, 1, 0),
|
|
|
|
new Cuboid6( SHORTER, LONGER, SHORTER, LONGER, MAX_DIRECTION, LONGER ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-06-11 21:34:58 +02:00
|
|
|
// NORTH(0, 0, -1),
|
|
|
|
new Cuboid6( SHORTER, SHORTER, MIN_DIRECTION, LONGER, LONGER, SHORTER ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-06-11 21:34:58 +02:00
|
|
|
// SOUTH(0, 0, 1),
|
|
|
|
new Cuboid6( SHORTER, SHORTER, LONGER, LONGER, LONGER, MAX_DIRECTION ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-06-11 21:34:58 +02:00
|
|
|
// WEST(-1, 0, 0),
|
|
|
|
new Cuboid6( MIN_DIRECTION, SHORTER, SHORTER, SHORTER, LONGER, LONGER ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-06-11 21:34:58 +02:00
|
|
|
// EAST(1, 0, 0),
|
|
|
|
new Cuboid6( LONGER, SHORTER, SHORTER, MAX_DIRECTION, LONGER, LONGER ),
|
2014-09-24 02:26:27 +02:00
|
|
|
};
|
2015-06-11 21:34:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mask for {@link IMaskedRedstonePart#getConnectionMask(int)}
|
2017-04-12 16:10:13 +02:00
|
|
|
* <p>
|
2015-06-11 21:34:58 +02:00
|
|
|
* the bits are derived from the rotation, where 4 is the center
|
|
|
|
*/
|
|
|
|
private static final int CONNECTION_MASK = 0x000010;
|
2015-10-08 15:42:42 +02:00
|
|
|
private CableBusContainer cb = new CableBusContainer( this );
|
|
|
|
private boolean canUpdate = false;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean recolourBlock( final ForgeDirection side, final AEColor colour, final EntityPlayer who )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().recolourBlock( side, colour, who );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public Cuboid6 getBounds()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
AxisAlignedBB b = null;
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
for( final AxisAlignedBB bx : this.getCableBus().getSelectedBoundingBoxesFromPool( false, true, null, true ) )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
if( b == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
b = bx;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final double minX = Math.min( b.minX, bx.minX );
|
|
|
|
final double minY = Math.min( b.minY, bx.minY );
|
|
|
|
final double minZ = Math.min( b.minZ, bx.minZ );
|
|
|
|
final double maxX = Math.max( b.maxX, bx.maxX );
|
|
|
|
final double maxY = Math.max( b.maxY, bx.maxY );
|
|
|
|
final double maxZ = Math.max( b.maxZ, bx.maxZ );
|
2015-04-03 08:54:31 +02:00
|
|
|
b.setBounds( minX, minY, minZ, maxX, maxY, maxZ );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( b == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return new Cuboid6( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
return new Cuboid6( b.minX, b.minY, b.minZ, b.maxX, b.maxY, b.maxZ );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public String getType()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return PartRegistry.CableBusPart.getName();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public int getLightValue()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().getLightValue();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void onWorldJoin()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.canUpdate = true;
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getCableBus().updateConnections();
|
|
|
|
this.getCableBus().addToWorld();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean occlusionTest( final TMultiPart part )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return NormalOcclusionTest.apply( this, part );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean renderStatic( final Vector3 pos, final int pass )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( pass == 0 || ( pass == 1 && AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) ) )
|
|
|
|
{
|
|
|
|
BusRenderHelper.INSTANCE.setPass( pass );
|
2015-10-08 15:42:42 +02:00
|
|
|
BusRenderer.INSTANCE.getRenderer().renderAllFaces = true;
|
|
|
|
BusRenderer.INSTANCE.getRenderer().blockAccess = this.world();
|
|
|
|
BusRenderer.INSTANCE.getRenderer().overrideBlockTexture = null;
|
|
|
|
this.getCableBus().renderStatic( pos.x, pos.y, pos.z );
|
2015-04-03 08:54:31 +02:00
|
|
|
return BusRenderHelper.INSTANCE.getItemsRendered() > 0;
|
|
|
|
}
|
|
|
|
return false;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void renderDynamic( final Vector3 pos, final float frame, final int pass )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( pass == 0 || ( pass == 1 && AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
BusRenderHelper.INSTANCE.setPass( pass );
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getCableBus().renderDynamic( pos.x, pos.y, pos.z );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void onPartChanged( final TMultiPart part )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getCableBus().updateConnections();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void onEntityCollision( final Entity entity )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getCableBus().onEntityCollision( entity );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean activate( final EntityPlayer player, final MovingObjectPosition hit, final ItemStack item )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().activate( player, hit.hitVec.addVector( -hit.blockX, -hit.blockY, -hit.blockZ ) );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void load( final NBTTagCompound tag )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getCableBus().readFromNBT( tag );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public void onWorldSeparate()
|
|
|
|
{
|
|
|
|
this.canUpdate = false;
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getCableBus().removeFromWorld();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void save( final NBTTagCompound tag )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getCableBus().writeToNBT( tag );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void writeDesc( final MCDataOutput packet )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final ByteBuf stream = Unpooled.buffer();
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getCableBus().writeToStream( stream );
|
2015-04-03 08:54:31 +02:00
|
|
|
packet.writeInt( stream.readableBytes() );
|
|
|
|
stream.capacity( stream.readableBytes() );
|
|
|
|
packet.writeByteArray( stream.array() );
|
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final IOException e )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-11-22 15:54:29 +01:00
|
|
|
AELog.debug( e );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public ItemStack pickItem( final MovingObjectPosition hit )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final Vec3 v3 = hit.hitVec.addVector( -hit.blockX, -hit.blockY, -hit.blockZ );
|
2015-10-08 15:42:42 +02:00
|
|
|
final SelectedPart sp = this.getCableBus().selectPart( v3 );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( sp != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( sp.part != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return sp.part.getItemStack( PartItemStack.Break );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( sp.facade != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return sp.facade.getItemStack();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Iterable<ItemStack> getDrops()
|
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().getDrops( new ArrayList() );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void onNeighborChanged()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getCableBus().onNeighborChanged();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean doesTick()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return false;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void invalidateConvertedTile()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getCableBus().setHost( this );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void readDesc( final MCDataInput packet )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final int len = packet.readInt();
|
|
|
|
final byte[] data = packet.readByteArray( len );
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( len > 0 )
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final ByteBuf byteBuffer = Unpooled.wrappedBuffer( data );
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getCableBus().readFromStream( byteBuffer );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final IOException e )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-11-22 15:54:29 +01:00
|
|
|
AELog.debug( e );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
2014-09-28 00:50:06 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean canConnectRedstone( final int side )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().canConnectRedstone( EnumSet.of( ForgeDirection.getOrientation( side ) ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public int weakPowerLevel( final int side )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().isProvidingWeakPower( ForgeDirection.getOrientation( side ) );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public int strongPowerLevel( final int side )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().isProvidingStrongPower( ForgeDirection.getOrientation( side ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public void convertFromTile( final TileEntity blockTileEntity )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final TileCableBus tcb = (TileCableBus) blockTileEntity;
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setCableBus( tcb.getCableBus() );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public Iterable<Cuboid6> getOcclusionBoxes()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final LinkedList<Cuboid6> l = new LinkedList<Cuboid6>();
|
2015-10-08 15:42:42 +02:00
|
|
|
for( final AxisAlignedBB b : this.getCableBus().getSelectedBoundingBoxesFromPool( true, DISABLE_FACADE_OCCLUSION.get() == null, null, true ) )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
l.add( new Cuboid6( b.minX, b.minY, b.minZ, b.maxX, b.maxY, b.maxZ ) );
|
|
|
|
}
|
|
|
|
return l;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public IGridNode getGridNode( final ForgeDirection dir )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().getGridNode( dir );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public AECableType getCableConnectionType( final ForgeDirection dir )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().getCableConnectionType( dir );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void securityBreak()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getCableBus().securityBreak();
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// @Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public int getHollowSize( final int side )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final IPartCable cable = (IPartCable) this.getPart( ForgeDirection.UNKNOWN );
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final ForgeDirection dir = ForgeDirection.getOrientation( side );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( cable != null && cable.isConnected( dir ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final List<AxisAlignedBB> boxes = new ArrayList<AxisAlignedBB>();
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final BusCollisionHelper bch = new BusCollisionHelper( boxes, ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH, null, true );
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final ForgeDirection whichSide : ForgeDirection.values() )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final IPart fPart = this.getPart( whichSide );
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
if( fPart != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
fPart.getBoxes( bch );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AxisAlignedBB b = null;
|
2015-09-25 23:10:56 +02:00
|
|
|
final AxisAlignedBB pb = Platform.getPrimaryBox( dir, 2 );
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final AxisAlignedBB bb : boxes )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
if( bb.intersectsWith( pb ) )
|
|
|
|
{
|
|
|
|
if( b == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
b = bb;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
b.maxX = Math.max( b.maxX, bb.maxX );
|
|
|
|
b.maxY = Math.max( b.maxY, bb.maxY );
|
|
|
|
b.maxZ = Math.max( b.maxZ, bb.maxZ );
|
|
|
|
b.minX = Math.min( b.minX, bb.minX );
|
|
|
|
b.minY = Math.min( b.minY, bb.minY );
|
|
|
|
b.minZ = Math.min( b.minZ, bb.minZ );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( b == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
switch( dir )
|
|
|
|
{
|
|
|
|
case WEST:
|
|
|
|
case EAST:
|
|
|
|
return this.getSize( b.minZ, b.maxZ, b.minY, b.maxY );
|
|
|
|
case DOWN:
|
|
|
|
case NORTH:
|
|
|
|
return this.getSize( b.minX, b.maxX, b.minZ, b.maxZ );
|
|
|
|
case SOUTH:
|
|
|
|
case UP:
|
|
|
|
return this.getSize( b.minX, b.maxX, b.minY, b.maxY );
|
|
|
|
default:
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
return 12;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
private int getSize( final double a, final double b, final double c, final double d )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
double r = Math.abs( a - 0.5 );
|
|
|
|
r = Math.max( Math.abs( b - 0.5 ), r );
|
|
|
|
r = Math.max( Math.abs( c - 0.5 ), r );
|
2017-04-12 16:10:13 +02:00
|
|
|
return ( 8 * (int) Math.max( Math.abs( d - 0.5 ), r ) );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
public int getSlotMask()
|
|
|
|
{
|
|
|
|
int mask = 0;
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final ForgeDirection side : ForgeDirection.values() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.getPart( side ) != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
mask |= 1 << side.ordinal();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( side != ForgeDirection.UNKNOWN && this.getFacadeContainer().getFacade( side ) != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
mask |= 1 << side.ordinal();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
return mask;
|
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-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().getFacadeContainer();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean canAddPart( ItemStack is, final ForgeDirection side )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final IFacadePart fp = PartPlacement.isFacade( is, side );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( fp != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !( side == null || side == ForgeDirection.UNKNOWN || this.tile() == null ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final List<AxisAlignedBB> boxes = new ArrayList<AxisAlignedBB>();
|
|
|
|
final IPartCollisionHelper bch = new BusCollisionHelper( boxes, side, null, true );
|
2014-09-24 02:26:27 +02:00
|
|
|
fp.getBoxes( bch, null );
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final AxisAlignedBB bb : boxes )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-01-01 22:13:10 +01:00
|
|
|
DISABLE_FACADE_OCCLUSION.set( true );
|
2015-09-25 23:10:56 +02:00
|
|
|
final boolean canAdd = this.tile().canAddPart( new NormallyOccludedPart( new Cuboid6( bb ) ) );
|
2015-01-01 22:13:10 +01:00
|
|
|
DISABLE_FACADE_OCCLUSION.remove();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !canAdd )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is.getItem() instanceof IPartItem )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final IPartItem bi = (IPartItem) is.getItem();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
is = is.copy();
|
|
|
|
is.stackSize = 1;
|
|
|
|
|
2015-05-24 13:36:43 +02:00
|
|
|
final IPart bp = bi.createPartFromItemStack( is );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !( side == null || side == ForgeDirection.UNKNOWN || this.tile() == null ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final List<AxisAlignedBB> boxes = new ArrayList<AxisAlignedBB>();
|
|
|
|
final IPartCollisionHelper bch = new BusCollisionHelper( boxes, side, null, true );
|
2015-05-24 13:36:43 +02:00
|
|
|
if( bp != null )
|
|
|
|
{
|
|
|
|
bp.getBoxes( bch );
|
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final AxisAlignedBB bb : boxes )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !this.tile().canAddPart( new NormallyOccludedPart( new Cuboid6( bb ) ) ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().canAddPart( is, side );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public ForgeDirection addPart( final ItemStack is, final ForgeDirection side, final EntityPlayer owner )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().addPart( is, side, owner );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public IPart getPart( final ForgeDirection side )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().getPart( side );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void removePart( final ForgeDirection side, final boolean suppressUpdate )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getCableBus().removePart( side, suppressUpdate );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markForUpdate()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.isServer() && this.canUpdate )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.sendDescUpdate();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DimensionalCoord getLocation()
|
|
|
|
{
|
2014-10-01 11:39:58 +02:00
|
|
|
return new DimensionalCoord( this.tile() );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public AEColor getColor()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().getColor();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void clearContainer()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setCableBus( new CableBusContainer( this ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean isBlocked( final ForgeDirection side )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( side == null || side == ForgeDirection.UNKNOWN || this.tile() == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-01-01 22:13:10 +01:00
|
|
|
DISABLE_FACADE_OCCLUSION.set( true );
|
2015-06-11 21:34:58 +02:00
|
|
|
|
|
|
|
final int ordinal = side.ordinal();
|
|
|
|
final Cuboid6 sideTest = SIDE_TESTS[ordinal];
|
|
|
|
final NormallyOccludedPart occludedPart = new NormallyOccludedPart( sideTest );
|
2015-09-25 23:10:56 +02:00
|
|
|
final boolean blocked = !this.tile().canAddPart( occludedPart );
|
2015-01-01 22:13:10 +01:00
|
|
|
DISABLE_FACADE_OCCLUSION.remove();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
return blocked;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public SelectedPart selectPart( final Vec3 pos )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().selectPart( pos );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markForSave()
|
|
|
|
{
|
|
|
|
// mark the chunk for save...
|
2015-09-25 23:10:56 +02:00
|
|
|
final TileEntity te = this.tile();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( te != null && te.getWorldObj() != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
te.getWorldObj().getChunkFromBlockCoords( this.x(), this.z() ).isModified = true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void partChanged()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isInWorld() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.notifyNeighbors();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean hasRedstone( final ForgeDirection side )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().hasRedstone( side );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEmpty()
|
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().isEmpty();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public Set<LayerFlags> getLayerFlags()
|
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().getLayerFlags();
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
@Override
|
|
|
|
public void cleanup()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tile().remPart( this );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyNeighbors()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.tile() instanceof TIInventoryTile )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
( (TIInventoryTile) this.tile() ).rebuildSlotMap();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.world() != null && this.world().blockExists( this.x(), this.y(), this.z() ) && !CableBusContainer.isLoading() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
Platform.notifyBlocksOfNeighbors( this.world(), this.x(), this.y(), this.z() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public boolean isInWorld()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getCableBus().isInWorld();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-06-11 21:34:58 +02:00
|
|
|
@Override
|
|
|
|
public Iterable<Cuboid6> getCollisionBoxes()
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final LinkedList<Cuboid6> l = new LinkedList<Cuboid6>();
|
2015-10-08 15:42:42 +02:00
|
|
|
for( final AxisAlignedBB b : this.getCableBus().getSelectedBoundingBoxesFromPool( false, true, null, true ) )
|
2015-06-11 21:34:58 +02:00
|
|
|
{
|
|
|
|
l.add( new Cuboid6( b.minX, b.minY, b.minZ, b.maxX, b.maxY, b.maxZ ) );
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-06-11 21:34:58 +02:00
|
|
|
@Override
|
|
|
|
public Iterable<IndexedCuboid6> getSubParts()
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final LinkedList<IndexedCuboid6> l = new LinkedList<IndexedCuboid6>();
|
|
|
|
for( final Cuboid6 c : this.getCollisionBoxes() )
|
2015-06-11 21:34:58 +02:00
|
|
|
{
|
|
|
|
l.add( new IndexedCuboid6( 0, c ) );
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-06-11 21:34:58 +02:00
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public int getConnectionMask( final int side )
|
2015-06-11 21:34:58 +02:00
|
|
|
{
|
|
|
|
return CONNECTION_MASK;
|
|
|
|
}
|
2015-10-08 15:42:42 +02:00
|
|
|
|
|
|
|
public CableBusContainer getCableBus()
|
|
|
|
{
|
|
|
|
return this.cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setCableBus( final CableBusContainer cb )
|
|
|
|
{
|
|
|
|
this.cb = cb;
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|