Generator is now working again
This commit is contained in:
parent
7c3adc4c2b
commit
28e9a9a9ef
9 changed files with 82 additions and 155 deletions
|
@ -42,7 +42,8 @@ public class TileGenerator extends TileElectrical implements IRotatable
|
|||
|
||||
if (!isInversed)
|
||||
{
|
||||
// energy.receiveEnergy(getNetwork().getPower(), true);
|
||||
receiveMechanical(this.getDirection());
|
||||
receiveMechanical(this.getDirection().getOpposite());
|
||||
produce();
|
||||
}
|
||||
else
|
||||
|
@ -53,6 +54,24 @@ public class TileGenerator extends TileElectrical implements IRotatable
|
|||
|
||||
}
|
||||
|
||||
public void receiveMechanical(ForgeDirection inputDir)
|
||||
{
|
||||
Vector3 inputVector = new Vector3(this).translate(inputDir);
|
||||
TileEntity tile = inputVector.getTileEntity(worldObj);
|
||||
|
||||
if (tile instanceof IMechanical)
|
||||
{
|
||||
IMechanical mech = ((IMechanical) tile).getInstance(inputDir.getOpposite());
|
||||
long receive = energy.receiveEnergy((long) Math.abs(mech.getTorque() * mech.getAngularVelocity()), true);
|
||||
|
||||
if (receive > 0)
|
||||
{
|
||||
mech.setTorque((long) (mech.getTorque() * 0.5));
|
||||
mech.setAngularVelocity(mech.getAngularVelocity() * 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void produceMechanical(ForgeDirection outputDir)
|
||||
{
|
||||
Vector3 outputVector = new Vector3(this).translate(outputDir);
|
||||
|
@ -67,13 +86,21 @@ public class TileGenerator extends TileElectrical implements IRotatable
|
|||
{
|
||||
final float maxAngularVelocity = energy.getEnergyCapacity() / (float) torqueRatio;
|
||||
final long maxTorque = (long) ((double) energy.getEnergyCapacity() / maxAngularVelocity);
|
||||
float addAngularVelocity = extract / (float) torqueRatio;
|
||||
long addTorque = (long) (((double) extract) / addAngularVelocity);
|
||||
long setTorque = Math.min(mech.getTorque() + addTorque, maxTorque);
|
||||
float setAngularVelocity = Math.min(mech.getAngularVelocity() + addAngularVelocity, maxAngularVelocity);
|
||||
float setAngularVelocity = extract / (float) torqueRatio;
|
||||
long setTorque = (long) (((double) extract) / setAngularVelocity);
|
||||
|
||||
long currentTorque = Math.abs(mech.getTorque());
|
||||
|
||||
if (currentTorque != 0)
|
||||
setTorque = Math.min(+setTorque, maxTorque) * (mech.getTorque() / currentTorque);
|
||||
|
||||
float currentVelo = Math.abs(mech.getAngularVelocity());
|
||||
if (currentVelo != 0)
|
||||
setAngularVelocity = Math.min(+setAngularVelocity, maxAngularVelocity) * (mech.getAngularVelocity() / currentVelo);
|
||||
|
||||
mech.setTorque(setTorque);
|
||||
mech.setAngularVelocity(setAngularVelocity);
|
||||
energy.extractEnergy((long) (setTorque * setAngularVelocity), true);
|
||||
energy.extractEnergy((long) Math.abs(setTorque * setAngularVelocity), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,12 +79,13 @@ public class TileConveyorBelt extends TileMechanical implements IBelt, IRotatabl
|
|||
this.worldObj.playSound(this.xCoord, this.yCoord, this.zCoord, "mods.assemblyline.conveyor", 0.5f, 0.7f, true);
|
||||
}
|
||||
|
||||
double wheelRotPct = getNetwork().getRotation() / Math.PI;
|
||||
angle += Math.abs(angularVelocity / 20);
|
||||
double beltPercentage = (angle % Math.PI) / Math.PI;
|
||||
|
||||
// Sync the animation. Slant belts are slower.
|
||||
if (this.getSlant() == SlantType.NONE || this.getSlant() == SlantType.TOP)
|
||||
{
|
||||
this.animationFrame = (int) (wheelRotPct * MAX_FRAME);
|
||||
this.animationFrame = (int) (beltPercentage * MAX_FRAME);
|
||||
if (this.animationFrame < 0)
|
||||
this.animationFrame = 0;
|
||||
if (this.animationFrame > MAX_FRAME)
|
||||
|
@ -92,7 +93,7 @@ public class TileConveyorBelt extends TileMechanical implements IBelt, IRotatabl
|
|||
}
|
||||
else
|
||||
{
|
||||
this.animationFrame = (int) (wheelRotPct * MAX_SLANT_FRAME);
|
||||
this.animationFrame = (int) (beltPercentage * MAX_SLANT_FRAME);
|
||||
if (this.animationFrame < 0)
|
||||
this.animationFrame = 0;
|
||||
if (this.animationFrame > MAX_SLANT_FRAME)
|
||||
|
@ -104,6 +105,7 @@ public class TileConveyorBelt extends TileMechanical implements IBelt, IRotatabl
|
|||
if (markRefresh)
|
||||
{
|
||||
sendRefreshPacket();
|
||||
markRefresh = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,7 +218,7 @@ public class TileConveyorBelt extends TileMechanical implements IBelt, IRotatabl
|
|||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
return direction == ForgeDirection.DOWN;
|
||||
return direction != getDirection() || direction != getDirection().getOpposite();
|
||||
}
|
||||
|
||||
public void refresh()
|
||||
|
@ -293,6 +295,6 @@ public class TileConveyorBelt extends TileMechanical implements IBelt, IRotatabl
|
|||
|
||||
public float getMoveVelocity()
|
||||
{
|
||||
return Math.max(getNetwork().getAngularVelocity(), getNetwork().getPrevAngularVelocity());
|
||||
return Math.abs(angularVelocity);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,38 +9,8 @@ import universalelectricity.api.net.INetwork;
|
|||
*/
|
||||
public interface IMechanicalNetwork extends INetwork<IMechanicalNetwork, IMechanical>
|
||||
{
|
||||
/**
|
||||
* Gets the power of the network.
|
||||
*
|
||||
* @return Power in Watts.
|
||||
*/
|
||||
public long getPower();
|
||||
|
||||
public void setPower(long torque, float angularVelocity);
|
||||
|
||||
/** Torque applied by the network at the given speed */
|
||||
public long getTorque();
|
||||
|
||||
/**
|
||||
* Gets the angular velocity of the network.
|
||||
*
|
||||
* @return In radians per second.
|
||||
*/
|
||||
public float getAngularVelocity();
|
||||
|
||||
public long getPrevTorque();
|
||||
|
||||
public float getPrevAngularVelocity();
|
||||
|
||||
public long onReceiveEnergy(IMechanical source, long torque, float angularVelocity);
|
||||
|
||||
/**
|
||||
* @return The current rotation value of the network.
|
||||
*/
|
||||
public float getRotation();
|
||||
|
||||
/**
|
||||
* Disables the network due to rotation issues.
|
||||
*/
|
||||
public void setDisabled();
|
||||
}
|
||||
|
|
|
@ -31,15 +31,6 @@ import universalelectricity.core.net.NetworkTickHandler;
|
|||
*/
|
||||
public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical> implements IMechanicalNetwork, IUpdate
|
||||
{
|
||||
private long prevTorque = 0;
|
||||
private float prevAngularVelocity = 0;
|
||||
|
||||
private long torque = 0;
|
||||
private float angularVelocity = 0;
|
||||
|
||||
/** The cached resistance caused by all connectors */
|
||||
private float load = 0;
|
||||
|
||||
/** The current rotation of the network */
|
||||
private float rotation = 0;
|
||||
private long lastRotateTime;
|
||||
|
@ -47,10 +38,6 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
|
|||
/** The direction in which a conductor is placed relative to a specific conductor. */
|
||||
protected final HashMap<Object, EnumSet<ForgeDirection>> handlerDirectionMap = new LinkedHashMap<Object, EnumSet<ForgeDirection>>();
|
||||
|
||||
private Set<IMechanical> prevGenerators = new LinkedHashSet<IMechanical>();
|
||||
private Set<IMechanical> generators = new LinkedHashSet<IMechanical>();
|
||||
private boolean disabled;
|
||||
|
||||
private boolean markUpdateRotation = true;
|
||||
|
||||
/**
|
||||
|
@ -115,7 +102,7 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
|
|||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return !disabled && getConnectors().size() > 0;
|
||||
return getConnectors().size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -124,68 +111,9 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
|
|||
return canUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies energy to the mechanical network this tick.
|
||||
* Note: Server side only.
|
||||
*/
|
||||
@Override
|
||||
public long onReceiveEnergy(IMechanical source, long torque, float angularVelocity)
|
||||
{
|
||||
this.torque += torque;
|
||||
this.angularVelocity += angularVelocity;
|
||||
this.generators.add(source);
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
return (long) (torque * angularVelocity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPrevTorque()
|
||||
{
|
||||
return prevTorque;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPrevAngularVelocity()
|
||||
{
|
||||
return prevAngularVelocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTorque()
|
||||
{
|
||||
return torque;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAngularVelocity()
|
||||
{
|
||||
return angularVelocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPower()
|
||||
{
|
||||
return (long) (getTorque() * getAngularVelocity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPower(long torque, float angularVelocity)
|
||||
{
|
||||
prevTorque = this.torque;
|
||||
prevAngularVelocity = this.angularVelocity;
|
||||
this.torque = torque;
|
||||
this.angularVelocity = angularVelocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
disabled = false;
|
||||
// Reset
|
||||
prevTorque = torque = 0;
|
||||
prevAngularVelocity = angularVelocity = 0;
|
||||
load = 1;
|
||||
|
||||
super.reconstruct();
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
}
|
||||
|
@ -222,20 +150,13 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
|
|||
|
||||
if (deltaTime > 1)
|
||||
{
|
||||
rotation = (float) (((angularVelocity) * (deltaTime / 1000f) + rotation) % (2 * Math.PI));
|
||||
rotation = (float) (((0) * (deltaTime / 1000f) + rotation) % (2 * Math.PI));
|
||||
lastRotateTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
return rotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisabled()
|
||||
{
|
||||
System.out.println("NETWORK DISABLED");
|
||||
disabled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMechanicalNetwork newInstance()
|
||||
{
|
||||
|
@ -247,11 +168,4 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
|
|||
{
|
||||
return IMechanical.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getClass().getSimpleName() + "[" + this.hashCode() + ", Handlers: " + getConnectors().size() + ", Connectors: " + getConnectors().size() + ", Power:" + getPower() + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,10 +48,16 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
|||
/** The mechanical connections this connector has made */
|
||||
protected Object[] connections = new Object[6];
|
||||
|
||||
protected float angularVelocity;
|
||||
protected float prevAngularVelocity, angularVelocity;
|
||||
|
||||
protected long torque;
|
||||
|
||||
/**
|
||||
* Packets
|
||||
*/
|
||||
int ticks = 0;
|
||||
boolean markPacketUpdate = false;
|
||||
|
||||
/** Side of the block this is placed on */
|
||||
public ForgeDirection placementSide = ForgeDirection.UNKNOWN;
|
||||
|
||||
|
@ -66,11 +72,19 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
|||
@Override
|
||||
public void update()
|
||||
{
|
||||
ticks++;
|
||||
angle += angularVelocity / 20;
|
||||
|
||||
if (!world().isRemote)
|
||||
if (prevAngularVelocity != angularVelocity)
|
||||
{
|
||||
prevAngularVelocity = angularVelocity;
|
||||
markPacketUpdate = true;
|
||||
}
|
||||
|
||||
if (!world().isRemote && markPacketUpdate && ticks % 5 == 0)
|
||||
{
|
||||
sendRotationPacket();
|
||||
markPacketUpdate = false;
|
||||
}
|
||||
|
||||
super.update();
|
||||
|
|
|
@ -70,11 +70,11 @@ public class BlockGrinderWheel extends BlockRIRotatable implements ITileEntityPr
|
|||
|
||||
}
|
||||
|
||||
if (tile.getNetwork().getAngularVelocity() > 0)
|
||||
if (tile.getAngularVelocity() != 0)
|
||||
{
|
||||
// Move entity based on the direction of the block.
|
||||
ForgeDirection dir = this.getDirection(world, x, y, z);
|
||||
dir = ForgeDirection.getOrientation(!(dir.ordinal() % 2 == 0) ? dir.ordinal() - 1 : dir.ordinal());
|
||||
dir = ForgeDirection.getOrientation(!(dir.ordinal() % 2 == 0) ? dir.ordinal() - 1 : dir.ordinal()).getOpposite();
|
||||
float speed = tile.getAngularVelocity() / 20;
|
||||
entity.addVelocity(dir.offsetX * speed, Math.random() * speed, dir.offsetZ * speed);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class RenderGrinderWheel extends TileEntitySpecialRenderer
|
|||
TileGrinderWheel tile = (TileGrinderWheel) t;
|
||||
glPushMatrix();
|
||||
glTranslatef((float) x + 0.5F, (float) y + 0.5f, (float) z + 0.5F);
|
||||
glScalef(0.51f, 0.51f, 0.51f);
|
||||
glScalef(0.51f, 0.5f, 0.5f);
|
||||
RenderUtility.rotateBlockBasedOnDirection(tile.getDirection());
|
||||
glRotatef((float) Math.toDegrees(tile.angle), 0, 0, 1);
|
||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
|
||||
|
|
|
@ -33,7 +33,7 @@ public class TileGrinderWheel extends TileMechanical implements IRotatable
|
|||
|
||||
public EntityItem grindingItem = null;
|
||||
|
||||
private final long requiredTorque = 10000;
|
||||
private final long requiredTorque = 1000;
|
||||
private long counter = 0;
|
||||
|
||||
@Override
|
||||
|
@ -51,7 +51,7 @@ public class TileGrinderWheel extends TileMechanical implements IRotatable
|
|||
*/
|
||||
public boolean canWork()
|
||||
{
|
||||
return counter > requiredTorque;
|
||||
return counter >= requiredTorque;
|
||||
}
|
||||
|
||||
public void doWork()
|
||||
|
@ -110,7 +110,7 @@ public class TileGrinderWheel extends TileMechanical implements IRotatable
|
|||
|
||||
if (didWork)
|
||||
{
|
||||
if (this.ticks % 20 == 0)
|
||||
if (this.ticks % 8 == 0)
|
||||
{
|
||||
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, Reference.PREFIX + "grinder", 0.5f, 1);
|
||||
}
|
||||
|
|
|
@ -69,18 +69,6 @@ public class TraitMechanical extends TileMultipart implements IMechanical
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClockwise()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClockwise(boolean isClockwise)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getConnections()
|
||||
{
|
||||
|
@ -117,20 +105,32 @@ public class TraitMechanical extends TileMultipart implements IMechanical
|
|||
}
|
||||
|
||||
@Override
|
||||
public float getResistance()
|
||||
public float getAngularVelocity()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRotationInversed()
|
||||
public void setAngularVelocity(float velocity)
|
||||
{
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getLocation()
|
||||
public long getTorque()
|
||||
{
|
||||
return null;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTorque(long torque)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRatio()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue