From 9c3700382f05b1e8f95ad303885d2e3496da01bf Mon Sep 17 00:00:00 2001 From: Calclavia Date: Mon, 27 Jan 2014 01:02:16 +0800 Subject: [PATCH] Some minor work on the filter --- .../resource/fluid/BlockFluidMixture.java | 3 +- .../electrical/generator/TileGenerator.java | 43 ++++++++-------- .../fluid/pump/LiquidPathFinder.java | 49 ++++++++----------- .../mechanical/gear/PartGear.java | 10 ++-- .../mechanical/network/PartMechanical.java | 12 ++++- .../mechanical/process/BlockFilter.java | 3 +- .../mechanical/process/TileMixer.java | 13 ++--- 7 files changed, 68 insertions(+), 65 deletions(-) diff --git a/src/main/java/resonantinduction/core/resource/fluid/BlockFluidMixture.java b/src/main/java/resonantinduction/core/resource/fluid/BlockFluidMixture.java index 92b4d284..6d006ab8 100644 --- a/src/main/java/resonantinduction/core/resource/fluid/BlockFluidMixture.java +++ b/src/main/java/resonantinduction/core/resource/fluid/BlockFluidMixture.java @@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -36,7 +37,7 @@ public class BlockFluidMixture extends BlockFluidFinite implements ITileEntityPr { TileLiquidMixture tileFluid = (TileLiquidMixture) world.getBlockTileEntity(x, y, z); FluidStack stack = new FluidStack(ResonantInduction.MIXTURE, (int) (FluidContainerRegistry.BUCKET_VOLUME * this.getFilledPercentage(world, x, y, z))); - tileFluid.writeFluidToNBT(stack.tag); + tileFluid.writeFluidToNBT(stack.tag != null ? stack.tag : new NBTTagCompound()); return stack; } diff --git a/src/main/java/resonantinduction/electrical/generator/TileGenerator.java b/src/main/java/resonantinduction/electrical/generator/TileGenerator.java index 3aa8e56d..48f0ac73 100644 --- a/src/main/java/resonantinduction/electrical/generator/TileGenerator.java +++ b/src/main/java/resonantinduction/electrical/generator/TileGenerator.java @@ -86,32 +86,35 @@ public class TileGenerator extends TileElectrical implements IRotatable IMechanical mech = ((IMechanical) tile).getInstance(outputDir.getOpposite()); long extract = energy.extractEnergy(false); - if (extract > 0) + if (mech != null) { - final float maxAngularVelocity = energy.getEnergyCapacity() / (float) torqueRatio; - final long maxTorque = (long) ((double) energy.getEnergyCapacity() / maxAngularVelocity); - float setAngularVelocity = extract / (float) torqueRatio; - long setTorque = (long) (((double) extract) / setAngularVelocity); - - long currentTorque = Math.abs(mech.getTorque()); - - if (currentTorque != 0) + if (extract > 0) { - setTorque = Math.min(+setTorque, maxTorque) * (mech.getTorque() / currentTorque); + final float maxAngularVelocity = energy.getEnergyCapacity() / (float) torqueRatio; + final long maxTorque = (long) ((double) energy.getEnergyCapacity() / maxAngularVelocity); + float setAngularVelocity = extract / (float) torqueRatio; + long setTorque = (long) (((double) extract) / setAngularVelocity); - if (setTorque < currentTorque) + long currentTorque = Math.abs(mech.getTorque()); + + if (currentTorque != 0) { - setTorque = (long) Math.max(setTorque, currentTorque * (currentTorque / maxTorque)); + setTorque = Math.min(+setTorque, maxTorque) * (mech.getTorque() / currentTorque); + + if (setTorque < currentTorque) + { + setTorque = (long) Math.max(setTorque, currentTorque * (currentTorque / maxTorque)); + } } + + 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); } - - 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); } } } diff --git a/src/main/java/resonantinduction/mechanical/fluid/pump/LiquidPathFinder.java b/src/main/java/resonantinduction/mechanical/fluid/pump/LiquidPathFinder.java index 2bad33cd..75a99458 100644 --- a/src/main/java/resonantinduction/mechanical/fluid/pump/LiquidPathFinder.java +++ b/src/main/java/resonantinduction/mechanical/fluid/pump/LiquidPathFinder.java @@ -93,44 +93,37 @@ public class LiquidPathFinder { return false; } - try + this.addNode(node); + + if (this.isValidResult(node)) { - this.addNode(node); + this.addResult(node); + } - if (this.isValidResult(node)) - { - this.addResult(node); - } + if (this.isDone(node.clone())) + { + return false; + } - if (this.isDone(node.clone())) - { - return false; - } + if (find(this.priority, node.clone())) + { + return true; + } - if (find(this.priority, node.clone())) - { - return true; - } + Collections.shuffle(shuffledDirections); + Collections.shuffle(shuffledDirections); - Collections.shuffle(shuffledDirections); - Collections.shuffle(shuffledDirections); - - for (ForgeDirection direction : shuffledDirections) - { - if (find(direction, node.clone())) - { - return true; - } - } - - if (find(this.priority.getOpposite(), node.clone())) + for (ForgeDirection direction : shuffledDirections) + { + if (find(direction, node.clone())) { return true; } } - catch (Exception e) + + if (find(this.priority.getOpposite(), node.clone())) { - e.printStackTrace(); + return true; } return false; diff --git a/src/main/java/resonantinduction/mechanical/gear/PartGear.java b/src/main/java/resonantinduction/mechanical/gear/PartGear.java index e64735e6..9f04e1ec 100644 --- a/src/main/java/resonantinduction/mechanical/gear/PartGear.java +++ b/src/main/java/resonantinduction/mechanical/gear/PartGear.java @@ -37,6 +37,8 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock @Override public void update() { + super.update(); + if (!this.world().isRemote) { if (manualCrankTime > 0) @@ -69,16 +71,18 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock } getMultiBlock().update(); + } + public void checkClientUpdate() + { if (getMultiBlock().isPrimary()) - { - super.update(); - } + super.checkClientUpdate(); } @Override public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack item) { + // System.out.println(getNetwork()); if (BlockAdvanced.isUsableWrench(player, player.getCurrentEquippedItem(), x(), y(), z())) { if (player.isSneaking()) diff --git a/src/main/java/resonantinduction/mechanical/network/PartMechanical.java b/src/main/java/resonantinduction/mechanical/network/PartMechanical.java index 0ca9c4c5..add057b7 100644 --- a/src/main/java/resonantinduction/mechanical/network/PartMechanical.java +++ b/src/main/java/resonantinduction/mechanical/network/PartMechanical.java @@ -73,9 +73,19 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu @Override public void update() { + if (ticks == 0) + { + getNetwork().addConnector(this); + } + ticks++; angle += angularVelocity / 20; + super.update(); + } + + public void checkClientUpdate() + { if (Math.abs(prevAngularVelocity - angularVelocity) > 0.1f) { prevAngularVelocity = angularVelocity; @@ -87,8 +97,6 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu sendRotationPacket(); markPacketUpdate = false; } - - super.update(); } @Override diff --git a/src/main/java/resonantinduction/mechanical/process/BlockFilter.java b/src/main/java/resonantinduction/mechanical/process/BlockFilter.java index 54af9e07..c8a3472d 100644 --- a/src/main/java/resonantinduction/mechanical/process/BlockFilter.java +++ b/src/main/java/resonantinduction/mechanical/process/BlockFilter.java @@ -69,11 +69,12 @@ public class BlockFilter extends BlockRI implements ITileEntityProvider */ if (amount <= 1) { + System.out.println("filter dropped"); for (ItemStack itemStack : ((TileLiquidMixture) tileAbove).items) { for (Resource resoure : MachineRecipes.INSTANCE.getOutput(RecipeType.MIXER, itemStack)) { - InventoryUtility.dropItemStack(world, checkAbove, resoure.getItemStack()); + InventoryUtility.dropItemStack(world, checkAbove.clone().add(0.5), resoure.getItemStack()); } } } diff --git a/src/main/java/resonantinduction/mechanical/process/TileMixer.java b/src/main/java/resonantinduction/mechanical/process/TileMixer.java index 1f0c24c3..478184fd 100644 --- a/src/main/java/resonantinduction/mechanical/process/TileMixer.java +++ b/src/main/java/resonantinduction/mechanical/process/TileMixer.java @@ -29,16 +29,12 @@ public class TileMixer extends TileMechanical public static final long POWER = 500000; public static final int PROCESS_TIME = 5 * 20; public static final Timer timer = new Timer(); - private final long requiredTorque = 1000; - private long counter = 0; @Override public void updateEntity() { super.updateEntity(); - counter = Math.max(counter + torque, 0); - if (canWork()) { doWork(); @@ -52,7 +48,7 @@ public class TileMixer extends TileMechanical */ public boolean canWork() { - return counter >= requiredTorque; + return angularVelocity > 0; } public void doWork() @@ -70,8 +66,7 @@ public class TileMixer extends TileMechanical if (checkVector.getBlockID(worldObj) == Block.waterStill.blockID) { - checkVector.setBlock(worldObj, ResonantInduction.blockFluidMixture.blockID, 8); - System.out.println("SET"); + checkVector.setBlock(worldObj, ResonantInduction.blockFluidMixture.blockID, 8, 4); } } } @@ -86,7 +81,7 @@ public class TileMixer extends TileMechanical /** * Rotate entities around the mixer */ - double speed = 1; + double speed = angularVelocity; Vector3 originalPosition = new Vector3(entity); Vector3 relativePosition = originalPosition.clone().subtract(new Vector3(this).add(0.5)); @@ -156,8 +151,6 @@ public class TileMixer extends TileMechanical { this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, Reference.PREFIX + "mixer", 0.5f, 1); } - - counter -= requiredTorque; } }