Some minor work on the filter

This commit is contained in:
Calclavia 2014-01-27 01:02:16 +08:00
parent 56ab302f0e
commit 9c3700382f
7 changed files with 68 additions and 65 deletions

View file

@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -36,7 +37,7 @@ public class BlockFluidMixture extends BlockFluidFinite implements ITileEntityPr
{ {
TileLiquidMixture tileFluid = (TileLiquidMixture) world.getBlockTileEntity(x, y, z); TileLiquidMixture tileFluid = (TileLiquidMixture) world.getBlockTileEntity(x, y, z);
FluidStack stack = new FluidStack(ResonantInduction.MIXTURE, (int) (FluidContainerRegistry.BUCKET_VOLUME * this.getFilledPercentage(world, 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; return stack;
} }

View file

@ -86,32 +86,35 @@ public class TileGenerator extends TileElectrical implements IRotatable
IMechanical mech = ((IMechanical) tile).getInstance(outputDir.getOpposite()); IMechanical mech = ((IMechanical) tile).getInstance(outputDir.getOpposite());
long extract = energy.extractEnergy(false); long extract = energy.extractEnergy(false);
if (extract > 0) if (mech != null)
{ {
final float maxAngularVelocity = energy.getEnergyCapacity() / (float) torqueRatio; if (extract > 0)
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)
{ {
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);
} }
} }
} }

View file

@ -93,44 +93,37 @@ public class LiquidPathFinder
{ {
return false; return false;
} }
try this.addNode(node);
if (this.isValidResult(node))
{ {
this.addNode(node); this.addResult(node);
}
if (this.isValidResult(node)) if (this.isDone(node.clone()))
{ {
this.addResult(node); return false;
} }
if (this.isDone(node.clone())) if (find(this.priority, node.clone()))
{ {
return false; return true;
} }
if (find(this.priority, node.clone())) Collections.shuffle(shuffledDirections);
{ Collections.shuffle(shuffledDirections);
return true;
}
Collections.shuffle(shuffledDirections); for (ForgeDirection direction : shuffledDirections)
Collections.shuffle(shuffledDirections); {
if (find(direction, node.clone()))
for (ForgeDirection direction : shuffledDirections)
{
if (find(direction, node.clone()))
{
return true;
}
}
if (find(this.priority.getOpposite(), node.clone()))
{ {
return true; return true;
} }
} }
catch (Exception e)
if (find(this.priority.getOpposite(), node.clone()))
{ {
e.printStackTrace(); return true;
} }
return false; return false;

View file

@ -37,6 +37,8 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
@Override @Override
public void update() public void update()
{ {
super.update();
if (!this.world().isRemote) if (!this.world().isRemote)
{ {
if (manualCrankTime > 0) if (manualCrankTime > 0)
@ -69,16 +71,18 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
} }
getMultiBlock().update(); getMultiBlock().update();
}
public void checkClientUpdate()
{
if (getMultiBlock().isPrimary()) if (getMultiBlock().isPrimary())
{ super.checkClientUpdate();
super.update();
}
} }
@Override @Override
public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack item) public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack item)
{ {
// System.out.println(getNetwork());
if (BlockAdvanced.isUsableWrench(player, player.getCurrentEquippedItem(), x(), y(), z())) if (BlockAdvanced.isUsableWrench(player, player.getCurrentEquippedItem(), x(), y(), z()))
{ {
if (player.isSneaking()) if (player.isSneaking())

View file

@ -73,9 +73,19 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
@Override @Override
public void update() public void update()
{ {
if (ticks == 0)
{
getNetwork().addConnector(this);
}
ticks++; ticks++;
angle += angularVelocity / 20; angle += angularVelocity / 20;
super.update();
}
public void checkClientUpdate()
{
if (Math.abs(prevAngularVelocity - angularVelocity) > 0.1f) if (Math.abs(prevAngularVelocity - angularVelocity) > 0.1f)
{ {
prevAngularVelocity = angularVelocity; prevAngularVelocity = angularVelocity;
@ -87,8 +97,6 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
sendRotationPacket(); sendRotationPacket();
markPacketUpdate = false; markPacketUpdate = false;
} }
super.update();
} }
@Override @Override

View file

@ -69,11 +69,12 @@ public class BlockFilter extends BlockRI implements ITileEntityProvider
*/ */
if (amount <= 1) if (amount <= 1)
{ {
System.out.println("filter dropped");
for (ItemStack itemStack : ((TileLiquidMixture) tileAbove).items) for (ItemStack itemStack : ((TileLiquidMixture) tileAbove).items)
{ {
for (Resource resoure : MachineRecipes.INSTANCE.getOutput(RecipeType.MIXER, itemStack)) 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());
} }
} }
} }

View file

@ -29,16 +29,12 @@ public class TileMixer extends TileMechanical
public static final long POWER = 500000; public static final long POWER = 500000;
public static final int PROCESS_TIME = 5 * 20; public static final int PROCESS_TIME = 5 * 20;
public static final Timer<EntityItem> timer = new Timer<EntityItem>(); public static final Timer<EntityItem> timer = new Timer<EntityItem>();
private final long requiredTorque = 1000;
private long counter = 0;
@Override @Override
public void updateEntity() public void updateEntity()
{ {
super.updateEntity(); super.updateEntity();
counter = Math.max(counter + torque, 0);
if (canWork()) if (canWork())
{ {
doWork(); doWork();
@ -52,7 +48,7 @@ public class TileMixer extends TileMechanical
*/ */
public boolean canWork() public boolean canWork()
{ {
return counter >= requiredTorque; return angularVelocity > 0;
} }
public void doWork() public void doWork()
@ -70,8 +66,7 @@ public class TileMixer extends TileMechanical
if (checkVector.getBlockID(worldObj) == Block.waterStill.blockID) if (checkVector.getBlockID(worldObj) == Block.waterStill.blockID)
{ {
checkVector.setBlock(worldObj, ResonantInduction.blockFluidMixture.blockID, 8); checkVector.setBlock(worldObj, ResonantInduction.blockFluidMixture.blockID, 8, 4);
System.out.println("SET");
} }
} }
} }
@ -86,7 +81,7 @@ public class TileMixer extends TileMechanical
/** /**
* Rotate entities around the mixer * Rotate entities around the mixer
*/ */
double speed = 1; double speed = angularVelocity;
Vector3 originalPosition = new Vector3(entity); Vector3 originalPosition = new Vector3(entity);
Vector3 relativePosition = originalPosition.clone().subtract(new Vector3(this).add(0.5)); 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); this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, Reference.PREFIX + "mixer", 0.5f, 1);
} }
counter -= requiredTorque;
} }
} }