Resolved all errors

This commit is contained in:
Calclavia 2014-03-04 22:40:04 +08:00
parent dacf725587
commit abdb29a4ec
18 changed files with 104 additions and 112 deletions

View file

@ -19,7 +19,15 @@ import calclavia.lib.prefab.tile.TileElectrical;
*/
public class TileGenerator extends TileElectrical implements IRotatable, IMechanicalNodeProvider
{
protected MechanicalNode node = new MechanicalNode(this).setLoad(0.5f);;
protected MechanicalNode node = new MechanicalNode(this)
{
@Override
public boolean canConnect(ForgeDirection from, Object source)
{
return from == getDirection() || from == getDirection().getOpposite();
}
}.setLoad(0.5f);
/** Generator turns KE -> EE. Inverted one will turn EE -> KE. */
public boolean isInversed = true;
@ -40,83 +48,61 @@ public class TileGenerator extends TileElectrical implements IRotatable, IMechan
{
if (!isInversed)
{
receiveMechanical(getDirection());
receiveMechanical(getDirection().getOpposite());
receiveMechanical();
produce();
}
else
{
produceMechanical(getDirection());
produceMechanical(getDirection().getOpposite());
produceMechanical();
}
}
public void receiveMechanical(ForgeDirection inputDir)
public void receiveMechanical()
{
Vector3 inputVector = new Vector3(this).translate(inputDir);
TileEntity tile = inputVector.getTileEntity(worldObj);
double power = node.getEnergy();
long receive = energy.receiveEnergy((long) power, true);
if (tile instanceof IMechanical)
if (receive > 0)
{
IMechanical mech = ((IMechanical) tile).getInstance(inputDir.getOpposite());
if (mech != null)
{
long power = (long) Math.abs(mech.getTorque() * mech.getAngularVelocity()) / 2;
long receive = energy.receiveEnergy(power, true);
if (receive > 0)
{
double percentageUsed = (double) receive / (double) power;
mech.setTorque((long) (mech.getTorque() - (mech.getTorque() * percentageUsed)));
mech.setAngularVelocity((float) (mech.getAngularVelocity() - (mech.getAngularVelocity() * percentageUsed)));
}
}
double percentageUsed = (double) receive / (double) power;
node.torque = (node.getTorque() - (node.getTorque() * percentageUsed));
node.angularVelocity = (node.getAngularVelocity() - (node.getAngularVelocity() * percentageUsed));
}
}
public void produceMechanical(ForgeDirection outputDir)
public void produceMechanical()
{
Vector3 outputVector = new Vector3(this).translate(outputDir);
TileEntity tile = outputVector.getTileEntity(worldObj);
long extract = energy.extractEnergy(energy.getEnergy(), false);
if (tile instanceof IMechanical)
if (extract > 0)
{
IMechanical mech = ((IMechanical) tile).getInstance(outputDir.getOpposite());
long extract = energy.extractEnergy(energy.getEnergy() / 2, false);
long torqueRatio = (long) ((gearRatio + 1) / 2.2d * (extract));
if (mech != null && mech.canConnect(outputDir.getOpposite(), this))
if (torqueRatio > 0)
{
if (extract > 0)
{
long torqueRatio = (long) ((gearRatio + 1) / 2.2d * (extract));
final double maxAngularVelocity = extract / (float) torqueRatio;
if (torqueRatio > 0)
{
final float maxAngularVelocity = extract / (float) torqueRatio;
final double maxTorque = ((double) extract) / maxAngularVelocity;
final long maxTorque = (long) (((double) extract) / maxAngularVelocity);
double setAngularVelocity = maxAngularVelocity;
double setTorque = maxTorque;
float setAngularVelocity = maxAngularVelocity;
long setTorque = maxTorque;
double currentTorque = Math.abs(node.getTorque());
long currentTorque = Math.abs(mech.getTorque());
if (currentTorque != 0)
setTorque = Math.min(setTorque, maxTorque) * (node.getTorque() / currentTorque);
if (currentTorque != 0)
setTorque = Math.min(setTorque, maxTorque) * (mech.getTorque() / currentTorque);
double currentVelo = Math.abs(node.getAngularVelocity());
if (currentVelo != 0)
setAngularVelocity = Math.min(+setAngularVelocity, maxAngularVelocity) * (node.getAngularVelocity() / currentVelo);
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) Math.abs(setTorque * setAngularVelocity), true);
}
}
node.torque = setTorque;
node.angularVelocity = setAngularVelocity;
energy.extractEnergy((long) Math.abs(setTorque * setAngularVelocity), true);
}
}
}
@Override

View file

@ -286,8 +286,7 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
{
getNetwork().torqueGraph.queue(instance.getTorque());
getNetwork().angularVelocityGraph.queue(instance.getAngularVelocity());
getNetwork().energyGraph.queue((long) (instance.getEnergy()));
getNetwork().powerGraph.queue(getNetwork().energyGraph.getAverage() * 20);
getNetwork().powerGraph.queue((long) instance.getPower());
}
}

View file

@ -612,7 +612,7 @@ public class TileTesla extends TileElectrical implements IMultiBlockStructure<Ti
if (t instanceof TileTesla)
{
vectors.add(checkPosition.clone().subtract(position()));
vectors.add(checkPosition.clone().subtract(getPosition()));
}
else
{
@ -656,7 +656,7 @@ public class TileTesla extends TileElectrical implements IMultiBlockStructure<Ti
}
@Override
public Vector3 position()
public Vector3 getPosition()
{
return new Vector3(this);
}

View file

@ -43,7 +43,7 @@ public class BlockConveyorBelt extends BlockTile
if (t != null && t instanceof TileConveyorBelt)
{
TileConveyorBelt tileEntity = (TileConveyorBelt) t;
tileEntity.getNetwork().reconstruct();
tileEntity.mechanicalNode.reconstruct();
}
}
@ -55,7 +55,7 @@ public class BlockConveyorBelt extends BlockTile
if (t != null && t instanceof TileConveyorBelt)
{
TileConveyorBelt tileEntity = (TileConveyorBelt) t;
tileEntity.getNetwork().reconstruct();
tileEntity.mechanicalNode.reconstruct();
}
}
@ -291,7 +291,7 @@ public class BlockConveyorBelt extends BlockTile
if (!world.isBlockIndirectlyGettingPowered(x, y, z))
{
float maxSpeed = tile.getMoveVelocity() / 20;
double maxSpeed = tile.getMoveVelocity() / 20;
if (maxSpeed > 0)
{

View file

@ -100,7 +100,7 @@ public class RenderConveyorBelt extends TileEntitySpecialRenderer implements ISi
bindTexture(name);
GL11.glRotatef(180, 0f, 1f, 0f);
GL11.glTranslatef(0f, -0.68f, 0f);
MODEL.render(0.0625f, (float) Math.toRadians(tileEntity.angle), false, false, false, false);
MODEL.render(0.0625f, (float) Math.toRadians(tileEntity.mechanicalNode.angle), false, false, false, false);
}
}
else
@ -122,7 +122,7 @@ public class RenderConveyorBelt extends TileEntitySpecialRenderer implements ISi
}
ResourceLocation name = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "belt/frame" + frame + ".png");
bindTexture(name);
MODEL.render(0.0625F, (float) Math.toRadians(tileEntity.angle), false, false, false, true);
MODEL.render(0.0625F, (float) Math.toRadians(tileEntity.mechanicalNode.angle), false, false, false, true);
}

View file

@ -12,15 +12,12 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.api.mechanical.IBelt;
import resonantinduction.api.mechanical.IMechanical;
import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInduction;
import resonantinduction.mechanical.Mechanical;
import resonantinduction.mechanical.energy.network.IMechanicalNodeProvider;
import resonantinduction.mechanical.energy.network.MechanicalNode;
import resonantinduction.mechanical.energy.network.TileMechanical;
import resonantinduction.mechanical.energy.network.TileMechanical.PacketMechanicalNode;
import resonantinduction.mechanical.process.crusher.TileMechanicalPiston;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.prefab.tile.IRotatable;

View file

@ -259,7 +259,7 @@ public class PartGear extends PartMechanical implements IMultiBlockStructure<Par
if (checkPart instanceof PartGear)
{
ForgeDirection requiredDirection = ((PartGear) checkPart).position().subtract(position()).toForgeDirection();
ForgeDirection requiredDirection = ((PartGear) checkPart).getPosition().subtract(position()).toForgeDirection();
return ((PartGear) checkPart).isCenterMultiBlock() && ((PartGear) source).placementSide == requiredDirection;
}
}
@ -410,7 +410,7 @@ public class PartGear extends PartMechanical implements IMultiBlockStructure<Par
return true;
}
universalelectricity.api.vector.Vector3 primaryPos = getMultiBlock().getPrimary().position();
universalelectricity.api.vector.Vector3 primaryPos = getMultiBlock().getPrimary().getPosition();
if (primaryPos.intX() == x() && placementSide.offsetX == 0)
{

View file

@ -55,7 +55,7 @@ public class RenderGear implements ISimpleItemRenderer
// Center the model first.
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
GL11.glPushMatrix();
renderGear(part.placementSide.ordinal(), part.tier, part.getMultiBlock().isConstructed(), Math.toDegrees(part.angle));
renderGear(part.placementSide.ordinal(), part.tier, part.getMultiBlock().isConstructed(), Math.toDegrees(part.node.angle));
GL11.glPopMatrix();
GL11.glPopMatrix();
}

View file

@ -62,7 +62,7 @@ public class RenderGearShaft implements ISimpleItemRenderer
break;
}
GL11.glRotatef((float) Math.toDegrees(part.angle), 0, 1, 0);
GL11.glRotatef((float) Math.toDegrees(part.node.angle), 0, 1, 0);
switch (part.tier)
{

View file

@ -4,5 +4,13 @@ import resonantinduction.core.grid.Node;
public abstract class EnergyNode extends Node
{
/**
* @return Gets the power of this node. Note that power by definition is energy per second.
*/
public abstract double getPower();
/**
* @return Gets the energy buffered in this node at this instance.
*/
public abstract double getEnergy();
}

View file

@ -31,6 +31,8 @@ public class MechanicalNode extends EnergyNode
protected double load = 1;
protected byte connectionMap = Byte.parseByte("111111", 2);
private double power = 0;
public MechanicalNode(IMechanicalNodeProvider parent)
{
this.parent = parent;
@ -52,6 +54,7 @@ public class MechanicalNode extends EnergyNode
public void update(float deltaTime)
{
float acceleration = this.acceleration * deltaTime;
power = getEnergy() / deltaTime;
prevAngularVelocity = angularVelocity;
@ -212,6 +215,12 @@ public class MechanicalNode extends EnergyNode
return torque * angularVelocity;
}
@Override
public double getPower()
{
return power;
}
@Override
public IGrid newGrid()
{

View file

@ -22,8 +22,7 @@ import codechicken.multipart.TMultiPart;
*/
public abstract class PartMechanical extends JCuboidPart implements JNormalOcclusion, TFacePart, IMechanicalNodeProvider
{
protected MechanicalNode node;
public MechanicalNode node;
protected double prevAngularVelocity;
/**
@ -189,7 +188,7 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
return getItem();
}
public universalelectricity.api.vector.Vector3 position()
public universalelectricity.api.vector.Vector3 getPosition()
{
return new universalelectricity.api.vector.Vector3(x(), y(), z());
}

View file

@ -16,7 +16,7 @@ public abstract class TileMechanical extends TileAdvanced implements IMechanical
{
protected static final int PACKET_VELOCITY = Mechanical.contentRegistry.getNextPacketID();
protected MechanicalNode mechanicalNode = new PacketMechanicalNode(this).setLoad(0.5f);;
public MechanicalNode mechanicalNode = new PacketMechanicalNode(this).setLoad(0.5f);
protected class PacketMechanicalNode extends MechanicalNode
{

View file

@ -24,13 +24,6 @@ public class TileWindTurbine extends TileMechanicalTurbine
private float efficiency = 0;
private long windPower = 0;
@Override
public void invalidate()
{
getNetwork().split(this);
super.invalidate();
}
@Override
public void updateEntity()
{
@ -44,7 +37,7 @@ public class TileWindTurbine extends TileMechanicalTurbine
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
return;
}
/**
* Only the primary turbine ticks.
*/

View file

@ -21,7 +21,7 @@ public class TilePump extends TileMechanical implements IFluidHandler, IRotatabl
{
super.updateEntity();
if (!worldObj.isRemote && getPower() > 0)
if (!worldObj.isRemote && mechanicalNode.getPower() > 0)
{
/**
* Try to suck fluid in
@ -30,7 +30,7 @@ public class TilePump extends TileMechanical implements IFluidHandler, IRotatabl
if (tileIn instanceof IFluidHandler && !(tileIn instanceof IPressurizedNode))
{
int flowRate = (int) (((double) getPower() / (double) maximumPower) * 500);
int flowRate = (int) (((double) mechanicalNode.getPower() / (double) maximumPower) * 500);
FluidStack drain = ((IFluidHandler) tileIn).drain(getDirection(), flowRate, false);
if (drain != null)
@ -105,24 +105,19 @@ public class TilePump extends TileMechanical implements IFluidHandler, IRotatabl
@Override
public int getPressure(ForgeDirection dir)
{
if (getPower() > 0)
if (mechanicalNode.getPower() > 0)
{
if (dir == getDirection())
{
return (int) Math.max((((double) getPower() / (double) maximumPower) * 100), 2);
return (int) Math.max((((double) mechanicalNode.getPower() / (double) maximumPower) * 100), 2);
}
else if (dir == getDirection().getOpposite())
{
return (int) -Math.max((((double) getPower() / (double) maximumPower) * 100), 2);
return (int) -Math.max((((double) mechanicalNode.getPower() / (double) maximumPower) * 100), 2);
}
}
return 0;
}
@Override
public boolean canConnect(ForgeDirection from, Object source)
{
return true;
}
}

View file

@ -79,12 +79,12 @@ public class BlockGrindingWheel extends BlockRotatable implements ITileEntityPro
}
if (tile.getAngularVelocity() != 0)
if (tile.mechanicalNode.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()).getOpposite();
float speed = tile.getAngularVelocity() / 20;
double speed = tile.mechanicalNode.getAngularVelocity() / 20;
entity.addVelocity(dir.offsetX * speed, Math.random() * speed, dir.offsetZ * speed);
}
}

View file

@ -36,7 +36,7 @@ public class RenderGrinderWheel extends TileEntitySpecialRenderer
ForgeDirection dir = tile.getDirection();
dir = ForgeDirection.getOrientation(!(dir.ordinal() % 2 == 0) ? dir.ordinal() - 1 : dir.ordinal());
RenderUtility.rotateBlockBasedOnDirection(dir);
glRotatef((float) Math.toDegrees(tile.angle), 0, 0, 1);
glRotatef((float) Math.toDegrees(tile.mechanicalNode.angle), 0, 0, 1);
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "planks_oak.png");
MODEL.renderAllExcept("teeth");
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "cobblestone.png");

View file

@ -7,13 +7,13 @@ import net.minecraftforge.common.ForgeDirection;
import org.apache.commons.lang3.ArrayUtils;
import resonantinduction.api.mechanical.IMechanical;
import resonantinduction.api.recipe.MachineRecipes;
import resonantinduction.api.recipe.MachineRecipes.RecipeType;
import resonantinduction.api.recipe.RecipeResource;
import resonantinduction.archaic.filter.Timer;
import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInduction;
import resonantinduction.mechanical.energy.network.MechanicalNode;
import resonantinduction.mechanical.energy.network.TileMechanical;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.prefab.tile.IRotatable;
@ -31,13 +31,36 @@ public class TileGrinderWheel extends TileMechanical implements IRotatable
public EntityItem grindingItem = null;
private final long requiredTorque = 1000;
private long counter = 0;
private double counter = 0;
public TileGrinderWheel()
{
mechanicalNode = new PacketMechanicalNode(this)
{
@Override
public boolean canConnect(ForgeDirection from, Object source)
{
if (getDirection().ordinal() < 2)
{
return from.offsetY != 0;
}
return getDirection().getRotation(ForgeDirection.UP) == from || getDirection().getRotation(ForgeDirection.DOWN) == from;
}
@Override
public boolean inverseRotation(ForgeDirection dir, MechanicalNode with)
{
return !(dir.offsetX > 0 || dir.offsetZ < 0 || dir.offsetY < 0);
}
};
}
@Override
public void updateEntity()
{
super.updateEntity();
counter = Math.max(counter + torque, 0);
counter = Math.max(counter + mechanicalNode.torque, 0);
doWork();
}
@ -164,21 +187,4 @@ public class TileGrinderWheel extends TileMechanical implements IRotatable
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, direction.ordinal(), 3);
}
@Override
public boolean canConnect(ForgeDirection from, Object source)
{
if (getDirection().ordinal() < 2)
{
return from.offsetY != 0;
}
return getDirection().getRotation(ForgeDirection.UP) == from || getDirection().getRotation(ForgeDirection.DOWN) == from;
}
@Override
public boolean inverseRotation(ForgeDirection dir, IMechanical with)
{
return !(dir.offsetX > 0 || dir.offsetZ < 0 || dir.offsetY < 0);
}
}