From abdb29a4ecd8c962559209e606c34ec24d830cb4 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Tue, 4 Mar 2014 22:40:04 +0800 Subject: [PATCH] Resolved all errors --- .../electrical/generator/TileGenerator.java | 88 ++++++++----------- .../electrical/multimeter/PartMultimeter.java | 3 +- .../electrical/tesla/TileTesla.java | 4 +- .../mechanical/belt/BlockConveyorBelt.java | 6 +- .../mechanical/belt/RenderConveyorBelt.java | 4 +- .../mechanical/belt/TileConveyorBelt.java | 3 - .../mechanical/energy/gear/PartGear.java | 4 +- .../mechanical/energy/gear/RenderGear.java | 2 +- .../energy/gear/RenderGearShaft.java | 2 +- .../mechanical/energy/network/EnergyNode.java | 8 ++ .../energy/network/MechanicalNode.java | 9 ++ .../energy/network/PartMechanical.java | 5 +- .../energy/network/TileMechanical.java | 2 +- .../energy/turbine/TileWindTurbine.java | 9 +- .../mechanical/fluid/transport/TilePump.java | 15 ++-- .../process/grinder/BlockGrindingWheel.java | 4 +- .../process/grinder/RenderGrinderWheel.java | 2 +- .../process/grinder/TileGrinderWheel.java | 46 +++++----- 18 files changed, 104 insertions(+), 112 deletions(-) diff --git a/electrical/src/main/java/resonantinduction/electrical/generator/TileGenerator.java b/electrical/src/main/java/resonantinduction/electrical/generator/TileGenerator.java index fcc95d063..b495f9adb 100644 --- a/electrical/src/main/java/resonantinduction/electrical/generator/TileGenerator.java +++ b/electrical/src/main/java/resonantinduction/electrical/generator/TileGenerator.java @@ -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 diff --git a/electrical/src/main/java/resonantinduction/electrical/multimeter/PartMultimeter.java b/electrical/src/main/java/resonantinduction/electrical/multimeter/PartMultimeter.java index 777864bc8..78523899d 100644 --- a/electrical/src/main/java/resonantinduction/electrical/multimeter/PartMultimeter.java +++ b/electrical/src/main/java/resonantinduction/electrical/multimeter/PartMultimeter.java @@ -286,8 +286,7 @@ public class PartMultimeter extends PartFace implements IConnector 0) { diff --git a/mechanical/src/main/java/resonantinduction/mechanical/belt/RenderConveyorBelt.java b/mechanical/src/main/java/resonantinduction/mechanical/belt/RenderConveyorBelt.java index 585ce39bf..2be774700 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/belt/RenderConveyorBelt.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/belt/RenderConveyorBelt.java @@ -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); } diff --git a/mechanical/src/main/java/resonantinduction/mechanical/belt/TileConveyorBelt.java b/mechanical/src/main/java/resonantinduction/mechanical/belt/TileConveyorBelt.java index 52ab721a7..e1a093a48 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/belt/TileConveyorBelt.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/belt/TileConveyorBelt.java @@ -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; diff --git a/mechanical/src/main/java/resonantinduction/mechanical/energy/gear/PartGear.java b/mechanical/src/main/java/resonantinduction/mechanical/energy/gear/PartGear.java index 02726de82..128a9da46 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/energy/gear/PartGear.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/energy/gear/PartGear.java @@ -259,7 +259,7 @@ public class PartGear extends PartMechanical implements IMultiBlockStructure 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; - } } diff --git a/mechanical/src/main/java/resonantinduction/mechanical/process/grinder/BlockGrindingWheel.java b/mechanical/src/main/java/resonantinduction/mechanical/process/grinder/BlockGrindingWheel.java index 8bf9d7965..27d7defa9 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/process/grinder/BlockGrindingWheel.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/process/grinder/BlockGrindingWheel.java @@ -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); } } diff --git a/mechanical/src/main/java/resonantinduction/mechanical/process/grinder/RenderGrinderWheel.java b/mechanical/src/main/java/resonantinduction/mechanical/process/grinder/RenderGrinderWheel.java index 1a3e6c6c1..d4cfa5c15 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/process/grinder/RenderGrinderWheel.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/process/grinder/RenderGrinderWheel.java @@ -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"); diff --git a/mechanical/src/main/java/resonantinduction/mechanical/process/grinder/TileGrinderWheel.java b/mechanical/src/main/java/resonantinduction/mechanical/process/grinder/TileGrinderWheel.java index 8095781ce..00b231241 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/process/grinder/TileGrinderWheel.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/process/grinder/TileGrinderWheel.java @@ -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); - } - }