Fixed gear shaft external connections

This commit is contained in:
Calclavia 2014-01-28 14:29:48 +08:00
parent 05b903f07b
commit ef4322338e
5 changed files with 27 additions and 22 deletions

View file

@ -155,7 +155,7 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
{ {
IMechanical instance = ((IMechanical) tileBehind).getInstance(placementSide.getOpposite()); IMechanical instance = ((IMechanical) tileBehind).getInstance(placementSide.getOpposite());
if (instance != null && instance.canConnect(placementSide, this)) if (instance != null && instance != this && instance.canConnect(placementSide, this))
{ {
connections[placementSide.getOpposite().ordinal()] = instance; connections[placementSide.getOpposite().ordinal()] = instance;
getNetwork().merge(instance.getNetwork()); getNetwork().merge(instance.getNetwork());
@ -178,7 +178,7 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
IMechanical instance = ((IMechanical) tile()).getInstance(checkDir == placementSide.getOpposite() ? ForgeDirection.UNKNOWN : checkDir); IMechanical instance = ((IMechanical) tile()).getInstance(checkDir == placementSide.getOpposite() ? ForgeDirection.UNKNOWN : checkDir);
if (connections[checkDir.ordinal()] == null && checkDir != placementSide && instance != null && instance.canConnect(checkDir.getOpposite(), this)) if (connections[checkDir.ordinal()] == null && instance != this && checkDir != placementSide && instance != null && instance.canConnect(checkDir.getOpposite(), this))
{ {
connections[checkDir.ordinal()] = instance; connections[checkDir.ordinal()] = instance;
getNetwork().merge(instance.getNetwork()); getNetwork().merge(instance.getNetwork());
@ -203,7 +203,7 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
{ {
IMechanical instance = (IMechanical) ((IMechanical) checkTile).getInstance(placementSide); IMechanical instance = (IMechanical) ((IMechanical) checkTile).getInstance(placementSide);
if (instance != null && instance.canConnect(checkDir.getOpposite(), this)) if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite(), this))
{ {
connections[checkDir.ordinal()] = instance; connections[checkDir.ordinal()] = instance;
getNetwork().merge(instance.getNetwork()); getNetwork().merge(instance.getNetwork());

View file

@ -37,6 +37,12 @@ public class PartGearShaft extends PartMechanical
sides[6] = new IndexedCuboid6(6, new Cuboid6(0.36, 0.36, 0.36, 0.64, 0.64, 0.64)); sides[6] = new IndexedCuboid6(6, new Cuboid6(0.36, 0.36, 0.36, 0.64, 0.64, 0.64));
} }
public void preparePlacement(int side, int itemDamage)
{
ForgeDirection dir = ForgeDirection.getOrientation((byte) (side ^ 1));
this.placementSide = ForgeDirection.getOrientation(!(dir.ordinal() % 2 == 0) ? dir.ordinal() - 1 : dir.ordinal());
}
@Override @Override
public void update() public void update()
{ {
@ -65,9 +71,8 @@ public class PartGearShaft extends PartMechanical
if (checkDir == placementSide || checkDir == placementSide.getOpposite()) if (checkDir == placementSide || checkDir == placementSide.getOpposite())
{ {
IMechanical instance = ((IMechanical) tile()).getInstance(checkDir); IMechanical instance = ((IMechanical) tile()).getInstance(checkDir);
System.out.println("FOUND POSSIBLE CHECK"+instance);
if (instance != null && instance.canConnect(checkDir.getOpposite(), this)) if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite(), this))
{ {
connections[checkDir.ordinal()] = instance; connections[checkDir.ordinal()] = instance;
getNetwork().merge(instance.getNetwork()); getNetwork().merge(instance.getNetwork());
@ -76,9 +81,9 @@ public class PartGearShaft extends PartMechanical
} }
/** Look for connections outside this block space, the relative FRONT and BACK */ /** Look for connections outside this block space, the relative FRONT and BACK */
for (int i = 0; i < 4; i++) for (int i = 0; i < 6; i++)
{ {
ForgeDirection checkDir = ForgeDirection.getOrientation(Rotation.rotateSide(this.placementSide.ordinal(), i)); ForgeDirection checkDir = ForgeDirection.getOrientation(i);
if (connections[checkDir.ordinal()] == null && (checkDir == placementSide || checkDir == placementSide.getOpposite())) if (connections[checkDir.ordinal()] == null && (checkDir == placementSide || checkDir == placementSide.getOpposite()))
{ {
@ -86,9 +91,9 @@ public class PartGearShaft extends PartMechanical
if (checkTile instanceof IMechanical) if (checkTile instanceof IMechanical)
{ {
IMechanical instance = (IMechanical) ((IMechanical) checkTile).getInstance(placementSide); IMechanical instance = (IMechanical) ((IMechanical) checkTile).getInstance(checkDir.getOpposite());
if (instance != null && instance.canConnect(checkDir.getOpposite(), this)) if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite(), this))
{ {
connections[checkDir.ordinal()] = instance; connections[checkDir.ordinal()] = instance;
getNetwork().merge(instance.getNetwork()); getNetwork().merge(instance.getNetwork());
@ -152,7 +157,7 @@ public class PartGearShaft extends PartMechanical
@Override @Override
public boolean inverseRotation(ForgeDirection dir) public boolean inverseRotation(ForgeDirection dir)
{ {
return false; return dir == placementSide;
} }
} }

View file

@ -36,7 +36,6 @@ public class RenderGearShaft
GL11.glPushMatrix(); GL11.glPushMatrix();
ForgeDirection dir = part.placementSide; ForgeDirection dir = part.placementSide;
dir = ForgeDirection.getOrientation(!(dir.ordinal() % 2 == 0) ? dir.ordinal() - 1 : dir.ordinal());
switch (dir) switch (dir)
{ {

View file

@ -81,6 +81,7 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
long torque = mechanical.getTorque(); long torque = mechanical.getTorque();
boolean inverseRotation = mechanical.inverseRotation(dir) && adjacentMech.inverseRotation(dir.getOpposite()); boolean inverseRotation = mechanical.inverseRotation(dir) && adjacentMech.inverseRotation(dir.getOpposite());
int inversion = inverseRotation ? -1 : 1; int inversion = inverseRotation ? -1 : 1;
if (Math.abs(torque + inversion * (adjacentMech.getTorque() / ratio * ACCELERATION)) < Math.abs(adjacentMech.getTorque() / ratio)) if (Math.abs(torque + inversion * (adjacentMech.getTorque() / ratio * ACCELERATION)) < Math.abs(adjacentMech.getTorque() / ratio))

View file

@ -58,16 +58,6 @@ public class TraitMechanical extends TileMultipart implements IMechanical
@Override @Override
public boolean canConnect(ForgeDirection from) public boolean canConnect(ForgeDirection from)
{ {
TMultiPart part = this.partMap(from.ordinal());
if (part != null)
{
if (this.mechanicalInterfaces.contains(part))
{
return ((IMechanical) part).canConnect(from);
}
}
return false; return false;
} }
@ -88,6 +78,11 @@ public class TraitMechanical extends TileMultipart implements IMechanical
{ {
TMultiPart part = this.partMap(from.ordinal()); TMultiPart part = this.partMap(from.ordinal());
if (part == null)
{
part = partMap(PartMap.CENTER.ordinal());
}
if (part != null) if (part != null)
{ {
if (part instanceof IMechanical) if (part instanceof IMechanical)
@ -148,4 +143,9 @@ public class TraitMechanical extends TileMultipart implements IMechanical
return null; return null;
} }
@Override
public boolean inverseRotation(ForgeDirection dir)
{
return false;
}
} }