Fix/Changed gear cranking to be reversible

This commit is contained in:
Robert Seifert 2014-03-04 00:51:07 -05:00
parent da2bd6f54b
commit b67fb29338

View file

@ -29,12 +29,9 @@ import codechicken.multipart.TileMultipart;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* We assume all the force acting on the gear is 90 degrees.
/** We assume all the force acting on the gear is 90 degrees.
*
* @author Calclavia
*
*/
* @author Calclavia */
public class PartGear extends PartMechanical implements IMechanical, IMultiBlockStructure<PartGear>
{
public static Cuboid6[][] oBoxes = new Cuboid6[6][2];
@ -53,6 +50,7 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
private int manualCrankTime = 0;
private int multiBlockRadius = 1;
private boolean crank_clockwize = true;
@Override
public void update()
@ -62,17 +60,9 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
if (!this.world().isRemote)
{
if (manualCrankTime > 0)
{
if (angularVelocity > 0)
{
torque += 4;
angularVelocity += 0.02f;
}
else
{
torque -= 4;
angularVelocity -= 0.02f;
}
angularVelocity += !crank_clockwize ? 0.03f : -0.03f;
manualCrankTime--;
}
@ -122,8 +112,9 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
{
if (!world().isRemote)
{
this.crank_clockwize = !this.crank_clockwize;
getMultiBlock().get().angularVelocity = -getMultiBlock().get().angularVelocity;
player.addChatMessage("Flipped gear to rotate " + (angularVelocity > 0 ? "clockwise" : "anticlockwise") + ".");
player.addChatMessage("Now cranking " + (this.crank_clockwize ? "clockwise" : "anticlockwise") + ".");
}
return true;
@ -151,17 +142,13 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
getMultiBlock().deconstruct();
}
/**
* Refresh should be called sparingly.
*/
/** Refresh should be called sparingly. */
@Override
public Object[] getConnections()
{
Object[] connections = new Object[6];
/**
* Only call refresh if this is the main block of a multiblock gear or a single gear block.
*/
/** Only call refresh if this is the main block of a multiblock gear or a single gear block. */
if (!getMultiBlock().isPrimary() || world() == null)
{
return connections;
@ -180,10 +167,8 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
}
}
/**
* Look for gears that are internal and adjacent to this gear. (The 4 sides + the internal
* center)
*/
/** Look for gears that are internal and adjacent to this gear. (The 4 sides + the internal
* center) */
for (int i = 0; i < 6; i++)
{
ForgeDirection checkDir = ForgeDirection.getOrientation(i);
@ -197,10 +182,8 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
if (tile instanceof IMechanical)
{
/**
* If we're checking for the block that is opposite to the gear's placement side
* (the center), then we try to look for a gear shaft in the center.
*/
/** If we're checking for the block that is opposite to the gear's placement side
* (the center), then we try to look for a gear shaft in the center. */
IMechanical instance = ((IMechanical) tile).getInstance(checkDir == placementSide.getOpposite() ? ForgeDirection.UNKNOWN : checkDir);
if (connections[checkDir.ordinal()] == null && instance != this && checkDir != placementSide && instance != null && instance.canConnect(checkDir.getOpposite(), this))
@ -237,12 +220,10 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
return connections;
}
/**
* Is this gear block the one in the center-edge of the multiblock that can interact with other
/** Is this gear block the one in the center-edge of the multiblock that can interact with other
* gears?
*
* @return
*/
* @return */
public boolean isCenterMultiBlock()
{
if (!getMultiBlock().isConstructed())
@ -306,9 +287,7 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
getMultiBlock().save(nbt);
}
/**
* Multiblock
*/
/** Multiblock */
private GearMultiBlockHandler multiBlock;
@Override
@ -397,13 +376,11 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
return getMultiBlock().get();
}
/**
* Can this gear be connected BY the source?
/** Can this gear be connected BY the source?
*
* @param from - Direction source is coming from.
* @param source - The source of the connection.
* @return True is so.
*/
* @return True is so. */
@Override
public boolean canConnect(ForgeDirection from, Object source)
{
@ -414,10 +391,8 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
if (source instanceof IMechanical)
{
/**
* Check for flat connections (gear face on gear face) to make sure it's actually on
* this gear block.
*/
/** Check for flat connections (gear face on gear face) to make sure it's actually on
* this gear block. */
if (from == placementSide.getOpposite())
{
if (source instanceof PartGear || source instanceof PartGearShaft)
@ -440,11 +415,8 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
if (part instanceof PartGear)
{
/**
* Case when we connect gears via edges internally. Large gear
* attempt
* to connect to small gear.
*/
/** Case when we connect gears via edges internally. Large gear
* attempt to connect to small gear. */
PartGear sourceGear = (PartGear) part;
if (sourceGear.isCenterMultiBlock() && !sourceGear.getMultiBlock().isPrimary())
@ -455,9 +427,7 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
}
else
{
/**
* Small gear attempting to connect to large gear.
*/
/** Small gear attempting to connect to large gear. */
if (getMultiBlock().isConstructed())
{
TMultiPart checkPart = ((PartGear) source).tile().partMap(placementSide.ordinal());
@ -473,9 +443,7 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
}
}
/**
* Face to face stick connection.
*/
/** Face to face stick connection. */
TileEntity sourceTile = getPosition().translate(from.getOpposite()).getTileEntity(world());
if (sourceTile instanceof IMechanical)
@ -486,9 +454,7 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
}
else if (from == placementSide)
{
/**
* Face to face stick connection.
*/
/** Face to face stick connection. */
TileEntity sourceTile = getPosition().translate(from).getTileEntity(world());
if (sourceTile instanceof IMechanical)
@ -527,9 +493,7 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
return false;
}
/**
* Multipart Bounds
*/
/** Multipart Bounds */
@Override
public Iterable<Cuboid6> getOcclusionBoxes()
{