Updated BuildCraft API

This commit is contained in:
Calclavia 2013-08-25 21:36:29 +08:00
parent 9b356038f9
commit e228e11031
4 changed files with 46 additions and 32 deletions

View file

@ -1,12 +1,10 @@
/** /**
* Copyright (c) SpaceToad, 2011 * Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
* http://www.mod-buildcraft.com
* *
* BuildCraft is distributed under the terms of the Minecraft Mod Public * BuildCraft is distributed under the terms of the Minecraft Mod Public License
* License 1.0, or MMPL. Please check the contents of the license located in * 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt * http://www.mod-buildcraft.com/MMPL-1.0.txt
*/ */
package buildcraft.api.core; package buildcraft.api.core;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -14,36 +12,35 @@ import net.minecraft.world.World;
public class SafeTimeTracker { public class SafeTimeTracker {
private long lastMark = Long.MIN_VALUE; private long lastMark = Long.MIN_VALUE;
private long duration = 0; private long duration = -1;
private boolean marked;
/** /**
* Return true if a given delay has passed since last time marked was called successfully. * Return true if a given delay has passed since last time marked was called
* successfully.
*/ */
public boolean markTimeIfDelay(World world, long delay) { public boolean markTimeIfDelay(World world, long delay) {
if (world == null) if (world == null)
return false; return false;
long currentTime = world.getWorldTime(); long currentTime = world.getTotalWorldTime();
if (currentTime < lastMark) { if (currentTime < lastMark) {
lastMark = currentTime; lastMark = currentTime;
return false; return false;
} else if (lastMark + delay <= currentTime) { } else if (lastMark + delay <= currentTime) {
duration = currentTime - lastMark; duration = currentTime - lastMark;
lastMark = world.getWorldTime(); lastMark = currentTime;
marked = true;
return true; return true;
} else } else
return false; return false;
} }
public long durationOfLastDelay(){ public long durationOfLastDelay() {
return marked ? duration : 0; return duration > 0 ? duration : 0;
} }
public void markTime(World world) { public void markTime(World world) {
lastMark = world.getWorldTime(); lastMark = world.getTotalWorldTime();
} }
} }

View file

@ -73,7 +73,7 @@ public final class PowerHandler {
return current; return current;
} }
} }
public static final PerditionCalculator DEFUALT_PERDITION = new PerditionCalculator(); public static final PerditionCalculator DEFAULT_PERDITION = new PerditionCalculator();
private float minEnergyReceived; private float minEnergyReceived;
private float maxEnergyReceived; private float maxEnergyReceived;
private float maxEnergyStored; private float maxEnergyStored;
@ -92,6 +92,7 @@ public final class PowerHandler {
this.receptor = receptor; this.receptor = receptor;
this.type = type; this.type = type;
this.receiver = new PowerReceiver(); this.receiver = new PowerReceiver();
this.perdition = DEFAULT_PERDITION;
} }
public PowerReceiver getPowerReceiver() { public PowerReceiver getPowerReceiver() {
@ -164,12 +165,14 @@ public final class PowerHandler {
* @param perdition * @param perdition
*/ */
public void setPerdition(PerditionCalculator perdition) { public void setPerdition(PerditionCalculator perdition) {
if (perdition == null)
perdition = DEFAULT_PERDITION;
this.perdition = perdition; this.perdition = perdition;
} }
public PerditionCalculator getPerdition() { public PerditionCalculator getPerdition() {
if (perdition == null) if (perdition == null)
return DEFUALT_PERDITION; return DEFAULT_PERDITION;
return perdition; return perdition;
} }
@ -191,11 +194,10 @@ public final class PowerHandler {
private void applyPerdition() { private void applyPerdition() {
if (perditionTracker.markTimeIfDelay(receptor.getWorld(), 1) && energyStored > 0) { if (perditionTracker.markTimeIfDelay(receptor.getWorld(), 1) && energyStored > 0) {
float newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay()); float newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
if (newEnergy == 0 || newEnergy < energyStored) { if (newEnergy == 0 || newEnergy < energyStored)
energyStored = newEnergy; energyStored = newEnergy;
} else { else
energyStored = DEFUALT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay()); energyStored = DEFAULT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
}
validateEnergy(); validateEnergy();
} }
} }
@ -313,6 +315,7 @@ public final class PowerHandler {
* @return * @return
*/ */
public float powerRequest() { public float powerRequest() {
update();
return Math.min(maxEnergyReceived, maxEnergyStored - energyStored); return Math.min(maxEnergyReceived, maxEnergyStored - energyStored);
} }

View file

@ -1,17 +1,29 @@
/** /**
* Copyright (c) SpaceToad, 2011 * Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
* http://www.mod-buildcraft.com
* *
* BuildCraft is distributed under the terms of the Minecraft Mod Public * BuildCraft is distributed under the terms of the Minecraft Mod Public License
* License 1.0, or MMPL. Please check the contents of the license located in * 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt * http://www.mod-buildcraft.com/MMPL-1.0.txt
*/ */
package buildcraft.api.transport; package buildcraft.api.transport;
import buildcraft.api.transport.IPipeTile.PipeType;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
public interface IPipeConnection { public interface IPipeConnection {
public boolean isPipeConnected(ForgeDirection with); enum ConnectOverride {
CONNECT, DISCONNECT, DEFAULT
};
/**
* Allows you to override pipe connection logic.
*
* @param type
* @param with
* @return CONNECT to force a connection, DISCONNECT to force no connection,
* and DEFAULT to let the pipe decide.
*/
public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with);
} }

View file

@ -11,7 +11,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidHandler;
public interface IPipeTile extends ISolidSideTile, IPipeConnection, IFluidHandler { public interface IPipeTile extends ISolidSideTile, IFluidHandler {
public enum PipeType { public enum PipeType {
@ -34,4 +34,6 @@ public interface IPipeTile extends ISolidSideTile, IPipeConnection, IFluidHandle
* @return Amount of items used from the passed stack. * @return Amount of items used from the passed stack.
*/ */
int injectItem(ItemStack stack, boolean doAdd, ForgeDirection from); int injectItem(ItemStack stack, boolean doAdd, ForgeDirection from);
boolean isPipeConnected(ForgeDirection with);
} }