Converted PartFlatWire to Scala (error)
This commit is contained in:
parent
2a5914f56a
commit
d5159e94b2
|
@ -26,9 +26,9 @@ import resonant.lib.render.EnumColor;
|
|||
import resonant.lib.utility.LinkUtility;
|
||||
import resonant.lib.utility.WrenchUtility;
|
||||
import resonant.lib.utility.inventory.InventoryUtility;
|
||||
import resonantinduction.core.prefab.part.MultipartUtil;
|
||||
import resonantinduction.core.Settings;
|
||||
import resonantinduction.core.prefab.part.PartFace;
|
||||
import resonantinduction.core.util.MultipartUtil;
|
||||
import resonantinduction.electrical.Electrical;
|
||||
import resonantinduction.electrical.ElectricalContent;
|
||||
import resonantinduction.electrical.tesla.TileTesla;
|
||||
|
|
|
@ -33,7 +33,7 @@ import resonant.lib.utility.LanguageUtility;
|
|||
import resonant.lib.utility.LinkUtility;
|
||||
import resonantinduction.core.Reference;
|
||||
import resonantinduction.core.Settings;
|
||||
import resonantinduction.core.prefab.part.MultipartUtil;
|
||||
import resonantinduction.core.util.ResonantUtil;
|
||||
import resonantinduction.electrical.Electrical;
|
||||
import universalelectricity.core.transform.vector.Vector3;
|
||||
|
||||
|
@ -698,7 +698,7 @@ public class TileTesla extends TileElectric implements IMultiBlockStructure<Tile
|
|||
{
|
||||
if (entityPlayer.getCurrentEquippedItem() != null)
|
||||
{
|
||||
int dyeColor = MultipartUtil.isDye(entityPlayer.getCurrentEquippedItem());
|
||||
int dyeColor = ResonantUtil.isDye(entityPlayer.getCurrentEquippedItem());
|
||||
|
||||
if (dyeColor != -1)
|
||||
{
|
||||
|
|
|
@ -1,930 +0,0 @@
|
|||
package resonantinduction.electrical.wire.flat;
|
||||
|
||||
import codechicken.lib.colour.Colour;
|
||||
import codechicken.lib.colour.ColourARGB;
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
import codechicken.lib.data.MCDataOutput;
|
||||
import codechicken.lib.raytracer.IndexedCuboid6;
|
||||
import codechicken.lib.render.CCRenderState;
|
||||
import codechicken.lib.render.TextureUtils;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.lib.vec.Rotation;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.multipart.*;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemDye;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import resonantinduction.core.util.MultipartUtil;
|
||||
import resonantinduction.electrical.wire.base.TWire;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* This is the base class for all wire types. It can be used for any sub type, as it contains the
|
||||
* base calculations necessary to create a working wire. This calculates all possible connections to
|
||||
* sides, around corners, and inside corners, while checking for microblock obstructions.
|
||||
*
|
||||
* @author Calclavia, MrTJP
|
||||
*/
|
||||
public class PartFlatWire extends TWire implements TFacePart, TNormalOcclusion
|
||||
{
|
||||
public static Cuboid6[][] selectionBounds = new Cuboid6[3][6];
|
||||
public static Cuboid6[][] occlusionBounds = new Cuboid6[3][6];
|
||||
|
||||
static
|
||||
{
|
||||
for (int t = 0; t < 3; t++)
|
||||
{
|
||||
// Subtract the box a little because we'd like things like posts to get first hit
|
||||
Cuboid6 selection = new Cuboid6(0, 0, 0, 1, (t + 2) / 16D, 1).expand(-0.005);
|
||||
Cuboid6 occlusion = new Cuboid6(2 / 8D, 0, 2 / 8D, 6 / 8D, (t + 2) / 16D, 6 / 8D);
|
||||
for (int s = 0; s < 6; s++)
|
||||
{
|
||||
selectionBounds[t][s] = selection.copy().apply(Rotation.sideRotations[s].at(Vector3.center));
|
||||
occlusionBounds[t][s] = occlusion.copy().apply(Rotation.sideRotations[s].at(Vector3.center));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Dummy
|
||||
public Object[] connections()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte side;
|
||||
|
||||
/**
|
||||
* A map of the corners.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Currently split into 4 nybbles (from lowest) 0 = Corner connections (this wire should connect
|
||||
* around a corner to something external) 1 = Straight connections (this wire should connect to
|
||||
* something external) 2 = Internal connections (this wire should connect to something internal)
|
||||
* 3 = Internal open connections (this wire is not blocked by a cover/edge part and *could*
|
||||
* connect through side) bit 16 = connection to the centerpart 5 = Render corner connections.
|
||||
* Like corner connections but set to low if the other wire part is smaller than this (they
|
||||
* render to us not us to them)
|
||||
*/
|
||||
public int connMap;
|
||||
|
||||
public PartFlatWire()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void preparePlacement(int side, int meta)
|
||||
{
|
||||
this.side = (byte) (side ^ 1);
|
||||
setMaterial(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* PACKET and NBT Methods
|
||||
*/
|
||||
@Override
|
||||
public void load(NBTTagCompound tag)
|
||||
{
|
||||
super.load(tag);
|
||||
this.side = tag.getByte("side");
|
||||
this.connMap = tag.getInteger("connMap");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound tag)
|
||||
{
|
||||
super.save(tag);
|
||||
tag.setByte("side", this.side);
|
||||
tag.setInteger("connMap", this.connMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readDesc(MCDataInput packet)
|
||||
{
|
||||
super.readDesc(packet);
|
||||
side = packet.readByte();
|
||||
connMap = packet.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDesc(MCDataOutput packet)
|
||||
{
|
||||
super.writeDesc(packet);
|
||||
packet.writeByte(side);
|
||||
packet.writeInt(connMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(MCDataInput packet)
|
||||
{
|
||||
read(packet, packet.readUByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(MCDataInput packet, int packetID)
|
||||
{
|
||||
if (packetID == 0)
|
||||
{
|
||||
connMap = packet.readInt();
|
||||
tile().markRender();
|
||||
}
|
||||
else
|
||||
{
|
||||
super.read(packet, packetID);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendConnUpdate()
|
||||
{
|
||||
tile().getWriteStream(this).writeByte(0).writeInt(this.connMap);
|
||||
}
|
||||
|
||||
/* WORLD EVENTS */
|
||||
@Override
|
||||
public void onRemoved()
|
||||
{
|
||||
super.onRemoved();
|
||||
|
||||
if (!world().isRemote)
|
||||
{
|
||||
for (int r = 0; r < 4; r++)
|
||||
{
|
||||
if (maskConnects(r))
|
||||
{
|
||||
if ((connMap & 1 << r) != 0)
|
||||
{
|
||||
notifyCornerChange(r);
|
||||
}
|
||||
else if ((connMap & 0x10 << r) != 0)
|
||||
{
|
||||
notifyStraightChange(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkLoad()
|
||||
{
|
||||
if ((connMap & 0x80000000) != 0) // compat with converters, recalc connections
|
||||
{
|
||||
if (dropIfCantStay())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
connMap = 0;
|
||||
|
||||
updateInternalConnections();
|
||||
|
||||
if (updateOpenConnections())
|
||||
{
|
||||
updateExternalConnections();
|
||||
}
|
||||
|
||||
tile().markDirty();
|
||||
}
|
||||
|
||||
this.recalculateConnections();
|
||||
|
||||
super.onChunkLoad();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdded()
|
||||
{
|
||||
super.onAdded();
|
||||
|
||||
if (!world().isRemote)
|
||||
{
|
||||
updateOpenConnections();
|
||||
boolean changed = updateInternalConnections();
|
||||
// don't use || because it's fail fast
|
||||
changed |= updateExternalConnections();
|
||||
|
||||
if (changed)
|
||||
{
|
||||
sendConnUpdate();
|
||||
}
|
||||
|
||||
this.recalculateConnections();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPartChanged(TMultiPart part)
|
||||
{
|
||||
if (!world().isRemote)
|
||||
{
|
||||
boolean changed = updateInternalConnections();
|
||||
|
||||
if (updateOpenConnections())
|
||||
{
|
||||
changed |= updateExternalConnections();
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
sendConnUpdate();
|
||||
}
|
||||
|
||||
this.recalculateConnections();
|
||||
}
|
||||
|
||||
super.onPartChanged(part);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
if (!world().isRemote)
|
||||
{
|
||||
if (dropIfCantStay())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (updateExternalConnections())
|
||||
{
|
||||
sendConnUpdate();
|
||||
}
|
||||
|
||||
this.recalculateConnections();
|
||||
}
|
||||
super.onNeighborChanged();
|
||||
}
|
||||
|
||||
public void recalculateConnections()
|
||||
{
|
||||
this.updateOpenConnections();
|
||||
|
||||
boolean[] calculatedSides = new boolean[6];
|
||||
|
||||
/** Check external connections. */
|
||||
for (byte r = 0; r < 4; r++)
|
||||
{
|
||||
if (maskOpen(r))
|
||||
{
|
||||
int absDir = Rotation.rotateSide(this.side, r);
|
||||
|
||||
// Check direct connection.
|
||||
if (this.setExternalConnection(r, absDir))
|
||||
{
|
||||
calculatedSides[absDir] = true;
|
||||
}
|
||||
|
||||
// Check Corner Connection
|
||||
BlockCoord cornerPos = new BlockCoord(tile());
|
||||
cornerPos.offset(absDir);
|
||||
|
||||
if (canConnectThroughCorner(cornerPos, absDir ^ 1, this.side))
|
||||
{
|
||||
cornerPos.offset(this.side);
|
||||
TileMultipart tpCorner = MultipartUtil.getMultipartTile(world(), cornerPos);
|
||||
|
||||
if (tpCorner != null)
|
||||
{
|
||||
TMultiPart tp = tpCorner.partMap(absDir ^ 1);
|
||||
|
||||
if (this.canConnectTo(tp, ForgeDirection.getOrientation(absDir)))
|
||||
{
|
||||
this.connections()[absDir] = tp;
|
||||
|
||||
if (tp instanceof PartFlatWire)
|
||||
{
|
||||
// We found a wire, merge networks!
|
||||
//this.getNetwork().merge(((PartFlatWire) tp).getNetwork());
|
||||
}
|
||||
|
||||
calculatedSides[absDir] = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!calculatedSides[absDir])
|
||||
{
|
||||
this.disconnect(absDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Check internal connections. */
|
||||
for (byte r = 0; r < 4; r++)
|
||||
{
|
||||
int absDir = Rotation.rotateSide(this.side, r);
|
||||
|
||||
/** Look for an internal straight connection. */
|
||||
if (tile().partMap(PartMap.edgeBetween(absDir, this.side)) == null)
|
||||
{
|
||||
TMultiPart tp = tile().partMap(absDir);
|
||||
|
||||
if (this.canConnectTo(tp))
|
||||
{
|
||||
// We found a wire! Merge networks!
|
||||
this.connections()[absDir] = tp;
|
||||
|
||||
if (tp instanceof PartFlatWire)
|
||||
{
|
||||
//this.getNetwork().merge(((PartFlatWire) tp).getNetwork());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!calculatedSides[absDir])
|
||||
{
|
||||
this.disconnect(absDir);
|
||||
}
|
||||
}
|
||||
|
||||
// Connect to the face of the block the wire is placed on.
|
||||
this.setExternalConnection(-1, this.side);
|
||||
|
||||
//this.getNetwork().reconstruct();
|
||||
}
|
||||
|
||||
public boolean setExternalConnection(int r, int absSide)
|
||||
{
|
||||
BlockCoord pos = new BlockCoord(tile()).offset(absSide);
|
||||
|
||||
/** Look for an external wire connection. */
|
||||
TileMultipart tileMultiPart = MultipartUtil.getMultipartTile(world(), pos);
|
||||
|
||||
if (tileMultiPart != null && r != -1)
|
||||
{
|
||||
TMultiPart tp = tileMultiPart.partMap(this.side);
|
||||
|
||||
if (this.canConnectTo(tp, ForgeDirection.getOrientation(absSide)))
|
||||
{
|
||||
// Check the wire we are connecting to and see if THAT block can accept this one.
|
||||
int otherR = (r + 2) % 4;
|
||||
|
||||
if (tp instanceof PartFlatWire && ((PartFlatWire) tp).canConnectTo(this, ForgeDirection.getOrientation(absSide).getOpposite()) && ((PartFlatWire) tp).maskOpen(otherR))
|
||||
{
|
||||
// We found a wire! Merge connection.
|
||||
connections()[absSide] = tp;
|
||||
//getNetwork().merge(((PartFlatWire) tp).getNetwork());
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Check for a micro-energy block */
|
||||
if (canConnectTo(tp))
|
||||
{
|
||||
connections()[absSide] = tp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
this.disconnect(absSide);
|
||||
}
|
||||
|
||||
/** Look for an external energy handler. */
|
||||
TileEntity tileEntity = world().getTileEntity(pos.x, pos.y, pos.z);
|
||||
|
||||
if (this.canConnectTo(tileEntity, ForgeDirection.getOrientation(absSide)))
|
||||
{
|
||||
this.connections()[absSide] = tileEntity;
|
||||
return true;
|
||||
}
|
||||
|
||||
this.disconnect(absSide);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private synchronized void disconnect(int i)
|
||||
{
|
||||
if (!this.world().isRemote)
|
||||
{
|
||||
if (this.connections()[i] != null)
|
||||
{
|
||||
if (this.connections()[i] instanceof PartFlatWire)
|
||||
{
|
||||
PartFlatWire wire = (PartFlatWire) this.connections()[i];
|
||||
this.connections()[i] = null;
|
||||
//this.getNetwork().split(this, wire);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.connections()[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canStay()
|
||||
{
|
||||
BlockCoord pos = new BlockCoord(tile()).offset(side);
|
||||
return MultipartUtil.canPlaceWireOnSide(world(), pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side ^ 1), false);
|
||||
}
|
||||
|
||||
public boolean dropIfCantStay()
|
||||
{
|
||||
if (!canStay())
|
||||
{
|
||||
drop();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void drop()
|
||||
{
|
||||
TileMultipart.dropItem(getItem(), world(), Vector3.fromTileEntityCenter(tile()));
|
||||
tile().remPart(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculates connections to blocks outside this space
|
||||
*
|
||||
* @return true if a new connection was added or one was removed
|
||||
*/
|
||||
protected boolean updateExternalConnections()
|
||||
{
|
||||
int newConn = 0;
|
||||
|
||||
for (int r = 0; r < 4; r++)
|
||||
{
|
||||
if (!maskOpen(r))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (connectStraight(r))
|
||||
{
|
||||
newConn |= 0x10 << r;
|
||||
}
|
||||
else
|
||||
{
|
||||
int cnrMode = connectCorner(r);
|
||||
|
||||
if (cnrMode != 0)
|
||||
{
|
||||
newConn |= 1 << r;
|
||||
|
||||
if (cnrMode == 2)
|
||||
{
|
||||
newConn |= 0x100000 << r;// render flag
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newConn != (connMap & 0xF000FF))
|
||||
{
|
||||
int diff = connMap ^ newConn;
|
||||
connMap = connMap & ~0xF000FF | newConn;
|
||||
|
||||
// Notify corner disconnections
|
||||
for (int r = 0; r < 4; r++)
|
||||
{
|
||||
if ((diff & 1 << r) != 0)
|
||||
{
|
||||
notifyCornerChange(r);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculates connections to other parts within this space
|
||||
*
|
||||
* @return true if a new connection was added or one was removed
|
||||
*/
|
||||
protected boolean updateInternalConnections()
|
||||
{
|
||||
int newConn = 0;
|
||||
for (int r = 0; r < 4; r++)
|
||||
{
|
||||
if (connectInternal(r))
|
||||
{
|
||||
newConn |= 0x100 << r;
|
||||
}
|
||||
}
|
||||
|
||||
if (connectCenter())
|
||||
{
|
||||
newConn |= 0x10000;
|
||||
}
|
||||
|
||||
if (newConn != (connMap & 0x10F00))
|
||||
{
|
||||
connMap = connMap & ~0x10F00 | newConn;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculates connections that can be made to other parts outside of this space
|
||||
*
|
||||
* @return true if external connections should be recalculated
|
||||
*/
|
||||
protected boolean updateOpenConnections()
|
||||
{
|
||||
int newConn = 0;
|
||||
for (int r = 0; r < 4; r++)
|
||||
{
|
||||
if (connectionOpen(r))
|
||||
{
|
||||
newConn |= 0x1000 << r;
|
||||
}
|
||||
}
|
||||
|
||||
if (newConn != (connMap & 0xF000))
|
||||
{
|
||||
connMap = connMap & ~0xF000 | newConn;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean connectionOpen(int r)
|
||||
{
|
||||
int absDir = Rotation.rotateSide(side, r);
|
||||
TMultiPart facePart = tile().partMap(absDir);
|
||||
if (facePart != null && (!(facePart instanceof PartFlatWire) || !canConnectTo(facePart, ForgeDirection.getOrientation(absDir))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tile().partMap(PartMap.edgeBetween(side, absDir)) != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a corner connection state. 0 = No connection 1 = Physical connection 2 = Render
|
||||
* connection
|
||||
*/
|
||||
public int connectCorner(int r)
|
||||
{
|
||||
int absDir = Rotation.rotateSide(side, r);
|
||||
|
||||
BlockCoord pos = new BlockCoord(tile());
|
||||
pos.offset(absDir);
|
||||
|
||||
if (!canConnectThroughCorner(pos, absDir ^ 1, side))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pos.offset(side);
|
||||
TileMultipart t = MultipartUtil.getMultipartTile(world(), pos);
|
||||
if (t != null)
|
||||
{
|
||||
TMultiPart tp = t.partMap(absDir ^ 1);
|
||||
|
||||
if (canConnectTo(tp, ForgeDirection.getOrientation(absDir)))
|
||||
{
|
||||
if (tp instanceof PartFlatWire)
|
||||
{
|
||||
boolean b = ((PartFlatWire) tp).connectCorner(this, Rotation.rotationTo(absDir ^ 1, side ^ 1));
|
||||
|
||||
if (b)
|
||||
{
|
||||
// let them connect to us
|
||||
if (!renderThisCorner((PartFlatWire) tp))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean canConnectThroughCorner(BlockCoord pos, int side1, int side2)
|
||||
{
|
||||
if (world().isAirBlock(pos.x, pos.y, pos.z))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
TileMultipart t = MultipartUtil.getMultipartTile(world(), pos);
|
||||
if (t != null)
|
||||
{
|
||||
return t.partMap(side1) == null && t.partMap(side2) == null && t.partMap(PartMap.edgeBetween(side1, side2)) == null;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean connectStraight(int r)
|
||||
{
|
||||
int absDir = Rotation.rotateSide(side, r);
|
||||
|
||||
BlockCoord pos = new BlockCoord(tile()).offset(absDir);
|
||||
|
||||
TileMultipart t = MultipartUtil.getMultipartTile(world(), pos);
|
||||
if (t != null)
|
||||
{
|
||||
TMultiPart tp = t.partMap(side);
|
||||
|
||||
if (this.canConnectTo(tp, ForgeDirection.getOrientation(absDir)))
|
||||
{
|
||||
if (tp instanceof PartFlatWire)
|
||||
{
|
||||
return ((PartFlatWire) tp).connectStraight(this, (r + 2) % 4);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TileEntity tileEntity = world().getTileEntity(pos.x, pos.y, pos.z);
|
||||
return this.canConnectTo(tileEntity, ForgeDirection.getOrientation(absDir));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean connectInternal(int r)
|
||||
{
|
||||
int absDir = Rotation.rotateSide(side, r);
|
||||
|
||||
if (tile().partMap(PartMap.edgeBetween(absDir, side)) != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TMultiPart tp = tile().partMap(absDir);
|
||||
|
||||
if (this.canConnectTo(tp, ForgeDirection.getOrientation(absDir)))
|
||||
{
|
||||
return ((PartFlatWire) tp).connectInternal(this, Rotation.rotationTo(absDir, side));
|
||||
}
|
||||
|
||||
return connectInternalOverride(tp, r);
|
||||
}
|
||||
|
||||
public boolean connectInternalOverride(TMultiPart p, int r)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean connectCenter()
|
||||
{
|
||||
TMultiPart tp = tile().partMap(6);
|
||||
|
||||
if (this.canConnectTo(tp))
|
||||
{
|
||||
if (tp instanceof PartFlatWire)
|
||||
{
|
||||
return ((PartFlatWire) tp).connectInternal(this, side);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean renderThisCorner(PartFlatWire part)
|
||||
{
|
||||
if (!(part instanceof PartFlatWire))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
PartFlatWire wire = part;
|
||||
if (wire.getThickness() == getThickness())
|
||||
{
|
||||
return side < wire.side;
|
||||
}
|
||||
|
||||
return wire.getThickness() > getThickness();
|
||||
}
|
||||
|
||||
public boolean connectCorner(PartFlatWire wire, int r)
|
||||
{
|
||||
int absDir = Rotation.rotateSide(side, r);
|
||||
|
||||
if (this.canConnectTo(wire, ForgeDirection.getOrientation(absDir)) && maskOpen(r))
|
||||
{
|
||||
int oldConn = connMap;
|
||||
connMap |= 0x1 << r;
|
||||
if (renderThisCorner(wire))// render connection
|
||||
{
|
||||
connMap |= 0x100000 << r;
|
||||
}
|
||||
|
||||
if (oldConn != connMap)
|
||||
{
|
||||
sendConnUpdate();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean connectStraight(PartFlatWire wire, int r)
|
||||
{
|
||||
int absDir = Rotation.rotateSide(side, r);
|
||||
|
||||
if (this.canConnectTo(wire, ForgeDirection.getOrientation(absDir)) && maskOpen(r))
|
||||
{
|
||||
int oldConn = connMap;
|
||||
connMap |= 0x10 << r;
|
||||
if (oldConn != connMap)
|
||||
{
|
||||
sendConnUpdate();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean connectInternal(PartFlatWire wire, int r)
|
||||
{
|
||||
int absDir = Rotation.rotateSide(side, r);
|
||||
|
||||
if (this.canConnectTo(wire, ForgeDirection.getOrientation(absDir)))
|
||||
{
|
||||
int oldConn = connMap;
|
||||
connMap |= 0x100 << r;
|
||||
if (oldConn != connMap)
|
||||
{
|
||||
sendConnUpdate();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canConnectCorner(int r)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void notifyCornerChange(int r)
|
||||
{
|
||||
int absDir = Rotation.rotateSide(side, r);
|
||||
|
||||
BlockCoord pos = new BlockCoord(tile()).offset(absDir).offset(side);
|
||||
world().notifyBlockOfNeighborChange(pos.x, pos.y, pos.z, tile().getBlockType());
|
||||
}
|
||||
|
||||
public void notifyStraightChange(int r)
|
||||
{
|
||||
int absDir = Rotation.rotateSide(side, r);
|
||||
|
||||
BlockCoord pos = new BlockCoord(tile()).offset(absDir);
|
||||
world().notifyBlockOfNeighborChange(pos.x, pos.y, pos.z, tile().getBlockType());
|
||||
}
|
||||
|
||||
public boolean maskConnects(int r)
|
||||
{
|
||||
return (connMap & 0x111 << r) != 0;
|
||||
}
|
||||
|
||||
public boolean maskOpen(int r)
|
||||
{
|
||||
return (connMap & 0x1000 << r) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* START TILEMULTIPART INTERACTIONS *
|
||||
*/
|
||||
@Override
|
||||
public float getStrength(MovingObjectPosition hit, EntityPlayer player)
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotMask()
|
||||
{
|
||||
return 1 << this.side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<IndexedCuboid6> getSubParts()
|
||||
{
|
||||
return Arrays.asList(new IndexedCuboid6(0, selectionBounds[getThickness()][side]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean occlusionTest(TMultiPart npart)
|
||||
{
|
||||
return NormalOcclusionTest.apply(this, npart);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Cuboid6> getOcclusionBoxes()
|
||||
{
|
||||
return Arrays.asList(occlusionBounds[getThickness()][side]);
|
||||
}
|
||||
|
||||
public int getThickness()
|
||||
{
|
||||
return insulated ? 2 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int redstoneConductionMap()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean solid(int arg0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
{
|
||||
return "resonant_induction_flat_wire";
|
||||
}
|
||||
|
||||
/**
|
||||
* RENDERING
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon()
|
||||
{
|
||||
return RenderFlatWire$.MODULE$.flatWireTexture();
|
||||
}
|
||||
|
||||
public Colour getColour()
|
||||
{
|
||||
if (isInsulated)
|
||||
{
|
||||
Colour color = new ColourARGB(ItemDye.field_150922_c[this.color]);
|
||||
color.a = (byte) 255;
|
||||
return color;
|
||||
}
|
||||
|
||||
return getMaterial().color;
|
||||
}
|
||||
|
||||
public boolean useStaticRenderer()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean renderStatic(Vector3 pos, int pass)
|
||||
{
|
||||
if (pass == 0 && useStaticRenderer())
|
||||
{
|
||||
CCRenderState.setBrightness(world(), x(), y(), z());
|
||||
RenderFlatWire.render(this, pos);
|
||||
CCRenderState.setColour(-1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderDynamic(Vector3 pos, float frame, int pass)
|
||||
{
|
||||
if (pass == 0 && !useStaticRenderer())
|
||||
{
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
TextureUtils.bindAtlas(0);
|
||||
//CCRenderState.useModelColours(true);
|
||||
CCRenderState.startDrawing(7);
|
||||
RenderFlatWire.render(this, pos);
|
||||
CCRenderState.draw();
|
||||
CCRenderState.setColour(-1);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void drawBreaking(RenderBlocks renderBlocks)
|
||||
{
|
||||
CCRenderState.reset();
|
||||
RenderFlatWire.renderBreakingOverlay(renderBlocks.overrideBlockTexture, this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,797 @@
|
|||
package resonantinduction.electrical.wire.flat
|
||||
|
||||
import java.lang.{Iterable => JIterable}
|
||||
|
||||
import codechicken.lib.colour.{Colour, ColourARGB}
|
||||
import codechicken.lib.data.{MCDataInput, MCDataOutput}
|
||||
import codechicken.lib.raytracer.IndexedCuboid6
|
||||
import codechicken.lib.render.{CCRenderState, TextureUtils}
|
||||
import codechicken.lib.vec.{BlockCoord, Cuboid6, Rotation, Vector3}
|
||||
import codechicken.multipart._
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.minecraft.client.renderer.RenderBlocks
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemDye
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.util.{IIcon, MovingObjectPosition}
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import org.lwjgl.opengl.GL11
|
||||
import resonantinduction.core.util.MultipartUtil
|
||||
import resonantinduction.electrical.wire.base.TWire
|
||||
|
||||
import scala.collection.convert.wrapAll._
|
||||
|
||||
/**
|
||||
* This is the class for all flat wire types. It can be used for any sub type, as it contains the
|
||||
* base calculations necessary to create a working wire. This calculates all possible connections to
|
||||
* sides, around corners, and inside corners, while checking for microblock obstructions.
|
||||
*
|
||||
* @author Calclavia, MrTJP
|
||||
*/
|
||||
object PartFlatWire
|
||||
{
|
||||
var selectionBounds = Array.ofDim[Cuboid6](3, 6)
|
||||
var occlusionBounds = Array.ofDim[Cuboid6](3, 6)
|
||||
|
||||
for (t <- 0 until 3)
|
||||
{
|
||||
lazy val selection: Cuboid6 = new Cuboid6(0, 0, 0, 1, (t + 2) / 16D, 1).expand(-0.005)
|
||||
lazy val occlusion: Cuboid6 = new Cuboid6(2 / 8D, 0, 2 / 8D, 6 / 8D, (t + 2) / 16D, 6 / 8D)
|
||||
{
|
||||
for (s <- 0 until 6)
|
||||
{
|
||||
selectionBounds(t)(s) = selection.copy.apply(Rotation.sideRotations(s).at(Vector3.center))
|
||||
occlusionBounds(t)(s) = occlusion.copy.apply(Rotation.sideRotations(s).at(Vector3.center))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PartFlatWire extends TWire with TFacePart with TNormalOcclusion
|
||||
{
|
||||
var side: Byte = 0
|
||||
/**
|
||||
* A map of the corners.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Currently split into 4 nybbles (from lowest) 0 = Corner connections (this wire should connect
|
||||
* around a corner to something external) 1 = Straight connections (this wire should connect to
|
||||
* something external) 2 = Internal connections (this wire should connect to something internal)
|
||||
* 3 = Internal open connections (this wire is not blocked by a cover/edge part and *could*
|
||||
* connect through side) bit 16 = connection to the centerpart 5 = Render corner connections.
|
||||
* Like corner connections but set to low if the other wire part is smaller than this (they
|
||||
* render to us not us to them)
|
||||
*/
|
||||
var connMap: Int = 0x00
|
||||
|
||||
def connections: Array[AnyRef] =
|
||||
{
|
||||
return null
|
||||
}
|
||||
|
||||
def preparePlacement(side: Int, meta: Int)
|
||||
{
|
||||
this.side = (side ^ 1).asInstanceOf[Byte]
|
||||
setMaterial(meta)
|
||||
}
|
||||
|
||||
/**
|
||||
* PACKET and NBT Methods
|
||||
*/
|
||||
override def load(tag: NBTTagCompound)
|
||||
{
|
||||
super.load(tag)
|
||||
this.side = tag.getByte("side")
|
||||
this.connMap = tag.getInteger("connMap")
|
||||
}
|
||||
|
||||
override def save(tag: NBTTagCompound)
|
||||
{
|
||||
super.save(tag)
|
||||
tag.setByte("side", this.side)
|
||||
tag.setInteger("connMap", this.connMap)
|
||||
}
|
||||
|
||||
override def readDesc(packet: MCDataInput)
|
||||
{
|
||||
super.readDesc(packet)
|
||||
side = packet.readByte
|
||||
connMap = packet.readInt
|
||||
}
|
||||
|
||||
override def writeDesc(packet: MCDataOutput)
|
||||
{
|
||||
super.writeDesc(packet)
|
||||
packet.writeByte(side)
|
||||
packet.writeInt(connMap)
|
||||
}
|
||||
|
||||
override def read(packet: MCDataInput)
|
||||
{
|
||||
read(packet, packet.readUByte)
|
||||
}
|
||||
|
||||
override def read(packet: MCDataInput, packetID: Int)
|
||||
{
|
||||
if (packetID == 0)
|
||||
{
|
||||
connMap = packet.readInt
|
||||
tile.markRender
|
||||
}
|
||||
else
|
||||
{
|
||||
super.read(packet, packetID)
|
||||
}
|
||||
}
|
||||
|
||||
def sendConnUpdate
|
||||
{
|
||||
tile.getWriteStream(this).writeByte(0).writeInt(this.connMap)
|
||||
}
|
||||
|
||||
override def onRemoved
|
||||
{
|
||||
super.onRemoved
|
||||
if (!world.isRemote)
|
||||
{
|
||||
{
|
||||
var r: Int = 0
|
||||
while (r < 4)
|
||||
{
|
||||
{
|
||||
if (maskConnects(r))
|
||||
{
|
||||
if ((connMap & 1 << r) != 0)
|
||||
{
|
||||
notifyCornerChange(r)
|
||||
}
|
||||
else if ((connMap & 0x10 << r) != 0)
|
||||
{
|
||||
notifyStraightChange(r)
|
||||
}
|
||||
}
|
||||
}
|
||||
({r += 1; r - 1 })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def onChunkLoad
|
||||
{
|
||||
if ((connMap & 0x80000000) != 0)
|
||||
{
|
||||
if (dropIfCantStay)
|
||||
{
|
||||
return
|
||||
}
|
||||
connMap = 0
|
||||
updateInternalConnections
|
||||
if (updateOpenConnections)
|
||||
{
|
||||
updateExternalConnections
|
||||
}
|
||||
tile.markDirty
|
||||
}
|
||||
this.recalculateConnections
|
||||
super.onChunkLoad
|
||||
}
|
||||
|
||||
override def onAdded
|
||||
{
|
||||
super.onAdded
|
||||
if (!world.isRemote)
|
||||
{
|
||||
updateOpenConnections
|
||||
var changed: Boolean = updateInternalConnections
|
||||
changed |= updateExternalConnections
|
||||
if (changed)
|
||||
{
|
||||
sendConnUpdate
|
||||
}
|
||||
this.recalculateConnections
|
||||
}
|
||||
}
|
||||
|
||||
override def onPartChanged(part: TMultiPart)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
var changed: Boolean = updateInternalConnections
|
||||
if (updateOpenConnections)
|
||||
{
|
||||
changed |= updateExternalConnections
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
sendConnUpdate
|
||||
}
|
||||
this.recalculateConnections
|
||||
}
|
||||
super.onPartChanged(part)
|
||||
}
|
||||
|
||||
override def onNeighborChanged
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
if (dropIfCantStay)
|
||||
{
|
||||
return
|
||||
}
|
||||
if (updateExternalConnections)
|
||||
{
|
||||
sendConnUpdate
|
||||
}
|
||||
this.recalculateConnections
|
||||
}
|
||||
super.onNeighborChanged
|
||||
}
|
||||
|
||||
def recalculateConnections()
|
||||
{
|
||||
updateOpenConnections
|
||||
val calculatedSides: Array[Boolean] = Array.ofDim[Boolean](6)
|
||||
|
||||
for (r <- 0 until 4)
|
||||
{
|
||||
if (maskOpen(r))
|
||||
{
|
||||
var skip = false
|
||||
val absDir: Int = Rotation.rotateSide(side, r)
|
||||
|
||||
if (setExternalConnection(r, absDir))
|
||||
{
|
||||
calculatedSides(absDir) = true
|
||||
}
|
||||
|
||||
val cornerPos: BlockCoord = new BlockCoord(tile)
|
||||
cornerPos.offset(absDir)
|
||||
|
||||
if (canConnectThroughCorner(cornerPos, absDir ^ 1, side))
|
||||
{
|
||||
cornerPos.offset(side)
|
||||
val tpCorner: TileMultipart = MultipartUtil.getMultipartTile(world, cornerPos)
|
||||
if (tpCorner != null)
|
||||
{
|
||||
val tp: TMultiPart = tpCorner.partMap(absDir ^ 1)
|
||||
|
||||
if (canConnectTo(tp, ForgeDirection.getOrientation(absDir)))
|
||||
{
|
||||
connections(absDir) = tp
|
||||
/*
|
||||
if (tp.isInstanceOf[PartFlatWire])
|
||||
{
|
||||
}
|
||||
*/
|
||||
calculatedSides(absDir) = true
|
||||
skip = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!calculatedSides(absDir) && !skip)
|
||||
{
|
||||
disconnect(absDir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (r <- 0 until 4)
|
||||
{
|
||||
var skip = false
|
||||
|
||||
val absDir: Int = Rotation.rotateSide(this.side, r)
|
||||
if (tile.partMap(PartMap.edgeBetween(absDir, this.side)) == null)
|
||||
{
|
||||
val tp: TMultiPart = tile.partMap(absDir)
|
||||
if (this.canConnectTo(tp))
|
||||
{
|
||||
this.connections(absDir) = tp
|
||||
/*
|
||||
if (tp.isInstanceOf[PartFlatWire])
|
||||
{
|
||||
}*/
|
||||
|
||||
skip = true
|
||||
}
|
||||
}
|
||||
if (!calculatedSides(absDir) && !skip)
|
||||
{
|
||||
disconnect(absDir)
|
||||
}
|
||||
}
|
||||
|
||||
setExternalConnection(-1, this.side)
|
||||
}
|
||||
|
||||
def setExternalConnection(r: Int, absSide: Int): Boolean =
|
||||
{
|
||||
val pos: BlockCoord = new BlockCoord(tile).offset(absSide)
|
||||
val tileMultiPart: TileMultipart = MultipartUtil.getMultipartTile(world, pos)
|
||||
if (tileMultiPart != null && r != -1)
|
||||
{
|
||||
val tp: TMultiPart = tileMultiPart.partMap(this.side)
|
||||
if (this.canConnectTo(tp, ForgeDirection.getOrientation(absSide)))
|
||||
{
|
||||
val otherR: Int = (r + 2) % 4
|
||||
if (tp.isInstanceOf[PartFlatWire] && (tp.asInstanceOf[PartFlatWire]).canConnectTo(this, ForgeDirection.getOrientation(absSide).getOpposite) && (tp.asInstanceOf[PartFlatWire]).maskOpen(otherR))
|
||||
{
|
||||
connections(absSide) = tp
|
||||
return true
|
||||
}
|
||||
if (canConnectTo(tp))
|
||||
{
|
||||
connections(absSide) = tp
|
||||
return true
|
||||
}
|
||||
}
|
||||
this.disconnect(absSide)
|
||||
}
|
||||
val tileEntity: TileEntity = world.getTileEntity(pos.x, pos.y, pos.z)
|
||||
if (this.canConnectTo(tileEntity, ForgeDirection.getOrientation(absSide)))
|
||||
{
|
||||
this.connections(absSide) = tileEntity
|
||||
return true
|
||||
}
|
||||
this.disconnect(absSide)
|
||||
return false
|
||||
}
|
||||
|
||||
private def disconnect(i: Int)
|
||||
{
|
||||
if (!this.world.isRemote)
|
||||
{
|
||||
if (this.connections(i) != null)
|
||||
{
|
||||
if (this.connections(i).isInstanceOf[PartFlatWire])
|
||||
{
|
||||
val wire: PartFlatWire = this.connections(i).asInstanceOf[PartFlatWire]
|
||||
this.connections(i) = null
|
||||
}
|
||||
else
|
||||
{
|
||||
this.connections(i) = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def canStay: Boolean =
|
||||
{
|
||||
val pos: BlockCoord = new BlockCoord(tile).offset(side)
|
||||
return MultipartUtil.canPlaceWireOnSide(world, pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side ^ 1), false)
|
||||
}
|
||||
|
||||
def dropIfCantStay: Boolean =
|
||||
{
|
||||
if (!canStay)
|
||||
{
|
||||
drop
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
def drop
|
||||
{
|
||||
TileMultipart.dropItem(getItem, world, Vector3.fromTileEntityCenter(tile))
|
||||
tile.remPart(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculates connections to blocks outside this space
|
||||
*
|
||||
* @return true if a new connection was added or one was removed
|
||||
*/
|
||||
protected def updateExternalConnections: Boolean =
|
||||
{
|
||||
var newConn: Int = 0
|
||||
|
||||
for (r <- 0 until 4)
|
||||
{
|
||||
if (maskOpen(r))
|
||||
{
|
||||
|
||||
if (connectStraight(r))
|
||||
{
|
||||
newConn |= 0x10 << r
|
||||
}
|
||||
else
|
||||
{
|
||||
val cnrMode: Int = connectCorner(r)
|
||||
if (cnrMode != 0)
|
||||
{
|
||||
newConn |= 1 << r
|
||||
if (cnrMode == 2)
|
||||
{
|
||||
newConn |= 0x100000 << r
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newConn != (connMap & 0xF000FF))
|
||||
{
|
||||
val diff: Int = connMap ^ newConn
|
||||
connMap = connMap & ~0xF000FF | newConn
|
||||
|
||||
for (r <- 0 until 4)
|
||||
{
|
||||
if ((diff & 1 << r) != 0)
|
||||
{
|
||||
notifyCornerChange(r)
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculates connections to other parts within this space
|
||||
*
|
||||
* @return true if a new connection was added or one was removed
|
||||
*/
|
||||
protected def updateInternalConnections: Boolean =
|
||||
{
|
||||
var newConn: Int = 0
|
||||
|
||||
for (r <- 0 until 4)
|
||||
{
|
||||
if (connectInternal(r))
|
||||
{
|
||||
newConn |= 0x100 << r
|
||||
}
|
||||
}
|
||||
|
||||
if (connectCenter)
|
||||
{
|
||||
newConn |= 0x10000
|
||||
}
|
||||
if (newConn != (connMap & 0x10F00))
|
||||
{
|
||||
connMap = connMap & ~0x10F00 | newConn
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculates connections that can be made to other parts outside of this space
|
||||
*
|
||||
* @return true if external connections should be recalculated
|
||||
*/
|
||||
protected def updateOpenConnections: Boolean =
|
||||
{
|
||||
var newConn: Int = 0
|
||||
|
||||
for (r <- 0 until 4)
|
||||
{
|
||||
if (connectionOpen(r))
|
||||
{
|
||||
newConn |= 0x1000 << r
|
||||
}
|
||||
}
|
||||
|
||||
if (newConn != (connMap & 0xF000))
|
||||
{
|
||||
connMap = connMap & ~0xF000 | newConn
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
def connectionOpen(r: Int): Boolean =
|
||||
{
|
||||
val absDir: Int = Rotation.rotateSide(side, r)
|
||||
val facePart: TMultiPart = tile.partMap(absDir)
|
||||
if (facePart != null && (!(facePart.isInstanceOf[PartFlatWire]) || !canConnectTo(facePart, ForgeDirection.getOrientation(absDir))))
|
||||
{
|
||||
return false
|
||||
}
|
||||
if (tile.partMap(PartMap.edgeBetween(side, absDir)) != null)
|
||||
{
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a corner connection state. 0 = No connection 1 = Physical connection 2 = Render
|
||||
* connection
|
||||
*/
|
||||
def connectCorner(r: Int): Int =
|
||||
{
|
||||
val absDir: Int = Rotation.rotateSide(side, r)
|
||||
val pos: BlockCoord = new BlockCoord(tile)
|
||||
pos.offset(absDir)
|
||||
if (!canConnectThroughCorner(pos, absDir ^ 1, side))
|
||||
{
|
||||
return 0
|
||||
}
|
||||
pos.offset(side)
|
||||
val t: TileMultipart = MultipartUtil.getMultipartTile(world, pos)
|
||||
if (t != null)
|
||||
{
|
||||
val tp: TMultiPart = t.partMap(absDir ^ 1)
|
||||
if (canConnectTo(tp, ForgeDirection.getOrientation(absDir)))
|
||||
{
|
||||
if (tp.isInstanceOf[PartFlatWire])
|
||||
{
|
||||
val b: Boolean = (tp.asInstanceOf[PartFlatWire]).connectCorner(this, Rotation.rotationTo(absDir ^ 1, side ^ 1))
|
||||
if (b)
|
||||
{
|
||||
if (!renderThisCorner(tp.asInstanceOf[PartFlatWire]))
|
||||
{
|
||||
return 1
|
||||
}
|
||||
return 2
|
||||
}
|
||||
}
|
||||
return 2
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
def canConnectThroughCorner(pos: BlockCoord, side1: Int, side2: Int): Boolean =
|
||||
{
|
||||
if (world.isAirBlock(pos.x, pos.y, pos.z))
|
||||
{
|
||||
return true
|
||||
}
|
||||
val t: TileMultipart = MultipartUtil.getMultipartTile(world, pos)
|
||||
if (t != null)
|
||||
{
|
||||
return t.partMap(side1) == null && t.partMap(side2) == null && t.partMap(PartMap.edgeBetween(side1, side2)) == null
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
def connectStraight(r: Int): Boolean =
|
||||
{
|
||||
val absDir: Int = Rotation.rotateSide(side, r)
|
||||
val pos: BlockCoord = new BlockCoord(tile).offset(absDir)
|
||||
val t: TileMultipart = MultipartUtil.getMultipartTile(world, pos)
|
||||
if (t != null)
|
||||
{
|
||||
val tp: TMultiPart = t.partMap(side)
|
||||
if (this.canConnectTo(tp, ForgeDirection.getOrientation(absDir)))
|
||||
{
|
||||
if (tp.isInstanceOf[PartFlatWire])
|
||||
{
|
||||
return (tp.asInstanceOf[PartFlatWire]).connectStraight(this, (r + 2) % 4)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
val tileEntity: TileEntity = world.getTileEntity(pos.x, pos.y, pos.z)
|
||||
return this.canConnectTo(tileEntity, ForgeDirection.getOrientation(absDir))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
def connectInternal(r: Int): Boolean =
|
||||
{
|
||||
val absDir: Int = Rotation.rotateSide(side, r)
|
||||
if (tile.partMap(PartMap.edgeBetween(absDir, side)) != null)
|
||||
{
|
||||
return false
|
||||
}
|
||||
val tp: TMultiPart = tile.partMap(absDir)
|
||||
if (this.canConnectTo(tp, ForgeDirection.getOrientation(absDir)))
|
||||
{
|
||||
return (tp.asInstanceOf[PartFlatWire]).connectInternal(this, Rotation.rotationTo(absDir, side))
|
||||
}
|
||||
return connectInternalOverride(tp, r)
|
||||
}
|
||||
|
||||
def connectInternalOverride(p: TMultiPart, r: Int): Boolean =
|
||||
{
|
||||
return false
|
||||
}
|
||||
|
||||
def connectCenter: Boolean =
|
||||
{
|
||||
val tp: TMultiPart = tile.partMap(6)
|
||||
if (this.canConnectTo(tp))
|
||||
{
|
||||
if (tp.isInstanceOf[PartFlatWire])
|
||||
{
|
||||
return (tp.asInstanceOf[PartFlatWire]).connectInternal(this, side)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
def renderThisCorner(part: PartFlatWire): Boolean =
|
||||
{
|
||||
if (!(part.isInstanceOf[PartFlatWire]))
|
||||
{
|
||||
return false
|
||||
}
|
||||
val wire: PartFlatWire = part
|
||||
if (wire.getThickness == getThickness)
|
||||
{
|
||||
return side < wire.side
|
||||
}
|
||||
return wire.getThickness > getThickness
|
||||
}
|
||||
|
||||
def connectCorner(wire: PartFlatWire, r: Int): Boolean =
|
||||
{
|
||||
val absDir: Int = Rotation.rotateSide(side, r)
|
||||
if (this.canConnectTo(wire, ForgeDirection.getOrientation(absDir)) && maskOpen(r))
|
||||
{
|
||||
val oldConn: Int = connMap
|
||||
connMap |= 0x1 << r
|
||||
if (renderThisCorner(wire))
|
||||
{
|
||||
connMap |= 0x100000 << r
|
||||
}
|
||||
if (oldConn != connMap)
|
||||
{
|
||||
sendConnUpdate
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
def connectStraight(wire: PartFlatWire, r: Int): Boolean =
|
||||
{
|
||||
val absDir: Int = Rotation.rotateSide(side, r)
|
||||
if (this.canConnectTo(wire, ForgeDirection.getOrientation(absDir)) && maskOpen(r))
|
||||
{
|
||||
val oldConn: Int = connMap
|
||||
connMap |= 0x10 << r
|
||||
if (oldConn != connMap)
|
||||
{
|
||||
sendConnUpdate
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
def connectInternal(wire: PartFlatWire, r: Int): Boolean =
|
||||
{
|
||||
val absDir: Int = Rotation.rotateSide(side, r)
|
||||
if (this.canConnectTo(wire, ForgeDirection.getOrientation(absDir)))
|
||||
{
|
||||
val oldConn: Int = connMap
|
||||
connMap |= 0x100 << r
|
||||
if (oldConn != connMap)
|
||||
{
|
||||
sendConnUpdate
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
def canConnectCorner(r: Int): Boolean =
|
||||
{
|
||||
return true
|
||||
}
|
||||
|
||||
def notifyCornerChange(r: Int)
|
||||
{
|
||||
val absDir: Int = Rotation.rotateSide(side, r)
|
||||
val pos: BlockCoord = new BlockCoord(tile).offset(absDir).offset(side)
|
||||
world.notifyBlockOfNeighborChange(pos.x, pos.y, pos.z, tile.getBlockType)
|
||||
}
|
||||
|
||||
def notifyStraightChange(r: Int)
|
||||
{
|
||||
val absDir: Int = Rotation.rotateSide(side, r)
|
||||
val pos: BlockCoord = new BlockCoord(tile).offset(absDir)
|
||||
world.notifyBlockOfNeighborChange(pos.x, pos.y, pos.z, tile.getBlockType)
|
||||
}
|
||||
|
||||
def maskConnects(r: Int): Boolean =
|
||||
{
|
||||
return (connMap & 0x111 << r) != 0
|
||||
}
|
||||
|
||||
def maskOpen(r: Int): Boolean =
|
||||
{
|
||||
return (connMap & 0x1000 << r) != 0
|
||||
}
|
||||
|
||||
/**
|
||||
* START TILEMULTIPART INTERACTIONS *
|
||||
*/
|
||||
override def getStrength(hit: MovingObjectPosition, player: EntityPlayer): Float =
|
||||
{
|
||||
return 4
|
||||
}
|
||||
|
||||
def getSlotMask: Int =
|
||||
{
|
||||
return 1 << this.side
|
||||
}
|
||||
|
||||
override def getSubParts: JIterable[IndexedCuboid6] = Seq(new IndexedCuboid6(0, PartFlatWire.selectionBounds(getThickness)(side)))
|
||||
|
||||
def getOcclusionBoxes: JIterable[Cuboid6] = Seq(PartFlatWire.occlusionBounds(getThickness)(side))
|
||||
|
||||
def getThickness: Int =
|
||||
{
|
||||
return if (insulated) 2 else 1
|
||||
}
|
||||
|
||||
override def solid(arg0: Int) = false
|
||||
|
||||
def getType: String = "resonant_induction_flat_wire"
|
||||
|
||||
/**
|
||||
* RENDERING
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
def getIcon: IIcon =
|
||||
{
|
||||
return RenderFlatWire.flatWireTexture
|
||||
}
|
||||
|
||||
def getColour: Colour =
|
||||
{
|
||||
if (insulated)
|
||||
{
|
||||
val color: Colour = new ColourARGB(ItemDye.field_150922_c(colorID))
|
||||
color.a = 255.asInstanceOf[Byte]
|
||||
return color
|
||||
}
|
||||
|
||||
return new ColourARGB(material.color)
|
||||
}
|
||||
|
||||
def useStaticRenderer: Boolean =
|
||||
{
|
||||
return true
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def renderStatic(pos: Vector3, pass: Int): Boolean =
|
||||
{
|
||||
if (pass == 0 && useStaticRenderer)
|
||||
{
|
||||
CCRenderState.setBrightness(world, x, y, z)
|
||||
RenderFlatWire.render(this, pos)
|
||||
CCRenderState.setColour(-1)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
|
||||
{
|
||||
if (pass == 0 && !useStaticRenderer)
|
||||
{
|
||||
GL11.glDisable(GL11.GL_LIGHTING)
|
||||
TextureUtils.bindAtlas(0)
|
||||
CCRenderState.startDrawing(7)
|
||||
RenderFlatWire.render(this, pos)
|
||||
CCRenderState.draw
|
||||
CCRenderState.setColour(-1)
|
||||
GL11.glEnable(GL11.GL_LIGHTING)
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def drawBreaking(renderBlocks: RenderBlocks)
|
||||
{
|
||||
CCRenderState.reset
|
||||
RenderFlatWire.renderBreakingOverlay(renderBlocks.overrideBlockTexture, this)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue