Updated BuildCraft API
This commit is contained in:
parent
9b356038f9
commit
e228e11031
4 changed files with 46 additions and 32 deletions
|
@ -1,12 +1,10 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
/**
|
||||
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package buildcraft.api.core;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
@ -14,36 +12,35 @@ import net.minecraft.world.World;
|
|||
public class SafeTimeTracker {
|
||||
|
||||
private long lastMark = Long.MIN_VALUE;
|
||||
private long duration = 0;
|
||||
private boolean marked;
|
||||
private long duration = -1;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (world == null)
|
||||
return false;
|
||||
|
||||
long currentTime = world.getWorldTime();
|
||||
long currentTime = world.getTotalWorldTime();
|
||||
|
||||
if (currentTime < lastMark) {
|
||||
lastMark = currentTime;
|
||||
return false;
|
||||
} else if (lastMark + delay <= currentTime) {
|
||||
duration = currentTime - lastMark;
|
||||
lastMark = world.getWorldTime();
|
||||
marked = true;
|
||||
lastMark = currentTime;
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public long durationOfLastDelay(){
|
||||
return marked ? duration : 0;
|
||||
|
||||
public long durationOfLastDelay() {
|
||||
return duration > 0 ? duration : 0;
|
||||
}
|
||||
|
||||
public void markTime(World world) {
|
||||
lastMark = world.getWorldTime();
|
||||
lastMark = world.getTotalWorldTime();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ public final class PowerHandler {
|
|||
return current;
|
||||
}
|
||||
}
|
||||
public static final PerditionCalculator DEFUALT_PERDITION = new PerditionCalculator();
|
||||
public static final PerditionCalculator DEFAULT_PERDITION = new PerditionCalculator();
|
||||
private float minEnergyReceived;
|
||||
private float maxEnergyReceived;
|
||||
private float maxEnergyStored;
|
||||
|
@ -92,6 +92,7 @@ public final class PowerHandler {
|
|||
this.receptor = receptor;
|
||||
this.type = type;
|
||||
this.receiver = new PowerReceiver();
|
||||
this.perdition = DEFAULT_PERDITION;
|
||||
}
|
||||
|
||||
public PowerReceiver getPowerReceiver() {
|
||||
|
@ -164,12 +165,14 @@ public final class PowerHandler {
|
|||
* @param perdition
|
||||
*/
|
||||
public void setPerdition(PerditionCalculator perdition) {
|
||||
if (perdition == null)
|
||||
perdition = DEFAULT_PERDITION;
|
||||
this.perdition = perdition;
|
||||
}
|
||||
|
||||
public PerditionCalculator getPerdition() {
|
||||
if (perdition == null)
|
||||
return DEFUALT_PERDITION;
|
||||
return DEFAULT_PERDITION;
|
||||
return perdition;
|
||||
}
|
||||
|
||||
|
@ -191,11 +194,10 @@ public final class PowerHandler {
|
|||
private void applyPerdition() {
|
||||
if (perditionTracker.markTimeIfDelay(receptor.getWorld(), 1) && energyStored > 0) {
|
||||
float newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
|
||||
if (newEnergy == 0 || newEnergy < energyStored) {
|
||||
if (newEnergy == 0 || newEnergy < energyStored)
|
||||
energyStored = newEnergy;
|
||||
} else {
|
||||
energyStored = DEFUALT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
|
||||
}
|
||||
else
|
||||
energyStored = DEFAULT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
|
||||
validateEnergy();
|
||||
}
|
||||
}
|
||||
|
@ -313,6 +315,7 @@ public final class PowerHandler {
|
|||
* @return
|
||||
*/
|
||||
public float powerRequest() {
|
||||
update();
|
||||
return Math.min(maxEnergyReceived, maxEnergyStored - energyStored);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,29 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
/**
|
||||
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package buildcraft.api.transport;
|
||||
|
||||
import buildcraft.api.transport.IPipeTile.PipeType;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public interface IPipeTile extends ISolidSideTile, IPipeConnection, IFluidHandler {
|
||||
public interface IPipeTile extends ISolidSideTile, IFluidHandler {
|
||||
|
||||
public enum PipeType {
|
||||
|
||||
|
@ -34,4 +34,6 @@ public interface IPipeTile extends ISolidSideTile, IPipeConnection, IFluidHandle
|
|||
* @return Amount of items used from the passed stack.
|
||||
*/
|
||||
int injectItem(ItemStack stack, boolean doAdd, ForgeDirection from);
|
||||
|
||||
boolean isPipeConnected(ForgeDirection with);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue