Merge branch 'power'

This commit is contained in:
Christian 2013-07-05 14:32:47 -04:00
commit 10452d4964
79 changed files with 2180 additions and 2500 deletions

View file

@ -6,6 +6,10 @@ gate.pipe.containsLiquids=Liquid Traversing
gate.pipe.containsEnergy=Power Traversing gate.pipe.containsEnergy=Power Traversing
gate.pipe.requestsEnergy=Power Requested gate.pipe.requestsEnergy=Power Requested
gate.pipe.tooMuchEnergy=Power Overloaded gate.pipe.tooMuchEnergy=Power Overloaded
gate.engine.blue=Engine Blue
gate.engine.green=Engine Green
gate.engine.yellow=Engine Yellow
gate.engine.red=Engine Red
gui.building.resources=Building Resources gui.building.resources=Building Resources
gui.del=Del gui.del=Del
gui.filling.resources=Filling Resources gui.filling.resources=Filling Resources

View file

@ -28,7 +28,6 @@ import net.minecraftforge.event.ForgeSubscribe;
import buildcraft.api.core.BuildCraftAPI; import buildcraft.api.core.BuildCraftAPI;
import buildcraft.api.core.IIconProvider; import buildcraft.api.core.IIconProvider;
import buildcraft.api.gates.ActionManager; import buildcraft.api.gates.ActionManager;
import buildcraft.api.power.PowerFramework;
import buildcraft.core.BlockIndex; import buildcraft.core.BlockIndex;
import buildcraft.core.BlockSpring; import buildcraft.core.BlockSpring;
import buildcraft.core.BuildCraftConfiguration; import buildcraft.core.BuildCraftConfiguration;
@ -41,7 +40,6 @@ import buildcraft.core.EntityRobot;
import buildcraft.core.ItemBuildCraft; import buildcraft.core.ItemBuildCraft;
import buildcraft.core.ItemSpring; import buildcraft.core.ItemSpring;
import buildcraft.core.ItemWrench; import buildcraft.core.ItemWrench;
import buildcraft.core.RedstonePowerFramework;
import buildcraft.core.SpringPopulate; import buildcraft.core.SpringPopulate;
import buildcraft.core.TickHandlerCoreClient; import buildcraft.core.TickHandlerCoreClient;
import buildcraft.core.Version; import buildcraft.core.Version;
@ -212,17 +210,6 @@ public class BuildCraftCore {
longFactor.comment = "delay between full client sync packets, increasing it saves bandwidth, decreasing makes for better client syncronization."; longFactor.comment = "delay between full client sync packets, increasing it saves bandwidth, decreasing makes for better client syncronization.";
longUpdateFactor = longFactor.getInt(40); longUpdateFactor = longFactor.getInt(40);
String powerFrameworkClassName = "buildcraft.energy.PneumaticPowerFramework";
if (!forcePneumaticPower) {
powerFrameworkClassName = powerFrameworkClass.getString();
}
try {
PowerFramework.currentFramework = (PowerFramework) Class.forName(powerFrameworkClassName).getConstructor().newInstance();
} catch (Throwable e) {
bcLog.throwing("BuildCraftCore", "loadConfiguration", e);
PowerFramework.currentFramework = new RedstonePowerFramework();
}
Property wrenchId = BuildCraftCore.mainConfiguration.getItem("wrench.id", DefaultProps.WRENCH_ID); Property wrenchId = BuildCraftCore.mainConfiguration.getItem("wrench.id", DefaultProps.WRENCH_ID);
wrenchItem = (new ItemWrench(wrenchId.getInt(DefaultProps.WRENCH_ID))).setUnlocalizedName("wrenchItem"); wrenchItem = (new ItemWrench(wrenchId.getInt(DefaultProps.WRENCH_ID))).setUnlocalizedName("wrenchItem");

View file

@ -42,11 +42,11 @@ import buildcraft.energy.BlockOilFlowing;
import buildcraft.energy.BlockOilStill; import buildcraft.energy.BlockOilStill;
import buildcraft.energy.BptBlockEngine; import buildcraft.energy.BptBlockEngine;
import buildcraft.energy.EnergyProxy; import buildcraft.energy.EnergyProxy;
import buildcraft.energy.Engine.EnergyStage;
import buildcraft.energy.GuiHandler; import buildcraft.energy.GuiHandler;
import buildcraft.energy.ItemBucketOil; import buildcraft.energy.ItemBucketOil;
import buildcraft.energy.ItemEngine; import buildcraft.energy.ItemEngine;
import buildcraft.energy.OilBucketHandler; import buildcraft.energy.OilBucketHandler;
import buildcraft.energy.TileEngine.EnergyStage;
import buildcraft.energy.worldgen.BiomeGenOilDesert; import buildcraft.energy.worldgen.BiomeGenOilDesert;
import buildcraft.energy.worldgen.OilPopulate; import buildcraft.energy.worldgen.OilPopulate;
import buildcraft.energy.TriggerEngineHeat; import buildcraft.energy.TriggerEngineHeat;
@ -86,10 +86,10 @@ public class BuildCraftEnergy {
public static LiquidStack fuelLiquid; public static LiquidStack fuelLiquid;
public static boolean canOilBurn; public static boolean canOilBurn;
public static TreeMap<BlockIndex, Integer> saturationStored = new TreeMap<BlockIndex, Integer>(); public static TreeMap<BlockIndex, Integer> saturationStored = new TreeMap<BlockIndex, Integer>();
public static BCTrigger triggerBlueEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_BLUE_ENGINE_HEAT, EnergyStage.Blue); public static BCTrigger triggerBlueEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_BLUE_ENGINE_HEAT, EnergyStage.BLUE);
public static BCTrigger triggerGreenEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_GREEN_ENGINE_HEAT, EnergyStage.Green); public static BCTrigger triggerGreenEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_GREEN_ENGINE_HEAT, EnergyStage.GREEN);
public static BCTrigger triggerYellowEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_YELLOW_ENGINE_HEAT, EnergyStage.Yellow); public static BCTrigger triggerYellowEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_YELLOW_ENGINE_HEAT, EnergyStage.YELLOW);
public static BCTrigger triggerRedEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_RED_ENGINE_HEAT, EnergyStage.Red); public static BCTrigger triggerRedEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_RED_ENGINE_HEAT, EnergyStage.RED);
@Instance("BuildCraft|Energy") @Instance("BuildCraft|Energy")
public static BuildCraftEnergy instance; public static BuildCraftEnergy instance;
@ -177,7 +177,8 @@ public class BuildCraftEnergy {
IronEngineFuel.fuels.add(new IronEngineFuel(LiquidDictionary.getLiquid("Fuel", LiquidContainerRegistry.BUCKET_VOLUME), 6, 100000)); IronEngineFuel.fuels.add(new IronEngineFuel(LiquidDictionary.getLiquid("Fuel", LiquidContainerRegistry.BUCKET_VOLUME), 6, 100000));
// Iron Engine Coolants // Iron Engine Coolants
IronEngineCoolant.coolants.add(new IronEngineCoolant(new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME), 1.0f)); IronEngineCoolant.addCoolant(new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME), 0.0023F);
IronEngineCoolant.addCoolant(Block.ice.blockID, 0, new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME * 2));
LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getLiquid("Oil", LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack( LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getLiquid("Oil", LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack(
bucketOil), new ItemStack(Item.bucketEmpty))); bucketOil), new ItemStack(Item.bucketEmpty)));

View file

@ -13,7 +13,9 @@ import net.minecraft.world.World;
public class SafeTimeTracker { public class SafeTimeTracker {
private long lastMark = 0; private long lastMark = Long.MIN_VALUE;
private long duration = 0;
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.
@ -28,13 +30,19 @@ public class SafeTimeTracker {
lastMark = currentTime; lastMark = currentTime;
return false; return false;
} else if (lastMark + delay <= currentTime) { } else if (lastMark + delay <= currentTime) {
duration = currentTime - lastMark;
lastMark = world.getWorldTime(); lastMark = world.getWorldTime();
marked = true;
return true; return true;
} else } else
return false; return false;
} }
public long durationOfLastDelay(){
return marked ? duration : 0;
}
public void markTime(World world) { public void markTime(World world) {
lastMark = world.getWorldTime(); lastMark = world.getWorldTime();
} }

View file

@ -1,32 +1,95 @@
package buildcraft.api.fuels; package buildcraft.api.fuels;
import java.util.LinkedList; import java.util.HashMap;
import java.util.Map;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack; import net.minecraftforge.liquids.LiquidStack;
public class IronEngineCoolant { public final class IronEngineCoolant {
public static LinkedList<IronEngineCoolant> coolants = new LinkedList<IronEngineCoolant>(); public static Map<String, Coolant> liquidCoolants = new HashMap<String, Coolant>();
public static Map<ItemData, LiquidStack> solidCoolants = new HashMap<ItemData, LiquidStack>();
public static IronEngineCoolant getCoolantForLiquid(LiquidStack liquid) { public static LiquidStack getLiquidCoolant(ItemStack stack) {
return solidCoolants.get(new ItemData(stack.itemID, stack.getItemDamage()));
}
public static Coolant getCoolant(ItemStack stack) {
return getCoolant(getLiquidCoolant(stack));
}
public static Coolant getCoolant(LiquidStack liquid) {
if (liquid == null) if (liquid == null)
return null; return null;
if (liquid.itemID <= 0) if (liquid.itemID <= 0)
return null; return null;
for (IronEngineCoolant coolant : coolants) String fluidId = LiquidDictionary.findLiquidName(liquid);
if (coolant.liquid.isLiquidEqual(liquid)) if (fluidId != null) {
return coolant; return liquidCoolants.get(fluidId);
}
return null; return null;
} }
public final LiquidStack liquid; private IronEngineCoolant() {
public final float coolingPerUnit;
public IronEngineCoolant(LiquidStack liquid, float coolingPerUnit) {
this.liquid = liquid;
this.coolingPerUnit = coolingPerUnit;
} }
public static interface Coolant {
float getDegreesCoolingPerMB(float currentHeat);
}
public static void addCoolant(final LiquidStack liquid, final float degreesCoolingPerMB) {
String fluidId = LiquidDictionary.findLiquidName(liquid);
if (fluidId != null) {
liquidCoolants.put(fluidId, new Coolant() {
@Override
public float getDegreesCoolingPerMB(float currentHeat) {
return degreesCoolingPerMB;
}
});
}
}
public static void addCoolant(final int itemId, final int metadata, final LiquidStack coolant) {
if (Item.itemsList[itemId] != null && coolant != null && coolant.amount > 0) {
solidCoolants.put(new ItemData(itemId, metadata), coolant);
}
}
public static class ItemData {
public final int itemId, meta;
public ItemData(int itemId, int meta) {
this.itemId = itemId;
this.meta = meta;
}
@Override
public int hashCode() {
int hash = 5;
hash = 67 * hash + this.itemId;
hash = 67 * hash + this.meta;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final ItemData other = (ItemData) obj;
if (this.itemId != other.itemId)
return false;
if (this.meta != other.meta)
return false;
return true;
}
}
} }

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) SpaceToad, 2011-2012
* 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.power;
import net.minecraftforge.common.ForgeDirection;
/**
* Essentially only used for Wooden Power Pipe connection rules.
*
* This Tile Entity interface allows you to indicate that a block can emit power
* from a specific side.
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public interface IPowerEmitter {
public boolean canEmitPowerFrom(ForgeDirection side);
}

View file

@ -1,41 +0,0 @@
package buildcraft.api.power;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.core.SafeTimeTracker;
public interface IPowerProvider {
int getLatency();
int getMinEnergyReceived();
int getMaxEnergyReceived();
int getMaxEnergyStored();
int getActivationEnergy();
float getEnergyStored();
void configure(int latency, int minEnergyReceived, int maxEnergyReceived, int minActivationEnergy, int maxStoredEnergy);
void configurePowerPerdition(int powerLoss, int powerLossRegularity);
boolean update(IPowerReceptor receptor);
boolean preConditions(IPowerReceptor receptor);
float useEnergy(float min, float max, boolean doUse);
void readFromNBT(NBTTagCompound nbttagcompound);
void writeToNBT(NBTTagCompound nbttagcompound);
void receiveEnergy(float quantity, ForgeDirection from);
boolean isPowerSource(ForgeDirection from);
SafeTimeTracker getTimeTracker();
}

View file

@ -7,24 +7,41 @@
*/ */
package buildcraft.api.power; package buildcraft.api.power;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
/**
* This interface should be implemented by any Tile Entity that wishes to be
* able to receive power.
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public interface IPowerReceptor { public interface IPowerReceptor {
public void setPowerProvider(IPowerProvider provider);
public IPowerProvider getPowerProvider();
public void doWork();
/** /**
* Used to request power from pipes. The return cannot be relied on to be * Get the PowerReceiver for this side of the block. You can return the same
* anything more than a approximate guide to the power needed. When * PowerReceiver for all sides or one for each side.
* transferring power, you much check the return value of
* PowerProvider.receiverEnergy().
* *
* @param from * You should NOT return null to this method unless you mean to NEVER
* receive power from that side. Returning null, after previous returning a
* PowerReceiver, will most likely cause pipe connections to derp out and
* engines to eventually explode.
*
* @param side
* @return * @return
*/ */
public int powerRequest(ForgeDirection from); public PowerReceiver getPowerReceiver(ForgeDirection side);
/**
* Call back from the PowerHandler that is called when the stored power
* exceeds the activation power.
*
* It can be triggered by update() calls or power modification calls.
*
* @param workProvider
*/
public void doWork(PowerHandler workProvider);
public World getWorldObj();
} }

View file

@ -1,55 +0,0 @@
/**
* 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.power;
import net.minecraft.nbt.NBTTagCompound;
public abstract class PowerFramework {
static private String baseNBTName = "net.minecraft.src.buildcarft.Power";
public static PowerFramework currentFramework;
public abstract IPowerProvider createPowerProvider();
public void loadPowerProvider(IPowerReceptor receptor, NBTTagCompound compound) {
IPowerProvider provider = createPowerProvider();
if (compound.hasKey(baseNBTName)) {
NBTTagCompound cpt = compound.getCompoundTag(baseNBTName);
if (cpt.getString("class").equals(this.getClass().getName())) {
provider.readFromNBT(cpt.getCompoundTag("contents"));
}
}
receptor.setPowerProvider(provider);
}
public void savePowerProvider(IPowerReceptor receptor, NBTTagCompound compound) {
IPowerProvider provider = receptor.getPowerProvider();
if (provider == null)
return;
NBTTagCompound cpt = new NBTTagCompound();
cpt.setString("class", this.getClass().getName());
NBTTagCompound contents = new NBTTagCompound();
provider.writeToNBT(contents);
cpt.setTag("contents", contents);
compound.setTag(baseNBTName, cpt);
}
}

View file

@ -0,0 +1,385 @@
/**
* 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.power;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.core.SafeTimeTracker;
public final class PowerHandler {
public static enum Type {
ENGINE, GATE, MACHINE, PIPE, STORAGE;
public boolean canReceiveFromPipes() {
switch (this) {
case MACHINE:
case STORAGE:
return true;
}
return false;
}
public boolean eatsEngineExcess() {
switch (this) {
case MACHINE:
case STORAGE:
return true;
}
return false;
}
}
public static class PerditionCalculator {
public static final float DEFAULT_POWERLOSS = 1F;
public static final float MIN_POWERLOSS = 0.01F;
private final float powerLoss;
public PerditionCalculator() {
powerLoss = DEFAULT_POWERLOSS;
}
public PerditionCalculator(float powerLoss) {
if (powerLoss < MIN_POWERLOSS) {
powerLoss = MIN_POWERLOSS;
}
this.powerLoss = powerLoss;
}
/**
* Apply the perdition algorithm to the current stored energy. This
* function can only be called once per tick, but it might not be called
* every tick. It is triggered by any manipulation of the stored energy.
*
* @param powerHandler the PowerHandler requesting the perdition update
* @param current the current stored energy
* @param ticksPassed ticks since the last time this function was called
* @return
*/
public float applyPerdition(PowerHandler powerHandler, float current, long ticksPassed) {
current -= powerLoss * ticksPassed;
if (current < 0) {
current = 0;
}
return current;
}
}
public static final PerditionCalculator DEFUALT_PERDITION = new PerditionCalculator();
private float minEnergyReceived;
private float maxEnergyReceived;
private float maxEnergyStored;
private float activationEnergy;
private float energyStored = 0;
private final SafeTimeTracker doWorkTracker = new SafeTimeTracker();
private final SafeTimeTracker sourcesTracker = new SafeTimeTracker();
private final SafeTimeTracker perditionTracker = new SafeTimeTracker();
public final int[] powerSources = new int[6];
public final IPowerReceptor receptor;
private PerditionCalculator perdition;
private final PowerReceiver receiver;
private final Type type;
public PowerHandler(IPowerReceptor receptor, Type type) {
this.receptor = receptor;
this.type = type;
this.receiver = new PowerReceiver();
}
public PowerReceiver getPowerReceiver() {
return receiver;
}
public float getMinEnergyReceived() {
return minEnergyReceived;
}
public float getMaxEnergyReceived() {
return maxEnergyReceived;
}
public float getMaxEnergyStored() {
return maxEnergyStored;
}
public float getActivationEnergy() {
return activationEnergy;
}
public float getEnergyStored() {
return energyStored;
}
/**
* Setup your PowerHandler's settings.
*
* @param minEnergyReceived This is the minimum about of power that will be
* accepted by the PowerHandler. This should generally be greater than the
* activationEnergy if you plan to use the doWork() callback. Anything
* greater than 1 will prevent Redstone Engines from powering this Provider.
* @param maxEnergyReceived The maximum amount of power accepted by the
* PowerHandler. This should generally be less than 500. Too low and larger
* engines will overheat while trying to power the machine. Too high, and
* the engines will never warm up. Greater values also place greater strain
* on the power net.
* @param activationEnergy If the stored energy is greater than this value,
* the doWork() callback is called (once per tick).
* @param maxStoredEnergy The maximum amount of power this PowerHandler can
* store. Values tend to range between 100 and 5000. With 1000 and 1500
* being common.
*/
public void configure(float minEnergyReceived, float maxEnergyReceived, float activationEnergy, float maxStoredEnergy) {
if (minEnergyReceived > maxEnergyReceived) {
maxEnergyReceived = minEnergyReceived;
}
this.minEnergyReceived = minEnergyReceived;
this.maxEnergyReceived = maxEnergyReceived;
this.maxEnergyStored = maxStoredEnergy;
this.activationEnergy = activationEnergy;
}
public void configurePowerPerdition(int powerLoss, int powerLossRegularity) {
if (powerLoss == 0 || powerLossRegularity == 0) {
perdition = new PerditionCalculator(0);
return;
}
perdition = new PerditionCalculator((float) powerLoss / (float) powerLossRegularity);
}
/**
* Allows you to define a new PerditionCalculator class to handler perdition
* calculations.
*
* For example if you want exponentially increasing loss bases on amount
* stored.
*
* @param perdition
*/
public void setPerdition(PerditionCalculator perdition) {
this.perdition = perdition;
}
public PerditionCalculator getPerdition() {
if (perdition == null)
return DEFUALT_PERDITION;
return perdition;
}
/**
* Ticks the power handler. You should call this if you can, but its not
* required.
*
* If you don't call it, the possibility exists for some weirdness with the
* perdition algorithm and work callback as its possible they will not be
* called on every tick they otherwise would be. You should be able to
* design around this though if you are aware of the limitations.
*/
public void update() {
applyPerdition();
applyWork();
validateEnergy();
}
private void applyPerdition() {
if (perditionTracker.markTimeIfDelay(receptor.getWorldObj(), 1) && energyStored > 0) {
float newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
if (newEnergy == 0 || newEnergy < energyStored) {
energyStored = newEnergy;
} else {
energyStored = DEFUALT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
}
validateEnergy();
}
}
private void applyWork() {
if (energyStored >= activationEnergy) {
if (doWorkTracker.markTimeIfDelay(receptor.getWorldObj(), 1)) {
receptor.doWork(this);
}
}
}
private void updateSources(ForgeDirection source) {
if (sourcesTracker.markTimeIfDelay(receptor.getWorldObj(), 1)) {
for (int i = 0; i < 6; ++i) {
powerSources[i] -= sourcesTracker.durationOfLastDelay();
if (powerSources[i] < 0) {
powerSources[i] = 0;
}
}
}
if (source != null)
powerSources[source.ordinal()] = 10;
}
/**
* Extract energy from the PowerHandler. You must call this even if doWork()
* triggers.
*
* @param min
* @param max
* @param doUse
* @return amount used
*/
public float useEnergy(float min, float max, boolean doUse) {
applyPerdition();
float result = 0;
if (energyStored >= min) {
if (energyStored <= max) {
result = energyStored;
if (doUse) {
energyStored = 0;
}
} else {
result = max;
if (doUse) {
energyStored -= max;
}
}
}
validateEnergy();
return result;
}
public void readFromNBT(NBTTagCompound data) {
readFromNBT(data, "powerProvider");
}
public void readFromNBT(NBTTagCompound data, String tag) {
NBTTagCompound nbt = data.getCompoundTag(tag);
energyStored = nbt.getFloat("storedEnergy");
}
public void writeToNBT(NBTTagCompound data) {
writeToNBT(data, "powerProvider");
}
public void writeToNBT(NBTTagCompound data, String tag) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setFloat("storedEnergy", energyStored);
data.setCompoundTag(tag, nbt);
}
public final class PowerReceiver {
private PowerReceiver() {
}
public float getMinEnergyReceived() {
return minEnergyReceived;
}
public float getMaxEnergyReceived() {
return maxEnergyReceived;
}
public float getMaxEnergyStored() {
return maxEnergyStored;
}
public float getActivationEnergy() {
return activationEnergy;
}
public float getEnergyStored() {
return energyStored;
}
public Type getType() {
return type;
}
public void update() {
PowerHandler.this.update();
}
/**
* The amount of power that this PowerHandler currently needs.
*
* @return
*/
public float powerRequest() {
return Math.min(maxEnergyReceived, maxEnergyStored - energyStored);
}
/**
* Add power to the PowerReceiver from an external source.
*
* @param quantity
* @param from
* @return the amount of power used
*/
public float receiveEnergy(Type source, final float quantity, ForgeDirection from) {
float used = quantity;
if (source == Type.ENGINE) {
if (used < minEnergyReceived) {
return 0;
} else if (used > maxEnergyReceived) {
used = maxEnergyReceived;
}
}
updateSources(from);
used = addEnergy(used);
applyWork();
if (source == Type.ENGINE && type.eatsEngineExcess()) {
return Math.min(quantity, maxEnergyReceived);
}
return used;
}
}
/**
*
* @return the amount the power changed by
*/
public float addEnergy(float quantity) {
energyStored += quantity;
if (energyStored > maxEnergyStored) {
quantity -= energyStored - maxEnergyStored;
energyStored = maxEnergyStored;
} else if (energyStored < 0) {
quantity -= energyStored;
energyStored = 0;
}
applyPerdition();
return quantity;
}
public void setEnergy(float quantity) {
this.energyStored = quantity;
validateEnergy();
}
public boolean isPowerSource(ForgeDirection from) {
return powerSources[from.ordinal()] != 0;
}
private void validateEnergy() {
if (energyStored < 0) {
energyStored = 0;
}
if (energyStored > maxEnergyStored) {
energyStored = maxEnergyStored;
}
}
}

View file

@ -1,187 +0,0 @@
/**
* 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.power;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.core.SafeTimeTracker;
public abstract class PowerProvider implements IPowerProvider {
protected int latency;
protected int minEnergyReceived;
protected int maxEnergyReceived;
protected int maxEnergyStored;
protected int minActivationEnergy;
protected float energyStored = 0;
protected int powerLoss = 1;
protected int powerLossRegularity = 1;
public SafeTimeTracker timeTracker = new SafeTimeTracker();
public SafeTimeTracker energyLossTracker = new SafeTimeTracker();
public int[] powerSources = { 0, 0, 0, 0, 0, 0 };
@Override
public SafeTimeTracker getTimeTracker() {
return this.timeTracker;
}
@Override
public int getLatency() {
return this.latency;
}
@Override
public int getMinEnergyReceived() {
return this.minEnergyReceived;
}
@Override
public int getMaxEnergyReceived() {
return this.maxEnergyReceived;
}
@Override
public int getMaxEnergyStored() {
return this.maxEnergyStored;
}
@Override
public int getActivationEnergy() {
return this.minActivationEnergy;
}
@Override
public float getEnergyStored() {
return this.energyStored;
}
@Override
public void configure(int latency, int minEnergyReceived, int maxEnergyReceived, int minActivationEnergy, int maxStoredEnergy) {
this.latency = latency;
this.minEnergyReceived = minEnergyReceived;
this.maxEnergyReceived = maxEnergyReceived;
this.maxEnergyStored = maxStoredEnergy;
this.minActivationEnergy = minActivationEnergy;
}
@Override
public void configurePowerPerdition(int powerLoss, int powerLossRegularity) {
this.powerLoss = powerLoss;
this.powerLossRegularity = powerLossRegularity;
}
@Override
public boolean update(IPowerReceptor receptor) {
if (!preConditions(receptor))
return false;
TileEntity tile = (TileEntity) receptor;
boolean result = false;
if (energyStored >= minActivationEnergy) {
if (latency == 0) {
receptor.doWork();
result = true;
} else {
if (timeTracker.markTimeIfDelay(tile.worldObj, latency)) {
receptor.doWork();
result = true;
}
}
}
if (powerLoss > 0 && energyLossTracker.markTimeIfDelay(tile.worldObj, powerLossRegularity)) {
energyStored -= powerLoss;
if (energyStored < 0) {
energyStored = 0;
}
}
for (int i = 0; i < 6; ++i) {
if (powerSources[i] > 0) {
powerSources[i]--;
}
}
return result;
}
@Override
public boolean preConditions(IPowerReceptor receptor) {
return true;
}
@Override
public float useEnergy(float min, float max, boolean doUse) {
float result = 0;
if (energyStored >= min) {
if (energyStored <= max) {
result = energyStored;
if (doUse) {
energyStored = 0;
}
} else {
result = max;
if (doUse) {
energyStored -= max;
}
}
}
return result;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
latency = nbttagcompound.getInteger("latency");
minEnergyReceived = nbttagcompound.getInteger("minEnergyReceived");
maxEnergyReceived = nbttagcompound.getInteger("maxEnergyReceived");
maxEnergyStored = nbttagcompound.getInteger("maxStoreEnergy");
minActivationEnergy = nbttagcompound.getInteger("minActivationEnergy");
try {
energyStored = nbttagcompound.getFloat("storedEnergy");
} catch (Throwable c) {
energyStored = 0;
}
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger("latency", latency);
nbttagcompound.setInteger("minEnergyReceived", minEnergyReceived);
nbttagcompound.setInteger("maxEnergyReceived", maxEnergyReceived);
nbttagcompound.setInteger("maxStoreEnergy", maxEnergyStored);
nbttagcompound.setInteger("minActivationEnergy", minActivationEnergy);
nbttagcompound.setFloat("storedEnergy", energyStored);
}
@Override
public void receiveEnergy(float quantity, ForgeDirection from) {
powerSources[from.ordinal()] = 2;
energyStored += quantity;
if (energyStored > maxEnergyStored) {
energyStored = maxEnergyStored;
}
}
@Override
public boolean isPowerSource(ForgeDirection from) {
return powerSources[from.ordinal()] != 0;
}
}

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.builders; package buildcraft.builders;
import java.util.Collection; import java.util.Collection;
@ -24,9 +22,10 @@ import buildcraft.BuildCraftBuilders;
import buildcraft.api.core.LaserKind; import buildcraft.api.core.LaserKind;
import buildcraft.api.core.Position; import buildcraft.api.core.Position;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.core.BlockIndex; import buildcraft.core.BlockIndex;
import buildcraft.core.Box; import buildcraft.core.Box;
import buildcraft.core.DefaultProps; import buildcraft.core.DefaultProps;
@ -50,18 +49,12 @@ import buildcraft.core.utils.Utils;
public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IPowerReceptor, IMachine { public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IPowerReceptor, IMachine {
private final ItemStack items[] = new ItemStack[28]; private final ItemStack items[] = new ItemStack[28];
private BptBuilderBase bluePrintBuilder; private BptBuilderBase bluePrintBuilder;
public @TileNetworkData public @TileNetworkData
Box box = new Box(); Box box = new Box();
private PowerHandler powerHandler;
private IPowerProvider powerProvider;
private LinkedList<BlockIndex> path; private LinkedList<BlockIndex> path;
private LinkedList<EntityLaser> pathLasers; private LinkedList<EntityLaser> pathLasers;
private EntityRobot builderRobot; private EntityRobot builderRobot;
private class PathIterator { private class PathIterator {
@ -170,16 +163,14 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
return true; return true;
} }
} }
public PathIterator currentPathIterator; public PathIterator currentPathIterator;
private boolean done = true; private boolean done = true;
public TileBuilder() { public TileBuilder() {
super(); super();
powerProvider = PowerFramework.currentFramework.createPowerProvider(); powerHandler = new PowerHandler(this, Type.MACHINE);
powerProvider.configure(10, 25, 25, 25, 25); powerHandler.configure(25, 25, 25, 25);
} }
@Override @Override
@ -272,7 +263,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
} }
@Override @Override
public void doWork() { public void doWork(PowerHandler workProvider) {
if (CoreProxy.proxy.isRenderWorld(worldObj)) if (CoreProxy.proxy.isRenderWorld(worldObj))
return; return;
@ -282,7 +273,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
if (builderRobot != null && !builderRobot.readyToBuild()) if (builderRobot != null && !builderRobot.readyToBuild())
return; return;
if (powerProvider.useEnergy(25, 25, true) < 25) if (powerHandler.useEnergy(25, 25, true) < 25)
return; return;
iterateBpt(); iterateBpt();
@ -526,13 +517,8 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
} }
@Override @Override
public void setPowerProvider(IPowerProvider provider) { public PowerReceiver getPowerReceiver(ForgeDirection side) {
powerProvider = provider; return powerHandler.getPowerReceiver();
}
@Override
public IPowerProvider getPowerProvider() {
return powerProvider;
} }
@Override @Override
@ -559,22 +545,19 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
@Override @Override
public void openChest() { public void openChest() {
} }
@Override @Override
public void closeChest() { public void closeChest() {
}
@Override
public int powerRequest(ForgeDirection from) {
if ((bluePrintBuilder != null || currentPathIterator != null) && !done)
return powerProvider.getMaxEnergyReceived();
else
return 0;
} }
// @Override
// public int powerRequest(ForgeDirection from) {
// if ((bluePrintBuilder != null || currentPathIterator != null) && !done)
// return powerProvider.getMaxEnergyReceived();
// else
// return 0;
// }
@Override @Override
public void updateEntity() { public void updateEntity() {

View file

@ -18,22 +18,23 @@ import buildcraft.api.filler.FillerManager;
import buildcraft.api.filler.IFillerPattern; import buildcraft.api.filler.IFillerPattern;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import buildcraft.api.gates.IActionReceptor; import buildcraft.api.gates.IActionReceptor;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.core.Box; import buildcraft.core.Box;
import buildcraft.core.IMachine; import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.PacketUpdate;
import buildcraft.core.network.TileNetworkData; import buildcraft.core.network.TileNetworkData;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.triggers.ActionMachineControl; import buildcraft.core.triggers.ActionMachineControl;
import buildcraft.core.triggers.ActionMachineControl.Mode; import buildcraft.core.triggers.ActionMachineControl.Mode;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import buildcraft.factory.TileMachine;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.ISidedInventory;
public class TileFiller extends TileMachine implements ISidedInventory, IPowerReceptor, IMachine, IActionReceptor { public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowerReceptor, IMachine, IActionReceptor {
private static int[] SLOTS_GRID = Utils.createSlotArray(0, 9); private static int[] SLOTS_GRID = Utils.createSlotArray(0, 9);
private static int[] SLOTS_INPUT = Utils.createSlotArray(9, 27); private static int[] SLOTS_INPUT = Utils.createSlotArray(9, 27);
@ -46,18 +47,18 @@ public class TileFiller extends TileMachine implements ISidedInventory, IPowerRe
public IFillerPattern currentPattern; public IFillerPattern currentPattern;
boolean forceDone = false; boolean forceDone = false;
private ItemStack contents[]; private ItemStack contents[];
IPowerProvider powerProvider; private PowerHandler powerHandler;
private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown; private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown;
public TileFiller() { public TileFiller() {
contents = new ItemStack[getSizeInventory()]; contents = new ItemStack[getSizeInventory()];
powerProvider = PowerFramework.currentFramework.createPowerProvider(); powerHandler = new PowerHandler(this, Type.MACHINE);
initPowerProvider(); initPowerProvider();
} }
private void initPowerProvider() { private void initPowerProvider() {
powerProvider.configure(20, 25, 50, 25, 100); powerHandler.configure(30, 50, 25, 100);
powerProvider.configurePowerPerdition(1, 1); powerHandler.configurePowerPerdition(1, 1);
} }
@Override @Override
@ -95,20 +96,20 @@ public class TileFiller extends TileMachine implements ISidedInventory, IPowerRe
return; return;
} }
if (powerProvider.getEnergyStored() >= 25) { if (powerHandler.getEnergyStored() >= 25) {
doWork(); doWork(powerHandler);
} }
} }
@Override @Override
public void doWork() { public void doWork(PowerHandler workProvider) {
if (CoreProxy.proxy.isRenderWorld(worldObj)) if (CoreProxy.proxy.isRenderWorld(worldObj))
return; return;
if (lastMode == Mode.Off) if (lastMode == Mode.Off)
return; return;
if (powerProvider.useEnergy(25, 25, true) < 25) if (powerHandler.useEnergy(25, 25, true) < 25)
return; return;
if (box.isInitialized() && currentPattern != null && !done) { if (box.isInitialized() && currentPattern != null && !done) {
@ -137,8 +138,8 @@ public class TileFiller extends TileMachine implements ISidedInventory, IPowerRe
} }
} }
if (powerProvider.getEnergyStored() >= 25) { if (powerHandler.getEnergyStored() >= 25) {
doWork(); doWork(workProvider);
} }
} }
@ -323,13 +324,8 @@ public class TileFiller extends TileMachine implements ISidedInventory, IPowerRe
} }
@Override @Override
public void setPowerProvider(IPowerProvider provider) { public PowerReceiver getPowerReceiver(ForgeDirection side) {
powerProvider = provider; return powerHandler.getPowerReceiver();
}
@Override
public IPowerProvider getPowerProvider() {
return powerProvider;
} }
@Override @Override

View file

@ -1,22 +0,0 @@
/**
* 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.core;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.PowerFramework;
public class RedstonePowerFramework extends PowerFramework {
@Override
public IPowerProvider createPowerProvider() {
return new RedstonePowerProvider();
}
}

View file

@ -1,75 +0,0 @@
/**
* 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.core;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import buildcraft.BuildCraftCore;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerProvider;
public class RedstonePowerProvider extends PowerProvider {
private boolean lastPower = false;
public RedstonePowerProvider() {
this.powerLoss = 0;
this.powerLossRegularity = 0;
}
@Override
public boolean preConditions(IPowerReceptor receptor) {
TileEntity tile = (TileEntity) receptor;
boolean currentPower = tile.worldObj.isBlockIndirectlyGettingPowered(tile.xCoord, tile.yCoord, tile.zCoord);
if (BuildCraftCore.continuousCurrentModel) {
if (currentPower)
return true;
} else if (currentPower != lastPower) {
lastPower = currentPower;
if (currentPower)
return true;
}
return false;
}
@Override
public float useEnergy(float min, float max, boolean doUse) {
return min;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
lastPower = nbttagcompound.getBoolean("lastPower");
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
nbttagcompound.setBoolean("lastPower", lastPower);
}
@Override
public void configure(int latency, int minEnergyReceived, int maxEnergyReceived, int minActivationEnergy, int maxStoredEnergy) {
super.configure(latency, minEnergyReceived, maxEnergyReceived, minActivationEnergy, maxStoredEnergy);
this.minActivationEnergy = 0;
this.energyStored = 1;
}
@Override
public void configurePowerPerdition(int powerLoss, int powerLossRegularity) {
}
}

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.core; package buildcraft.core;
import java.util.HashMap; import java.util.HashMap;
@ -22,6 +20,7 @@ import buildcraft.core.network.PacketUpdate;
import buildcraft.core.network.TilePacketWrapper; import buildcraft.core.network.TilePacketWrapper;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import net.minecraft.world.World;
public abstract class TileBuildCraft extends TileEntity implements ISynchronizedTile { public abstract class TileBuildCraft extends TileEntity implements ISynchronizedTile {
@ -29,10 +28,8 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
private static Map<Class, TilePacketWrapper> updateWrappers = new HashMap<Class, TilePacketWrapper>(); private static Map<Class, TilePacketWrapper> updateWrappers = new HashMap<Class, TilePacketWrapper>();
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static Map<Class, TilePacketWrapper> descriptionWrappers = new HashMap<Class, TilePacketWrapper>(); private static Map<Class, TilePacketWrapper> descriptionWrappers = new HashMap<Class, TilePacketWrapper>();
private final TilePacketWrapper descriptionPacket; private final TilePacketWrapper descriptionPacket;
private final TilePacketWrapper updatePacket; private final TilePacketWrapper updatePacket;
private boolean init = false; private boolean init = false;
public TileBuildCraft() { public TileBuildCraft() {
@ -58,8 +55,7 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
if (this instanceof IPowerReceptor) { if (this instanceof IPowerReceptor) {
IPowerReceptor receptor = ((IPowerReceptor) this); IPowerReceptor receptor = ((IPowerReceptor) this);
receptor.getPowerReceiver(null).update();
receptor.getPowerProvider().update(receptor);
} }
} }
@ -74,7 +70,6 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
} }
public void destroy() { public void destroy() {
} }
public void sendNetworkUpdate() { public void sendNetworkUpdate() {
@ -110,13 +105,10 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
@Override @Override
public void postPacketHandling(PacketUpdate packet) { public void postPacketHandling(PacketUpdate packet) {
} }
public boolean isInvNameLocalized() public boolean isInvNameLocalized() {
{
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
} }

View file

@ -15,23 +15,16 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon; import net.minecraft.util.Icon;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftEnergy;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.CreativeTabBuildCraft; import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.GuiIds;
import buildcraft.core.IItemPipe; import buildcraft.core.IItemPipe;
import buildcraft.core.liquids.LiquidUtils;
import buildcraft.core.proxy.CoreProxy;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.liquids.LiquidContainerRegistry;
public class BlockEngine extends BlockContainer { public class BlockEngine extends BlockContainer {
@ -71,15 +64,20 @@ public class BlockEngine extends BlockContainer {
} }
@Override @Override
public TileEntity createNewTileEntity(World var1) { public TileEntity createTileEntity(World world, int metadata) {
return new TileEngine(); if (metadata == 1)
return new TileEngineStone();
else if (metadata == 2)
return new TileEngineIron();
else
return new TileEngineWood();
} }
@Override @Override
public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side) { public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side) {
TileEntity tile = world.getBlockTileEntity(x, y, z); TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileEngine) { if (tile instanceof TileEngine) {
return ForgeDirection.getOrientation(((TileEngine) tile).orientation).getOpposite() == side; return ((TileEngine) tile).orientation.getOpposite() == side;
} }
return false; return false;
} }
@ -94,6 +92,15 @@ public class BlockEngine extends BlockContainer {
super.breakBlock(world, x, y, z, par5, par6); super.breakBlock(world, x, y, z, par5, par6);
} }
@Override
public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis) {
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileEngine) {
return ((TileEngine) tile).switchOrientation();
}
return false;
}
@Override @Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int side, float par7, float par8, float par9) { public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int side, float par7, float par8, float par9) {
@ -103,50 +110,15 @@ public class BlockEngine extends BlockContainer {
if (player.isSneaking()) if (player.isSneaking())
return false; return false;
// Switch orientation if whacked with a wrench.
Item equipped = player.getCurrentEquippedItem() != null ? player.getCurrentEquippedItem().getItem() : null;
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(player, i, j, k)) {
tile.switchOrientation();
((IToolWrench) equipped).wrenchUsed(player, i, j, k);
return true;
} else {
// Do not open guis when having a pipe in hand // Do not open guis when having a pipe in hand
if (player.getCurrentEquippedItem() != null) { if (player.getCurrentEquippedItem() != null) {
if (player.getCurrentEquippedItem().getItem() instanceof IItemPipe) { if (player.getCurrentEquippedItem().getItem() instanceof IItemPipe) {
return false; return false;
} }
if (tile.engine instanceof EngineIron) {
ItemStack current = player.getCurrentEquippedItem();
if (current != null && current.itemID != Item.bucketEmpty.itemID) {
if (CoreProxy.proxy.isSimulating(world)) {
if (LiquidUtils.handleRightClick(tile, ForgeDirection.getOrientation(side), player, true, false)) {
return true;
}
} else {
if (LiquidContainerRegistry.isContainer(current)) {
return true;
}
}
}
}
}
if (tile.engine instanceof EngineStone) {
if (!CoreProxy.proxy.isRenderWorld(tile.worldObj)) {
player.openGui(BuildCraftEnergy.instance, GuiIds.ENGINE_STONE, world, i, j, k);
}
return true;
} else if (tile.engine instanceof EngineIron) {
if (!CoreProxy.proxy.isRenderWorld(tile.worldObj)) {
player.openGui(BuildCraftEnergy.instance, GuiIds.ENGINE_IRON, world, i, j, k);
}
return true;
} }
if (tile instanceof TileEngine) {
return ((TileEngine) tile).onBlockActivated(player, ForgeDirection.getOrientation(side));
} }
return false; return false;
@ -155,7 +127,7 @@ public class BlockEngine extends BlockContainer {
@Override @Override
public void onPostBlockPlaced(World world, int x, int y, int z, int par5) { public void onPostBlockPlaced(World world, int x, int y, int z, int par5) {
TileEngine tile = (TileEngine) world.getBlockTileEntity(x, y, z); TileEngine tile = (TileEngine) world.getBlockTileEntity(x, y, z);
tile.orientation = ForgeDirection.UP.ordinal(); tile.orientation = ForgeDirection.UP;
tile.switchOrientation(); tile.switchOrientation();
} }
@ -215,4 +187,9 @@ public class BlockEngine extends BlockContainer {
return null; return null;
} }
} }
@Override
public TileEntity createNewTileEntity(World world) {
return null;
}
} }

View file

@ -37,7 +37,7 @@ public class BptBlockEngine extends BptBlock {
public void initializeFromWorld(BptSlotInfo bptSlot, IBptContext context, int x, int y, int z) { public void initializeFromWorld(BptSlotInfo bptSlot, IBptContext context, int x, int y, int z) {
TileEngine engine = (TileEngine) context.world().getBlockTileEntity(x, y, z); TileEngine engine = (TileEngine) context.world().getBlockTileEntity(x, y, z);
bptSlot.cpt.setInteger("orientation", engine.engine.orientation.ordinal()); bptSlot.cpt.setInteger("orientation", engine.orientation.ordinal());
} }
@Override @Override
@ -46,7 +46,7 @@ public class BptBlockEngine extends BptBlock {
TileEngine engine = (TileEngine) context.world().getBlockTileEntity(slot.x, slot.y, slot.z); TileEngine engine = (TileEngine) context.world().getBlockTileEntity(slot.x, slot.y, slot.z);
engine.orientation = slot.cpt.getInteger("orientation"); engine.orientation = ForgeDirection.getOrientation(slot.cpt.getInteger("orientation"));
} }
@Override @Override

View file

@ -8,7 +8,10 @@ public class EnergyProxy {
public static EnergyProxy proxy; public static EnergyProxy proxy;
public void registerTileEntities() { public void registerTileEntities() {
GameRegistry.registerTileEntity(TileEngine.class, "net.minecraft.src.buildcraft.energy.Engine"); GameRegistry.registerTileEntity(TileEngineLegacy.class, "net.minecraft.src.buildcraft.energy.Engine");
GameRegistry.registerTileEntity(TileEngineWood.class, "net.minecraft.src.buildcraft.energy.TileEngineWood");
GameRegistry.registerTileEntity(TileEngineStone.class, "net.minecraft.src.buildcraft.energy.TileEngineStone");
GameRegistry.registerTileEntity(TileEngineIron.class, "net.minecraft.src.buildcraft.energy.TileEngineIron");
} }
public void registerBlockRenderers() { public void registerBlockRenderers() {

View file

@ -1,212 +0,0 @@
/**
* 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.energy;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.LiquidStack;
import net.minecraftforge.liquids.LiquidTank;
import buildcraft.core.network.TileNetworkData;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.energy.gui.ContainerEngine;
public abstract class Engine {
public int maxEnergy;
protected float currentOutput = 0;
public @TileNetworkData
float progress;
public @TileNetworkData
ForgeDirection orientation;
public float energy;
public @TileNetworkData
EnergyStage energyStage = EnergyStage.Blue;
public int maxEnergyExtracted = 1;
protected TileEngine tile;
public enum EnergyStage {
Blue, Green, Yellow, Red, Explosion
}
public Engine(TileEngine tile) {
this.tile = tile;
}
protected void computeEnergyStage() {
double level = energy / (double) maxEnergy * 100.0;
if (level <= 25.0) {
energyStage = EnergyStage.Blue;
} else if (level <= 50.0) {
energyStage = EnergyStage.Green;
} else if (level <= 75.0) {
energyStage = EnergyStage.Yellow;
} else if (level <= 100.0) {
energyStage = EnergyStage.Red;
} else {
energyStage = EnergyStage.Explosion;
}
}
public final EnergyStage getEnergyStage() {
if (!CoreProxy.proxy.isRenderWorld(tile.worldObj)) {
computeEnergyStage();
}
return energyStage;
}
public void update() {
if (!tile.isRedstonePowered) {
if (energy >= 1) {
energy -= 1;
} else if (energy < 1) {
energy = 0;
}
}
}
public abstract String getTextureFile();
public abstract int explosionRange();
public int minEnergyReceived() {
return 2;
}
public abstract int maxEnergyReceived();
public abstract float getPistonSpeed();
public abstract boolean isBurning();
public abstract void delete();
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) {
return 0;
}
public void addEnergy(float addition) {
energy += addition;
if (getEnergyStage() == EnergyStage.Explosion) {
tile.worldObj.createExplosion(null, tile.xCoord, tile.yCoord, tile.zCoord, explosionRange(), true);
}
if (energy > maxEnergy) {
energy = maxEnergy;
}
}
public float extractEnergy(int min, int max, boolean doExtract) {
if (energy < min)
return 0;
int actualMax;
if (max > maxEnergyExtracted) {
actualMax = maxEnergyExtracted;
} else {
actualMax = max;
}
if (actualMax < min)
return 0;
float extracted;
if (energy >= actualMax) {
extracted = actualMax;
if (doExtract) {
energy -= actualMax;
}
} else {
extracted = energy;
if (doExtract) {
energy = 0;
}
}
return extracted;
}
public abstract int getScaledBurnTime(int i);
public abstract void burn();
public void readFromNBT(NBTTagCompound nbttagcompound) {
}
public void writeToNBT(NBTTagCompound nbttagcompound) {
}
public void getGUINetworkData(int i, int j) {
}
public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) {
}
public boolean isActive() {
return true;
}
public int getHeat() {
return 0;
}
public float getEnergyStored() {
return energy;
}
public float getCurrentOutput() {
return currentOutput;
}
/* ILIQUIDCONTAINER */
public LiquidTank[] getLiquidSlots() {
return new LiquidTank[0];
}
/* IINVENTORY */
public int getSizeInventory() {
return 0;
}
public ItemStack getStackInSlot(int i) {
return null;
}
public ItemStack decrStackSize(int i, int j) {
return null;
}
public ItemStack getStackInSlotOnClosing(int i) {
return getStackInSlot(i);
}
public void setInventorySlotContents(int i, ItemStack itemstack) {
}
public boolean isStackValidForSlot(int i, ItemStack itemstack){
return false;
}
public abstract ILiquidTank getTank(ForgeDirection direction, LiquidStack type);
}

View file

@ -1,446 +0,0 @@
/**
* 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.energy;
import net.minecraft.block.Block;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidStack;
import net.minecraftforge.liquids.LiquidTank;
import buildcraft.api.fuels.IronEngineCoolant;
import buildcraft.api.fuels.IronEngineFuel;
import buildcraft.core.DefaultProps;
import buildcraft.core.utils.Utils;
import buildcraft.energy.gui.ContainerEngine;
public class EngineIron extends Engine {
public static int MAX_LIQUID = LiquidContainerRegistry.BUCKET_VOLUME * 10;
public static int MAX_HEAT = 100000;
public static int COOLANT_THRESHOLD = 49000;
private ItemStack itemInInventory;
int burnTime = 0;
int heat = 0;
private LiquidTank fuelTank;
private LiquidTank coolantTank;
private IronEngineFuel currentFuel = null;
public int penaltyCooling = 0;
boolean lastPowered = false;
public EngineIron(TileEngine engine) {
super(engine);
maxEnergy = 100000;
maxEnergyExtracted = 500;
fuelTank = new LiquidTank(MAX_LIQUID);
coolantTank = new LiquidTank(MAX_LIQUID);
}
@Override
public String getTextureFile() {
return DefaultProps.TEXTURE_PATH_BLOCKS + "/base_iron.png";
}
@Override
public int explosionRange() {
return 8;
}
@Override
public int maxEnergyReceived() {
return 2000;
}
@Override
public float getPistonSpeed() {
switch (getEnergyStage()) {
case Blue:
return 0.04F;
case Green:
return 0.05F;
case Yellow:
return 0.06F;
case Red:
return 0.07F;
default:
return 0.0f;
}
}
@Override
public boolean isBurning() {
LiquidStack fuel = fuelTank.getLiquid();
return fuel != null && fuel.amount > 0 && penaltyCooling == 0 && tile.isRedstonePowered;
}
@Override
public void burn() {
currentOutput = 0;
LiquidStack fuel = this.fuelTank.getLiquid();
if(currentFuel == null) {
currentFuel = IronEngineFuel.getFuelForLiquid(fuel);
}
if (currentFuel == null)
return;
if (penaltyCooling <= 0 && tile.isRedstonePowered) {
lastPowered = true;
if (burnTime > 0 || fuel.amount > 0) {
if (burnTime > 0) {
burnTime--;
}
if (burnTime <= 0) {
if(fuel != null) {
if (--fuel.amount <= 0) {
fuelTank.setLiquid(null);
}
burnTime = currentFuel.totalBurningTime / LiquidContainerRegistry.BUCKET_VOLUME;
} else {
currentFuel = null;
return;
}
}
currentOutput = currentFuel.powerPerCycle;
addEnergy(currentFuel.powerPerCycle);
heat += currentFuel.powerPerCycle;
}
} else if (penaltyCooling <= 0) {
if (lastPowered) {
lastPowered = false;
penaltyCooling = 30 * 20;
// 30 sec of penalty on top of the cooling
}
}
}
@Override
public void update() {
super.update();
if (itemInInventory != null) {
LiquidStack liquid;
if (Block.ice.blockID == itemInInventory.itemID && heat > COOLANT_THRESHOLD) {
liquid = LiquidContainerRegistry.getLiquidForFilledItem(new ItemStack(Item.bucketWater));
} else {
liquid = LiquidContainerRegistry.getLiquidForFilledItem(itemInInventory);
}
if (liquid != null) {
if (fill(ForgeDirection.UNKNOWN, liquid, false) == liquid.amount) {
fill(ForgeDirection.UNKNOWN, liquid, true);
tile.setInventorySlotContents(0, Utils.consumeItem(itemInInventory));
}
}
}
if (heat > COOLANT_THRESHOLD) {
int extraHeat = heat - COOLANT_THRESHOLD;
LiquidStack coolant = this.coolantTank.getLiquid();
IronEngineCoolant currentCoolant = IronEngineCoolant.getCoolantForLiquid(coolant);
if (currentCoolant != null) {
if (coolant.amount * currentCoolant.coolingPerUnit > extraHeat) {
coolant.amount -= Math.round(extraHeat / currentCoolant.coolingPerUnit);
heat = COOLANT_THRESHOLD;
} else {
heat -= coolant.amount * currentCoolant.coolingPerUnit;
coolantTank.setLiquid(null);
}
}
}
if (heat > 0 && (penaltyCooling > 0 || !tile.isRedstonePowered)) {
heat -= 10;
}
if (heat <= 0) {
heat = 0;
}
if (heat == 0 && penaltyCooling > 0) {
penaltyCooling--;
}
}
@Override
public void computeEnergyStage() {
if (heat <= MAX_HEAT / 4) {
energyStage = EnergyStage.Blue;
} else if (heat <= MAX_HEAT / 2) {
energyStage = EnergyStage.Green;
} else if (heat <= MAX_HEAT * 3F / 4F) {
energyStage = EnergyStage.Yellow;
} else if (heat <= MAX_HEAT) {
energyStage = EnergyStage.Red;
} else {
energyStage = EnergyStage.Explosion;
}
}
@Override
public int getScaledBurnTime(int i) {
return this.fuelTank.getLiquid() != null ? (int) (((float) this.fuelTank.getLiquid().amount / (float) (MAX_LIQUID)) * i) : 0;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
if (nbttagcompound.hasKey("liquidId")) {
fuelTank.setLiquid(new LiquidStack(nbttagcompound.getInteger("liquidId"), nbttagcompound.getInteger("liquidQty"), nbttagcompound
.getInteger("liquidMeta")));
} else {
fuelTank.readFromNBT(nbttagcompound.getCompoundTag("fuelTank"));
}
burnTime = nbttagcompound.getInteger("burnTime");
if (nbttagcompound.hasKey("coolantId")) {
coolantTank.setLiquid(new LiquidStack(nbttagcompound.getInteger("coolantId"), nbttagcompound.getInteger("coolantQty"), nbttagcompound
.getInteger("coolantMeta")));
} else {
coolantTank.readFromNBT(nbttagcompound.getCompoundTag("coolantTank"));
}
heat = nbttagcompound.getInteger("heat");
penaltyCooling = nbttagcompound.getInteger("penaltyCooling");
if (nbttagcompound.hasKey("itemInInventory")) {
NBTTagCompound cpt = nbttagcompound.getCompoundTag("itemInInventory");
itemInInventory = ItemStack.loadItemStackFromNBT(cpt);
}
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setTag("fuelTank", fuelTank.writeToNBT(new NBTTagCompound()));
nbttagcompound.setTag("coolantTank", coolantTank.writeToNBT(new NBTTagCompound()));
nbttagcompound.setInteger("burnTime", burnTime);
nbttagcompound.setInteger("heat", heat);
nbttagcompound.setInteger("penaltyCooling", penaltyCooling);
if (itemInInventory != null) {
NBTTagCompound cpt = new NBTTagCompound();
itemInInventory.writeToNBT(cpt);
nbttagcompound.setTag("itemInInventory", cpt);
}
}
public int getScaledCoolant(int i) {
return coolantTank.getLiquid() != null ? (int) (((float) coolantTank.getLiquid().amount / (float) (MAX_LIQUID)) * i) : 0;
}
@Override
public void delete() {
ItemStack stack = tile.getStackInSlot(0);
if (stack != null) {
Utils.dropItems(tile.worldObj, stack, tile.xCoord, tile.yCoord, tile.zCoord);
}
}
@Override
public void getGUINetworkData(int i, int j) {
switch (i) {
case 0:
int iEnergy = Math.round(energy * 10);
iEnergy = (iEnergy & 0xffff0000) | (j & 0xffff);
energy = iEnergy / 10;
break;
case 1:
iEnergy = Math.round(energy * 10);
iEnergy = (iEnergy & 0xffff) | ((j & 0xffff) << 16);
energy = iEnergy / 10;
break;
case 2:
currentOutput = j / 10;
break;
case 3:
heat = (heat & 0xffff0000) | (j & 0xffff);
break;
case 4:
heat = (heat & 0xffff) | ((j & 0xffff) << 16);
break;
case 5:
if (fuelTank.getLiquid() == null) {
fuelTank.setLiquid(new LiquidStack(0, j));
} else {
fuelTank.getLiquid().amount = j;
}
break;
case 6:
if (fuelTank.getLiquid() == null) {
fuelTank.setLiquid(new LiquidStack(j, 0));
} else {
fuelTank.setLiquid(new LiquidStack(j,fuelTank.getLiquid().amount,fuelTank.getLiquid().itemMeta));
}
break;
case 7:
if (coolantTank.getLiquid() == null) {
coolantTank.setLiquid(new LiquidStack(0, j));
} else {
coolantTank.getLiquid().amount = j;
}
break;
case 8:
if (coolantTank.getLiquid() == null) {
coolantTank.setLiquid(new LiquidStack(j, 0));
} else {
coolantTank.setLiquid(new LiquidStack(j,coolantTank.getLiquid().amount,coolantTank.getLiquid().itemMeta));
}
break;
case 9:
if (fuelTank.getLiquid() == null) {
fuelTank.setLiquid(new LiquidStack(0, 0, j));
} else {
fuelTank.setLiquid(new LiquidStack(fuelTank.getLiquid().itemID,fuelTank.getLiquid().amount,j));
}
break;
case 10:
if (coolantTank.getLiquid() == null) {
coolantTank.setLiquid(new LiquidStack(0, 0, j));
} else {
coolantTank.setLiquid(new LiquidStack(coolantTank.getLiquid().itemID,coolantTank.getLiquid().amount,j));
}
}
}
@Override
public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) {
iCrafting.sendProgressBarUpdate(containerEngine, 0, Math.round(energy * 10) & 0xffff);
iCrafting.sendProgressBarUpdate(containerEngine, 1, (Math.round(energy * 10) & 0xffff0000) >> 16);
iCrafting.sendProgressBarUpdate(containerEngine, 2, Math.round(currentOutput * 10));
iCrafting.sendProgressBarUpdate(containerEngine, 3, heat & 0xffff);
iCrafting.sendProgressBarUpdate(containerEngine, 4, (heat & 0xffff0000) >> 16);
iCrafting.sendProgressBarUpdate(containerEngine, 5, fuelTank.getLiquid() != null ? fuelTank.getLiquid().amount : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 6, fuelTank.getLiquid() != null ? fuelTank.getLiquid().itemID : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 7, coolantTank.getLiquid() != null ? coolantTank.getLiquid().amount : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 8, coolantTank.getLiquid() != null ? coolantTank.getLiquid().itemID : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 9, fuelTank.getLiquid() != null ? fuelTank.getLiquid().itemMeta : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 10, coolantTank.getLiquid() != null ? coolantTank.getLiquid().itemMeta : 0);
}
@Override
public boolean isActive() {
return penaltyCooling <= 0;
}
@Override
public int getHeat() {
return heat;
}
/* ITANKCONTAINER */
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) {
// Handle coolant
if (IronEngineCoolant.getCoolantForLiquid(resource) != null)
return fillCoolant(from, resource, doFill);
if (IronEngineFuel.getFuelForLiquid(resource) != null)
return fuelTank.fill(resource, doFill);
return 0;
}
private int fillCoolant(ForgeDirection from, LiquidStack resource, boolean doFill) {
return coolantTank.fill(resource, doFill);
}
@Override
public LiquidTank[] getLiquidSlots() {
return new LiquidTank[] { fuelTank, coolantTank };
}
/* IINVENTORY */
@Override
public int getSizeInventory() {
return 1;
}
@Override
public ItemStack getStackInSlot(int i) {
return itemInInventory;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
itemInInventory = itemstack;
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
if (itemInInventory != null) {
if (itemInInventory.stackSize <= 0) {
itemInInventory = null;
return null;
}
ItemStack newStack = itemInInventory;
if (amount >= newStack.stackSize) {
itemInInventory = null;
} else {
newStack = itemInInventory.splitStack(amount);
}
return newStack;
}
return null;
}
@Override
public boolean isStackValidForSlot(int i, ItemStack itemstack) {
if (itemstack == null) return false;
if (Block.ice.blockID == itemstack.itemID) return true;
return LiquidContainerRegistry.getLiquidForFilledItem(itemstack) != null;
}
@Override
public ItemStack getStackInSlotOnClosing(int var1) {
if (itemInInventory == null)
return null;
ItemStack toReturn = itemInInventory;
itemInInventory = null;
return toReturn;
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) {
switch (direction) {
case UP:
return fuelTank;
case DOWN:
return coolantTank;
default:
return null;
}
}
public LiquidStack getFuel() {
return fuelTank.getLiquid();
}
public LiquidStack getCoolant() {
return coolantTank.getLiquid();
}
}

View file

@ -1,234 +0,0 @@
/**
* 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.energy;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.LiquidStack;
import buildcraft.core.DefaultProps;
import buildcraft.core.utils.Utils;
import buildcraft.energy.gui.ContainerEngine;
public class EngineStone extends Engine {
final float maxProduction = 1f;
final float minProduction = maxProduction / 3;
final float target = 0.375f;
final float kp = 1f;
final float ki = 0.05f;
final float eLimit = (maxProduction - minProduction) / ki;
int burnTime = 0;
int totalBurnTime = 0;
float esum = 0;
private ItemStack itemInInventory;
public EngineStone(TileEngine engine) {
super(engine);
maxEnergy = 10000;
maxEnergyExtracted = 100;
}
@Override
public String getTextureFile() {
return DefaultProps.TEXTURE_PATH_BLOCKS + "/base_stone.png";
}
@Override
public int explosionRange() {
return 4;
}
@Override
public int maxEnergyReceived() {
return 200;
}
@Override
public float getPistonSpeed() {
switch (getEnergyStage()) {
case Blue:
return 0.02F;
case Green:
return 0.04F;
case Yellow:
return 0.08F;
case Red:
return 0.16F;
default:
return 0;
}
}
@Override
public boolean isBurning() {
return burnTime > 0;
}
@Override
public void burn() {
currentOutput = 0;
if (burnTime > 0) {
burnTime--;
float e = target * maxEnergy - energy;
esum = Math.min(Math.max(esum + e, -eLimit), eLimit);
currentOutput = Math.min(Math.max(e * kp + esum * ki, minProduction), maxProduction);
addEnergy(currentOutput);
}
if (burnTime == 0 && tile.isRedstonePowered) {
burnTime = totalBurnTime = getItemBurnTime(tile.getStackInSlot(0));
if (burnTime > 0) {
tile.setInventorySlotContents(0, Utils.consumeItem(tile.getStackInSlot(0)));
}
}
}
@Override
public int getScaledBurnTime(int i) {
return (int) (((float) burnTime / (float) totalBurnTime) * i);
}
private int getItemBurnTime(ItemStack itemstack) {
if (itemstack == null)
return 0;
return TileEntityFurnace.getItemBurnTime(itemstack);
}
/* SAVING & LOADING */
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
burnTime = nbttagcompound.getInteger("burnTime");
totalBurnTime = nbttagcompound.getInteger("totalBurnTime");
if (nbttagcompound.hasKey("itemInInventory")) {
NBTTagCompound cpt = nbttagcompound.getCompoundTag("itemInInventory");
itemInInventory = ItemStack.loadItemStackFromNBT(cpt);
}
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger("burnTime", burnTime);
nbttagcompound.setInteger("totalBurnTime", totalBurnTime);
if (itemInInventory != null) {
NBTTagCompound cpt = new NBTTagCompound();
itemInInventory.writeToNBT(cpt);
nbttagcompound.setTag("itemInInventory", cpt);
}
}
@Override
public void delete() {
ItemStack stack = tile.getStackInSlot(0);
if (stack != null) {
Utils.dropItems(tile.worldObj, stack, tile.xCoord, tile.yCoord, tile.zCoord);
}
}
@Override
public void getGUINetworkData(int i, int j) {
switch (i) {
case 0:
energy = j;
break;
case 1:
currentOutput = j / 100f;
break;
case 2:
burnTime = j;
break;
case 3:
totalBurnTime = j;
break;
}
}
@Override
public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) {
iCrafting.sendProgressBarUpdate(containerEngine, 0, Math.round(energy));
iCrafting.sendProgressBarUpdate(containerEngine, 1, Math.round(currentOutput * 100f));
iCrafting.sendProgressBarUpdate(containerEngine, 2, burnTime);
iCrafting.sendProgressBarUpdate(containerEngine, 3, totalBurnTime);
}
@Override
public int getHeat() {
return Math.round(energy);
}
/* IINVENTORY */
@Override
public int getSizeInventory() {
return 1;
}
@Override
public ItemStack getStackInSlot(int i) {
return itemInInventory;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
itemInInventory = itemstack;
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
if (itemInInventory != null) {
if (itemInInventory.stackSize <= 0) {
itemInInventory = null;
return null;
}
ItemStack newStack = itemInInventory;
if (amount >= newStack.stackSize) {
itemInInventory = null;
} else {
newStack = itemInInventory.splitStack(amount);
}
return newStack;
}
return null;
}
@Override
public boolean isStackValidForSlot(int i, ItemStack itemstack) {
return getItemBurnTime(itemstack) > 0;
}
@Override
public ItemStack getStackInSlotOnClosing(int var1) {
if (itemInInventory == null)
return null;
ItemStack toReturn = itemInInventory;
itemInInventory = null;
return toReturn;
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) {
return null;
}
}

View file

@ -1,106 +0,0 @@
/**
* 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.energy;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.LiquidStack;
import buildcraft.core.DefaultProps;
public class EngineWood extends Engine {
public EngineWood(TileEngine engine) {
super(engine);
maxEnergy = 1000;
}
@Override
public String getTextureFile() {
return DefaultProps.TEXTURE_PATH_BLOCKS + "/base_wood.png";
}
@Override
public int explosionRange() {
return 1;
}
@Override
public int minEnergyReceived() {
return 1;
}
@Override
public int maxEnergyReceived() {
return 50;
}
@Override
protected void computeEnergyStage() {
double level = energy / (double) maxEnergy * 100.0;
if (level <= 25.0) {
energyStage = EnergyStage.Blue;
} else if (level <= 50.0) {
energyStage = EnergyStage.Green;
} else if (level <= 75.0) {
energyStage = EnergyStage.Yellow;
} else {
energyStage = EnergyStage.Red;
}
}
@Override
public float getPistonSpeed() {
switch (getEnergyStage()) {
case Blue:
return 0.01F;
case Green:
return 0.02F;
case Yellow:
return 0.04F;
case Red:
return 0.08F;
default:
return 0;
}
}
@Override
public void update() {
super.update();
if (tile.isRedstonePowered) {
if ((tile.worldObj.getWorldTime() % 20) == 0) {
addEnergy(1);
}
}
}
@Override
public boolean isBurning() {
return tile.isRedstonePowered;
}
@Override
public int getScaledBurnTime(int i) {
return 0;
}
@Override
public void delete() {
}
@Override
public void burn() {
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) {
return null;
}
}

View file

@ -1,15 +0,0 @@
/**
* 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.energy;
public interface IEngineProvider {
public Engine getEngine();
}

View file

@ -1,22 +0,0 @@
/**
* 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.energy;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.PowerFramework;
public class PneumaticPowerFramework extends PowerFramework {
@Override
public IPowerProvider createPowerProvider() {
return new PneumaticPowerProvider();
}
}

View file

@ -1,23 +0,0 @@
/**
* 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.energy;
import buildcraft.api.power.PowerProvider;
public class PneumaticPowerProvider extends PowerProvider {
@Override
public void configure(int latency, int minEnergyReceived, int maxEnergyReceived, int minActivationEnergy, int maxStoredEnergy) {
super.configure(latency, minEnergyReceived, maxEnergyReceived, minActivationEnergy, maxStoredEnergy);
this.latency = 0;
}
}

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.energy; package buildcraft.energy;
import java.util.LinkedList; import java.util.LinkedList;
@ -15,66 +13,144 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidStack;
import net.minecraftforge.liquids.LiquidTank;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftEnergy; import buildcraft.BuildCraftEnergy;
import buildcraft.api.core.Position; import buildcraft.api.core.Position;
import buildcraft.api.gates.IOverrideDefaultTriggers; import buildcraft.api.gates.IOverrideDefaultTriggers;
import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITrigger;
import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerEmitter;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerProvider; import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.api.transport.IPipeConnection; import buildcraft.api.transport.IPipeConnection;
import buildcraft.core.IBuilderInventory; import buildcraft.core.TileBuffer;
import buildcraft.core.TileBuildCraft; import buildcraft.core.TileBuildCraft;
import buildcraft.core.network.PacketUpdate; import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.network.TileNetworkData; import buildcraft.core.network.TileNetworkData;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.energy.gui.ContainerEngine;
import net.minecraft.inventory.ICrafting;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagFloat;
//TODO: All Engines need to take func_48081_b into account public abstract class TileEngine extends TileBuildCraft implements IPowerReceptor, IPowerEmitter, IInventory, IOverrideDefaultTriggers, IPipeConnection {
public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInventory, ITankContainer, IEngineProvider, IOverrideDefaultTriggers, public enum EnergyStage {
IPipeConnection, IBuilderInventory {
public @TileNetworkData
Engine engine;
public @TileNetworkData
int progressPart = 0;
public @TileNetworkData
float serverPistonSpeed = 0;
public @TileNetworkData
boolean isActive = false; // Used for SMP synch
boolean lastPower = false;
public int orientation;
IPowerProvider provider;
BLUE, GREEN, YELLOW, RED, OVERHEAT
}
public static final float MIN_HEAT = 20;
public static final float IDEAL_HEAT = 100;
public static final float MAX_HEAT = 250;
protected int progressPart = 0;
protected boolean lastPower = false;
protected PowerHandler powerHandler;
public float currentOutput = 0;
public boolean isRedstonePowered = false; public boolean isRedstonePowered = false;
public TileBuffer[] tileCache;
public float progress;
public float energy;
public float heat = MIN_HEAT;
private final SimpleInventory inv;
//
public @TileNetworkData
EnergyStage energyStage = EnergyStage.BLUE;
public @TileNetworkData
ForgeDirection orientation = ForgeDirection.UP;
public @TileNetworkData
boolean isPumping = false; // Used for SMP synch
public TileEngine() { public TileEngine(int invSize) {
provider = PowerFramework.currentFramework.createPowerProvider(); powerHandler = new PowerHandler(this, Type.ENGINE);
provider.configurePowerPerdition(1, 100); powerHandler.configurePowerPerdition(1, 100);
inv = new SimpleInventory(invSize, "Engine", 64);
} }
@Override @Override
public void initialize() { public void initialize() {
if (!CoreProxy.proxy.isRenderWorld(worldObj)) { if (!CoreProxy.proxy.isRenderWorld(worldObj)) {
if (engine == null) { tileCache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, true);
createEngineIfNeeded(); powerHandler.configure(minEnergyReceived(), maxEnergyReceived(), 1, getMaxEnergy());
checkRedstonePower();
}
} }
engine.orientation = ForgeDirection.VALID_DIRECTIONS[orientation]; public abstract String getTextureFile();
provider.configure(0, engine.minEnergyReceived(), engine.maxEnergyReceived(), 1, engine.maxEnergy);
checkRedstonePower(); public boolean onBlockActivated(EntityPlayer player, ForgeDirection side) {
return false;
}
public float getEnergyLevel() {
return energy / getMaxEnergy();
}
protected EnergyStage computeEnergyStage() {
float energyLevel = getHeatLevel();
if (energyLevel < 0.25f) {
return EnergyStage.BLUE;
} else if (energyLevel < 0.5f) {
return EnergyStage.GREEN;
} else if (energyLevel < 0.75f) {
return EnergyStage.YELLOW;
} else if (energyLevel < 1f) {
return EnergyStage.RED;
} else {
return EnergyStage.OVERHEAT;
}
}
public final EnergyStage getEnergyStage() {
if (CoreProxy.proxy.isSimulating(worldObj)) {
if (energyStage == EnergyStage.OVERHEAT) {
return energyStage;
}
EnergyStage newStage = computeEnergyStage();
if (energyStage != newStage) {
energyStage = newStage;
sendNetworkUpdate();
}
}
return energyStage;
}
public void updateHeatLevel() {
heat = ((MAX_HEAT - MIN_HEAT) * getEnergyLevel()) + MIN_HEAT;
}
public float getHeatLevel() {
return (heat - MIN_HEAT) / (MAX_HEAT - MIN_HEAT);
}
public float getIdealHeatLevel() {
return heat / IDEAL_HEAT;
}
public float getHeat() {
return heat;
}
public float getPistonSpeed() {
if (CoreProxy.proxy.isSimulating(worldObj)) {
return Math.max(0.16f * getHeatLevel(), 0.01f);
}
switch (getEnergyStage()) {
case BLUE:
return 0.02F;
case GREEN:
return 0.04F;
case YELLOW:
return 0.08F;
case RED:
return 0.16F;
default:
return 0;
} }
} }
@ -82,222 +158,214 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
if (engine == null)
return;
if (CoreProxy.proxy.isRenderWorld(worldObj)) { if (CoreProxy.proxy.isRenderWorld(worldObj)) {
if (progressPart != 0) { if (progressPart != 0) {
engine.progress += serverPistonSpeed; progress += getPistonSpeed();
if (engine.progress > 1) { if (progress > 1) {
progressPart = 0; progressPart = 0;
engine.progress = 0; progress = 0;
} }
} else if (this.isActive) { } else if (this.isPumping) {
progressPart = 1; progressPart = 1;
} }
return; return;
} }
engine.update(); updateHeatLevel();
engineUpdate();
float newPistonSpeed = engine.getPistonSpeed(); TileEntity tile = tileCache[orientation.ordinal()].getTile();
if (newPistonSpeed != serverPistonSpeed) {
serverPistonSpeed = newPistonSpeed;
sendNetworkUpdate();
}
if (progressPart != 0) { if (progressPart != 0) {
engine.progress += engine.getPistonSpeed(); progress += getPistonSpeed();
if (engine.progress > 0.5 && progressPart == 1) { if (progress > 0.5 && progressPart == 1) {
progressPart = 2; progressPart = 2;
sendPower(); // Comment out for constant power
Position pos = new Position(xCoord, yCoord, zCoord, engine.orientation); } else if (progress >= 1) {
pos.moveForwards(1.0); progress = 0;
TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
if (isPoweredTile(tile)) {
IPowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider();
float extracted = engine.extractEnergy(receptor.getMinEnergyReceived(),
Math.min(receptor.getMaxEnergyReceived(), receptor.getMaxEnergyStored() - (int) receptor.getEnergyStored()), true);
if (extracted > 0) {
receptor.receiveEnergy(extracted, engine.orientation.getOpposite());
}
}
} else if (engine.progress >= 1) {
engine.progress = 0;
progressPart = 0; progressPart = 0;
} }
} else if (isRedstonePowered && engine.isActive()) { } else if (isRedstonePowered && isActive()) {
if (isPoweredTile(tile, orientation)) {
Position pos = new Position(xCoord, yCoord, zCoord, engine.orientation); if (getPowerToExtract() > 0) {
pos.moveForwards(1.0);
TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
if (isPoweredTile(tile)) {
IPowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider();
if (engine.extractEnergy(receptor.getMinEnergyReceived(), receptor.getMaxEnergyReceived(), false) > 0) {
progressPart = 1; progressPart = 1;
setActive(true); setPumping(true);
} else { } else {
setActive(false); setPumping(false);
} }
} else { } else {
setActive(false); setPumping(false);
} }
} else { } else {
setActive(false); setPumping(false);
} }
engine.burn(); // Uncomment for constant power
// if (isRedstonePowered && isActive()) {
// sendPower();
// } else currentOutput = 0;
burn();
} }
private void setActive(boolean isActive) { private float getPowerToExtract() {
if (this.isActive == isActive) TileEntity tile = tileCache[orientation.ordinal()].getTile();
PowerReceiver receptor = ((IPowerReceptor) tile).getPowerReceiver(orientation.getOpposite());
return extractEnergy(receptor.getMinEnergyReceived(), receptor.getMaxEnergyReceived(), false); // Comment out for constant power
// return extractEnergy(0, getActualOutput(), false); // Uncomment for constant power
}
private void sendPower() {
TileEntity tile = tileCache[orientation.ordinal()].getTile();
if (isPoweredTile(tile, orientation)) {
PowerReceiver receptor = ((IPowerReceptor) tile).getPowerReceiver(orientation.getOpposite());
float extracted = getPowerToExtract();
if (extracted > 0) {
float needed = receptor.receiveEnergy(PowerHandler.Type.ENGINE, extracted, orientation.getOpposite());
extractEnergy(receptor.getMinEnergyReceived(), needed, true); // Comment out for constant power
// currentOutput = extractEnergy(0, needed, true); // Uncomment for constant power
}
}
}
// Uncomment out for constant power
// public float getActualOutput() {
// float heatLevel = getIdealHeatLevel();
// return getCurrentOutput() * heatLevel;
// }
protected void burn() {
}
protected void engineUpdate() {
if (!isRedstonePowered) {
if (energy >= 1) {
energy -= 1;
} else if (energy < 1) {
energy = 0;
}
}
}
public boolean isActive() {
return true;
}
protected final void setPumping(boolean isActive) {
if (this.isPumping == isActive)
return; return;
this.isActive = isActive; this.isPumping = isActive;
sendNetworkUpdate(); sendNetworkUpdate();
} }
private void createEngineIfNeeded() { public boolean switchOrientation() {
if (engine == null) { for (int i = orientation.ordinal() + 1; i <= orientation.ordinal() + 6; ++i) {
int kind = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); ForgeDirection o = ForgeDirection.VALID_DIRECTIONS[i % 6];
engine = newEngine(kind);
engine.orientation = ForgeDirection.VALID_DIRECTIONS[orientation];
worldObj.notifyBlockChange(xCoord, yCoord, zCoord, BuildCraftEnergy.engineBlock.blockID);
}
}
public void switchOrientation() {
for (int i = orientation + 1; i <= orientation + 6; ++i) {
ForgeDirection o = ForgeDirection.values()[i % 6];
Position pos = new Position(xCoord, yCoord, zCoord, o); Position pos = new Position(xCoord, yCoord, zCoord, o);
pos.moveForwards(1); pos.moveForwards(1);
TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
if (isPoweredTile(tile)) { if (isPoweredTile(tile, o)) {
if (engine != null) { orientation = o;
engine.orientation = o;
}
orientation = o.ordinal();
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlockId(xCoord, yCoord, zCoord)); worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlockId(xCoord, yCoord, zCoord));
return true;
}
}
return false;
}
@Override
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
orientation = ForgeDirection.getOrientation(data.getInteger("orientation"));
progress = data.getFloat("progress");
energy = data.getFloat("energyF");
NBTBase tag = data.getTag("heat");
if (tag instanceof NBTTagFloat) {
heat = data.getFloat("heat");
}
inv.readFromNBT(data);
}
@Override
public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
data.setInteger("orientation", orientation.ordinal());
data.setFloat("progress", progress);
data.setFloat("energyF", energy);
data.setFloat("heat", heat);
inv.writeToNBT(data);
}
public void getGUINetworkData(int id, int value) {
switch (id) {
case 0:
int iEnergy = Math.round(energy * 10);
iEnergy = (iEnergy & 0xffff0000) | (value & 0xffff);
energy = iEnergy / 10;
break;
case 1:
iEnergy = Math.round(energy * 10);
iEnergy = (iEnergy & 0xffff) | ((value & 0xffff) << 16);
energy = iEnergy / 10;
break;
case 2:
currentOutput = value / 10F;
break;
case 3:
heat = value / 100F;
break; break;
} }
} }
public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) {
iCrafting.sendProgressBarUpdate(containerEngine, 0, Math.round(energy * 10) & 0xffff);
iCrafting.sendProgressBarUpdate(containerEngine, 1, (Math.round(energy * 10) & 0xffff0000) >> 16);
iCrafting.sendProgressBarUpdate(containerEngine, 2, Math.round(currentOutput * 10));
iCrafting.sendProgressBarUpdate(containerEngine, 3, Math.round(heat * 100));
} }
public void delete() {
if (engine != null) {
engine.delete();
}
}
public Engine newEngine(int meta) {
if (meta == 1)
return new EngineStone(this);
else if (meta == 2)
return new EngineIron(this);
else
return new EngineWood(this);
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
int kind = nbttagcompound.getInteger("kind");
engine = newEngine(kind);
orientation = nbttagcompound.getInteger("orientation");
if (engine != null) {
engine.progress = nbttagcompound.getFloat("progress");
engine.energy = nbttagcompound.getFloat("energyF");
engine.orientation = ForgeDirection.values()[orientation];
}
if (engine != null) {
engine.readFromNBT(nbttagcompound);
}
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setInteger("kind", worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
if (engine != null) {
nbttagcompound.setInteger("orientation", orientation);
nbttagcompound.setFloat("progress", engine.progress);
nbttagcompound.setFloat("energyF", engine.energy);
}
if (engine != null) {
engine.writeToNBT(nbttagcompound);
}
}
/* IINVENTORY IMPLEMENTATION */ /* IINVENTORY IMPLEMENTATION */
@Override @Override
public int getSizeInventory() { public int getSizeInventory() {
if (engine != null) return inv.getSizeInventory();
return engine.getSizeInventory();
else
return 0;
} }
@Override @Override
public ItemStack getStackInSlot(int i) { public ItemStack getStackInSlot(int slot) {
if (engine != null) return inv.getStackInSlot(slot);
return engine.getStackInSlot(i);
else
return null;
} }
@Override @Override
public ItemStack decrStackSize(int i, int j) { public ItemStack decrStackSize(int slot, int amount) {
if (engine != null) return inv.decrStackSize(slot, amount);
return engine.decrStackSize(i, j);
else
return null;
} }
@Override @Override
public ItemStack getStackInSlotOnClosing(int i) { public ItemStack getStackInSlotOnClosing(int slot) {
if (engine != null) return inv.getStackInSlotOnClosing(slot);
return engine.getStackInSlotOnClosing(i);
else
return null;
} }
@Override @Override
public void setInventorySlotContents(int i, ItemStack itemstack) { public void setInventorySlotContents(int slot, ItemStack itemstack) {
if (engine != null) { inv.setInventorySlotContents(slot, itemstack);
engine.setInventorySlotContents(i, itemstack);
}
} }
@Override @Override
public boolean isStackValidForSlot(int i, ItemStack itemstack) { public boolean isStackValidForSlot(int i, ItemStack itemstack) {
if (engine != null){ return true;
return engine.isStackValidForSlot(i, itemstack);
} }
return false;
public void delete() {
Utils.dropItems(worldObj, inv, xCoord, yCoord, zCoord);
} }
@Override @Override
@ -316,71 +384,71 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
} }
/* STATE INFORMATION */ /* STATE INFORMATION */
public boolean isBurning() { public abstract boolean isBurning();
return engine != null && engine.isBurning();
}
public int getScaledBurnTime(int i) { public abstract int getScaledBurnTime(int scale);
if (engine != null)
return engine.getScaledBurnTime(i);
else
return 0;
}
/* SMP UPDATING */
@Override @Override
public Packet getDescriptionPacket() { public PowerReceiver getPowerReceiver(ForgeDirection side) {
createEngineIfNeeded(); return powerHandler.getPowerReceiver();
return super.getDescriptionPacket();
} }
@Override @Override
public Packet getUpdatePacket() { public void doWork(PowerHandler workProvider) {
if (engine != null) {
serverPistonSpeed = engine.getPistonSpeed();
}
return super.getUpdatePacket();
}
@Override
public void handleDescriptionPacket(PacketUpdate packet) {
createEngineIfNeeded();
super.handleDescriptionPacket(packet);
}
@Override
public void handleUpdatePacket(PacketUpdate packet) {
createEngineIfNeeded();
super.handleUpdatePacket(packet);
}
@Override
public void setPowerProvider(IPowerProvider provider) {
this.provider = provider;
}
@Override
public IPowerProvider getPowerProvider() {
return provider;
}
@Override
public void doWork() {
if (CoreProxy.proxy.isRenderWorld(worldObj)) if (CoreProxy.proxy.isRenderWorld(worldObj))
return; return;
engine.addEnergy(provider.useEnergy(1, engine.maxEnergyReceived(), true) * 0.95F); addEnergy(powerHandler.useEnergy(1, maxEnergyReceived(), true) * 0.95F);
} }
public boolean isPoweredTile(TileEntity tile) { public void addEnergy(float addition) {
if (tile instanceof IPowerReceptor) { energy += addition;
IPowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider();
return receptor != null && receptor.getClass().getSuperclass().equals(PowerProvider.class); if (getEnergyStage() == EnergyStage.OVERHEAT) {
worldObj.createExplosion(null, xCoord, yCoord, zCoord, explosionRange(), true);
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
if (energy > getMaxEnergy()) {
energy = getMaxEnergy();
}
}
public float extractEnergy(float min, float max, boolean doExtract) {
if (energy < min)
return 0;
float actualMax;
if (max > maxEnergyExtracted()) {
actualMax = maxEnergyExtracted();
} else {
actualMax = max;
}
if (actualMax < min)
return 0;
float extracted;
if (energy >= actualMax) {
extracted = actualMax;
if (doExtract) {
energy -= actualMax;
}
} else {
extracted = energy;
if (doExtract) {
energy = 0;
}
}
return extracted;
}
public boolean isPoweredTile(TileEntity tile, ForgeDirection side) {
if (tile instanceof IPowerReceptor) {
return ((IPowerReceptor) tile).getPowerReceiver(side.getOpposite()) != null;
} }
return false; return false;
@ -388,24 +456,30 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
@Override @Override
public void openChest() { public void openChest() {
} }
@Override @Override
public void closeChest() { public void closeChest() {
} }
@Override public abstract float getMaxEnergy();
public int powerRequest(ForgeDirection from) {
return 0; public float minEnergyReceived() {
return 2;
} }
@Override public abstract float maxEnergyReceived();
public Engine getEngine() {
return engine; public abstract float maxEnergyExtracted();
public abstract float explosionRange();
public float getEnergyStored() {
return energy;
} }
public abstract float getCurrentOutput();
@Override @Override
public LinkedList<ITrigger> getTriggers() { public LinkedList<ITrigger> getTriggers() {
LinkedList<ITrigger> triggers = new LinkedList<ITrigger>(); LinkedList<ITrigger> triggers = new LinkedList<ITrigger>();
@ -415,73 +489,20 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
triggers.add(BuildCraftEnergy.triggerYellowEngineHeat); triggers.add(BuildCraftEnergy.triggerYellowEngineHeat);
triggers.add(BuildCraftEnergy.triggerRedEngineHeat); triggers.add(BuildCraftEnergy.triggerRedEngineHeat);
if (engine instanceof EngineIron) {
triggers.add(BuildCraftCore.triggerEmptyLiquid);
triggers.add(BuildCraftCore.triggerContainsLiquid);
triggers.add(BuildCraftCore.triggerSpaceLiquid);
triggers.add(BuildCraftCore.triggerFullLiquid);
} else if (engine instanceof EngineStone) {
triggers.add(BuildCraftCore.triggerEmptyInventory);
triggers.add(BuildCraftCore.triggerContainsInventory);
triggers.add(BuildCraftCore.triggerSpaceInventory);
triggers.add(BuildCraftCore.triggerFullInventory);
}
return triggers; return triggers;
} }
@Override @Override
public boolean isPipeConnected(ForgeDirection with) { public boolean isPipeConnected(ForgeDirection with) {
if (engine instanceof EngineWood) return with != orientation;
return false;
return with.ordinal() != orientation;
} }
@Override @Override
public boolean isBuildingMaterial(int i) { public boolean canEmitPowerFrom(ForgeDirection side) {
return false; return side == orientation;
} }
public void checkRedstonePower() { public void checkRedstonePower() {
isRedstonePowered = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord); isRedstonePowered = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
} }
/* ILIQUIDCONTAINER */
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) {
if (engine == null)
return 0;
return engine.fill(from, resource, doFill);
}
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
// TODO Auto-generated method stub
return 0;
}
@Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
return null;
}
@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain) {
return null;
}
@Override
public LiquidTank[] getTanks(ForgeDirection direction) {
if (engine == null)
return new LiquidTank[0];
else
return engine.getLiquidSlots();
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) {
return engine != null ? engine.getTank(direction, type) : null;
}
} }

View file

@ -0,0 +1,407 @@
/**
* 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.energy;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftEnergy;
import net.minecraft.block.Block;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidStack;
import net.minecraftforge.liquids.LiquidTank;
import buildcraft.api.fuels.IronEngineCoolant;
import buildcraft.api.fuels.IronEngineCoolant.Coolant;
import buildcraft.api.fuels.IronEngineFuel;
import buildcraft.api.gates.ITrigger;
import buildcraft.core.DefaultProps;
import buildcraft.core.GuiIds;
import buildcraft.core.IItemPipe;
import buildcraft.core.liquids.LiquidUtils;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import static buildcraft.energy.TileEngine.EnergyStage.BLUE;
import static buildcraft.energy.TileEngine.EnergyStage.GREEN;
import static buildcraft.energy.TileEngine.EnergyStage.RED;
import static buildcraft.energy.TileEngine.EnergyStage.YELLOW;
import static buildcraft.energy.TileEngine.IDEAL_HEAT;
import static buildcraft.energy.TileEngine.MIN_HEAT;
import buildcraft.energy.gui.ContainerEngine;
import java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.liquids.ITankContainer;
public class TileEngineIron extends TileEngine implements ITankContainer {
public static int MAX_LIQUID = LiquidContainerRegistry.BUCKET_VOLUME * 10;
public static float HEAT_PER_MJ = 0.0023F;
public static float COOLDOWN_RATE = 0.005F;
int burnTime = 0;
private LiquidTank fuelTank;
private LiquidTank coolantTank;
private IronEngineFuel currentFuel = null;
public int penaltyCooling = 0;
boolean lastPowered = false;
public TileEngineIron() {
super(1);
fuelTank = new LiquidTank(MAX_LIQUID);
coolantTank = new LiquidTank(MAX_LIQUID);
}
@Override
public String getTextureFile() {
return DefaultProps.TEXTURE_PATH_BLOCKS + "/base_iron.png";
}
@Override
public boolean onBlockActivated(EntityPlayer player, ForgeDirection side) {
if (player.getCurrentEquippedItem() != null) {
if (player.getCurrentEquippedItem().getItem() instanceof IItemPipe) {
return false;
}
ItemStack current = player.getCurrentEquippedItem();
if (current != null && current.itemID != Item.bucketEmpty.itemID) {
if (CoreProxy.proxy.isSimulating(worldObj)) {
if (LiquidUtils.handleRightClick(this, side, player, true, false)) {
return true;
}
} else {
if (LiquidContainerRegistry.isContainer(current)) {
return true;
}
}
}
}
if (!CoreProxy.proxy.isRenderWorld(worldObj)) {
player.openGui(BuildCraftEnergy.instance, GuiIds.ENGINE_IRON, worldObj, xCoord, yCoord, zCoord);
}
return true;
}
@Override
public float explosionRange() {
return 4;
}
@Override
public float getPistonSpeed() {
if (CoreProxy.proxy.isSimulating(worldObj)) {
return Math.max(0.07f * getHeatLevel(), 0.01f);
}
switch (getEnergyStage()) {
case BLUE:
return 0.04F;
case GREEN:
return 0.05F;
case YELLOW:
return 0.06F;
case RED:
return 0.07F;
default:
return 0;
}
}
@Override
public boolean isBurning() {
LiquidStack fuel = fuelTank.getLiquid();
return fuel != null && fuel.amount > 0 && penaltyCooling == 0 && isRedstonePowered;
}
@Override
public void burn() {
LiquidStack fuel = this.fuelTank.getLiquid();
if (currentFuel == null) {
currentFuel = IronEngineFuel.getFuelForLiquid(fuel);
}
if (currentFuel == null)
return;
if (penaltyCooling <= 0 && isRedstonePowered) {
lastPowered = true;
if (burnTime > 0 || fuel.amount > 0) {
if (burnTime > 0) {
burnTime--;
}
if (burnTime <= 0) {
if (fuel != null) {
if (--fuel.amount <= 0) {
fuelTank.setLiquid(null);
}
burnTime = currentFuel.totalBurningTime / LiquidContainerRegistry.BUCKET_VOLUME;
} else {
currentFuel = null;
return;
}
}
currentOutput = currentFuel.powerPerCycle; // Comment out for constant power
addEnergy(currentFuel.powerPerCycle);
heat += currentFuel.powerPerCycle * HEAT_PER_MJ;
}
} else if (penaltyCooling <= 0) {
if (lastPowered) {
lastPowered = false;
penaltyCooling = 30 * 20;
// 30 sec of penalty on top of the cooling
}
}
}
@Override
public void updateHeatLevel() {
}
@Override
public void engineUpdate() {
final ItemStack stack = getStackInSlot(0);
if (stack != null) {
LiquidStack liquid = LiquidContainerRegistry.getLiquidForFilledItem(stack);
if (liquid == null && heat > IDEAL_HEAT) {
liquid = IronEngineCoolant.getLiquidCoolant(stack);
}
if (liquid != null) {
if (fill(ForgeDirection.UNKNOWN, liquid, false) == liquid.amount) {
fill(ForgeDirection.UNKNOWN, liquid, true);
setInventorySlotContents(0, Utils.consumeItem(stack));
}
}
}
if (heat > IDEAL_HEAT) {
float extraHeat = heat - IDEAL_HEAT;
LiquidStack coolant = this.coolantTank.getLiquid();
Coolant currentCoolant = IronEngineCoolant.getCoolant(coolant);
if (currentCoolant != null) {
float cooling = currentCoolant.getDegreesCoolingPerMB(heat);
if (coolant.amount * cooling > extraHeat) {
coolant.amount -= Math.round(extraHeat / cooling);
heat = IDEAL_HEAT;
} else {
heat -= coolant.amount * cooling;
coolantTank.setLiquid(null);
}
}
}
if (heat > MIN_HEAT && (penaltyCooling > 0 || !isRedstonePowered)) {
heat -= COOLDOWN_RATE;
}
if (heat <= MIN_HEAT) {
heat = MIN_HEAT;
}
if (heat <= MIN_HEAT && penaltyCooling > 0) {
penaltyCooling--;
}
}
@Override
public int getScaledBurnTime(int i) {
return this.fuelTank.getLiquid() != null ? (int) (((float) this.fuelTank.getLiquid().amount / (float) (MAX_LIQUID)) * i) : 0;
}
@Override
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
fuelTank.readFromNBT(data.getCompoundTag("fuelTank"));
coolantTank.readFromNBT(data.getCompoundTag("coolantTank"));
burnTime = data.getInteger("burnTime");
penaltyCooling = data.getInteger("penaltyCooling");
}
@Override
public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
data.setTag("fuelTank", fuelTank.writeToNBT(new NBTTagCompound()));
data.setTag("coolantTank", coolantTank.writeToNBT(new NBTTagCompound()));
data.setInteger("burnTime", burnTime);
data.setInteger("penaltyCooling", penaltyCooling);
}
public int getScaledCoolant(int i) {
return coolantTank.getLiquid() != null ? (int) (((float) coolantTank.getLiquid().amount / (float) (MAX_LIQUID)) * i) : 0;
}
@Override
public void getGUINetworkData(int id, int value) {
super.getGUINetworkData(id, value);
switch (id) {
case 15:
if (fuelTank.getLiquid() == null) {
fuelTank.setLiquid(new LiquidStack(0, value));
} else {
fuelTank.getLiquid().amount = value;
}
break;
case 16:
if (fuelTank.getLiquid() == null) {
fuelTank.setLiquid(new LiquidStack(value, 0));
} else {
fuelTank.setLiquid(new LiquidStack(value, fuelTank.getLiquid().amount, fuelTank.getLiquid().itemMeta));
}
break;
case 17:
if (coolantTank.getLiquid() == null) {
coolantTank.setLiquid(new LiquidStack(0, value));
} else {
coolantTank.getLiquid().amount = value;
}
break;
case 18:
if (coolantTank.getLiquid() == null) {
coolantTank.setLiquid(new LiquidStack(value, 0));
} else {
coolantTank.setLiquid(new LiquidStack(value, coolantTank.getLiquid().amount, coolantTank.getLiquid().itemMeta));
}
break;
case 19:
if (fuelTank.getLiquid() == null) {
fuelTank.setLiquid(new LiquidStack(0, 0, value));
} else {
fuelTank.setLiquid(new LiquidStack(fuelTank.getLiquid().itemID, fuelTank.getLiquid().amount, value));
}
break;
case 20:
if (coolantTank.getLiquid() == null) {
coolantTank.setLiquid(new LiquidStack(0, 0, value));
} else {
coolantTank.setLiquid(new LiquidStack(coolantTank.getLiquid().itemID, coolantTank.getLiquid().amount, value));
}
}
}
@Override
public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) {
super.sendGUINetworkData(containerEngine, iCrafting);
iCrafting.sendProgressBarUpdate(containerEngine, 15, fuelTank.getLiquid() != null ? fuelTank.getLiquid().amount : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 16, fuelTank.getLiquid() != null ? fuelTank.getLiquid().itemID : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 17, coolantTank.getLiquid() != null ? coolantTank.getLiquid().amount : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 18, coolantTank.getLiquid() != null ? coolantTank.getLiquid().itemID : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 19, fuelTank.getLiquid() != null ? fuelTank.getLiquid().itemMeta : 0);
iCrafting.sendProgressBarUpdate(containerEngine, 20, coolantTank.getLiquid() != null ? coolantTank.getLiquid().itemMeta : 0);
}
@Override
public boolean isActive() {
return penaltyCooling <= 0;
}
/* ITANKCONTAINER */
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
return 0;
}
@Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
return null;
}
@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain) {
return null;
}
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) {
// Handle coolant
if (IronEngineCoolant.getCoolant(resource) != null)
return coolantTank.fill(resource, doFill);
if (IronEngineFuel.getFuelForLiquid(resource) != null)
return fuelTank.fill(resource, doFill);
return 0;
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) {
switch (direction) {
case UP:
return fuelTank;
case DOWN:
return coolantTank;
default:
return null;
}
}
@Override
public ILiquidTank[] getTanks(ForgeDirection direction) {
return new ILiquidTank[]{fuelTank, coolantTank};
}
@Override
public boolean isStackValidForSlot(int i, ItemStack itemstack) {
if (itemstack == null)
return false;
if (Block.ice.blockID == itemstack.itemID)
return true;
return LiquidContainerRegistry.getLiquidForFilledItem(itemstack) != null;
}
public LiquidStack getFuel() {
return fuelTank.getLiquid();
}
public LiquidStack getCoolant() {
return coolantTank.getLiquid();
}
@Override
public float maxEnergyReceived() {
return 2000;
}
@Override
public float maxEnergyExtracted() {
return 500;
}
@Override
public float getMaxEnergy() {
return 10000;
}
@Override
public float getCurrentOutput() {
if (currentFuel == null) {
return 0;
}
return currentFuel.powerPerCycle;
}
@Override
public LinkedList<ITrigger> getTriggers() {
LinkedList<ITrigger> triggers = super.getTriggers();
triggers.add(BuildCraftCore.triggerEmptyLiquid);
triggers.add(BuildCraftCore.triggerContainsLiquid);
triggers.add(BuildCraftCore.triggerSpaceLiquid);
triggers.add(BuildCraftCore.triggerFullLiquid);
return triggers;
}
}

View file

@ -0,0 +1,87 @@
/**
* 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.energy;
import buildcraft.core.DefaultProps;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
/**
* This class is just intended to update pre 4.0 engines to the design.
*
* It can be deleted someday.
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public class TileEngineLegacy extends TileEngine {
private NBTTagCompound nbt;
public TileEngineLegacy() {
super(0);
}
@Override
public void updateEntity() {
worldObj.removeBlockTileEntity(xCoord, yCoord, zCoord);
TileEntity newTile = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord);
if (newTile instanceof TileEngine) {
newTile.readFromNBT(nbt);
sendNetworkUpdate();
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
@Override
public void readFromNBT(NBTTagCompound data) {
nbt = (NBTTagCompound) data.copy();
this.xCoord = data.getInteger("x");
this.yCoord = data.getInteger("y");
this.zCoord = data.getInteger("z");
}
@Override
public String getTextureFile() {
return DefaultProps.TEXTURE_PATH_BLOCKS + "/base_wood.png";
}
@Override
public float getMaxEnergy() {
return 1;
}
@Override
public float maxEnergyReceived() {
return 0;
}
@Override
public float explosionRange() {
return 0;
}
@Override
public boolean isBurning() {
return false;
}
@Override
public int getScaledBurnTime(int scale) {
return 0;
}
@Override
public float getCurrentOutput() {
return 1;
}
@Override
public float maxEnergyExtracted() {
return 1;
}
}

View file

@ -0,0 +1,163 @@
/**
* 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.energy;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftEnergy;
import buildcraft.api.gates.ITrigger;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityFurnace;
import buildcraft.core.DefaultProps;
import buildcraft.core.GuiIds;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.energy.gui.ContainerEngine;
import java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.ForgeDirection;
public class TileEngineStone extends TileEngine {
final float MAX_OUTPUT = 1f;
final float MIN_OUTPUT = MAX_OUTPUT / 3;
final float TARGET_OUTPUT = 0.375f;
final float kp = 1f;
final float ki = 0.05f;
final float eLimit = (MAX_OUTPUT - MIN_OUTPUT) / ki;
int burnTime = 0;
int totalBurnTime = 0;
float esum = 0;
public TileEngineStone() {
super(1);
}
@Override
public boolean onBlockActivated(EntityPlayer player, ForgeDirection side) {
if (!CoreProxy.proxy.isRenderWorld(worldObj)) {
player.openGui(BuildCraftEnergy.instance, GuiIds.ENGINE_STONE, worldObj, xCoord, yCoord, zCoord);
}
return true;
}
@Override
public String getTextureFile() {
return DefaultProps.TEXTURE_PATH_BLOCKS + "/base_stone.png";
}
@Override
public float explosionRange() {
return 2;
}
@Override
public boolean isBurning() {
return burnTime > 0;
}
@Override
public void burn() {
if (burnTime > 0) {
burnTime--;
float output = getCurrentOutput();
currentOutput = output; // Comment out for constant power
addEnergy(output);
}
if (burnTime == 0 && isRedstonePowered) {
burnTime = totalBurnTime = getItemBurnTime(getStackInSlot(0));
if (burnTime > 0) {
setInventorySlotContents(0, Utils.consumeItem(getStackInSlot(0)));
}
}
}
@Override
public int getScaledBurnTime(int i) {
return (int) (((float) burnTime / (float) totalBurnTime) * i);
}
private int getItemBurnTime(ItemStack itemstack) {
if (itemstack == null)
return 0;
return TileEntityFurnace.getItemBurnTime(itemstack);
}
/* SAVING & LOADING */
@Override
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
burnTime = data.getInteger("burnTime");
totalBurnTime = data.getInteger("totalBurnTime");
}
@Override
public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
data.setInteger("burnTime", burnTime);
data.setInteger("totalBurnTime", totalBurnTime);
}
@Override
public void getGUINetworkData(int id, int value) {
super.getGUINetworkData(id, value);
switch (id) {
case 15:
burnTime = value;
break;
case 16:
totalBurnTime = value;
break;
}
}
@Override
public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) {
super.sendGUINetworkData(containerEngine, iCrafting);
iCrafting.sendProgressBarUpdate(containerEngine, 15, burnTime);
iCrafting.sendProgressBarUpdate(containerEngine, 16, totalBurnTime);
}
@Override
public float maxEnergyReceived() {
return 200;
}
@Override
public float maxEnergyExtracted() {
return 100;
}
@Override
public float getMaxEnergy() {
return 1000;
}
@Override
public float getCurrentOutput() {
float e = TARGET_OUTPUT * getMaxEnergy() - energy;
esum = Math.min(Math.max(esum + e, -eLimit), eLimit);
return Math.min(Math.max(e * kp + esum * ki, MIN_OUTPUT), MAX_OUTPUT);
}
@Override
public LinkedList<ITrigger> getTriggers() {
LinkedList<ITrigger> triggers = super.getTriggers();
triggers.add(BuildCraftCore.triggerEmptyInventory);
triggers.add(BuildCraftCore.triggerContainsInventory);
triggers.add(BuildCraftCore.triggerSpaceInventory);
triggers.add(BuildCraftCore.triggerFullInventory);
return triggers;
}
}

View file

@ -0,0 +1,119 @@
/**
* 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.energy;
import buildcraft.core.DefaultProps;
import buildcraft.core.proxy.CoreProxy;
import static buildcraft.energy.TileEngine.EnergyStage.BLUE;
import static buildcraft.energy.TileEngine.EnergyStage.GREEN;
import static buildcraft.energy.TileEngine.EnergyStage.RED;
import static buildcraft.energy.TileEngine.EnergyStage.YELLOW;
import net.minecraftforge.common.ForgeDirection;
public class TileEngineWood extends TileEngine {
public static final float OUTPUT = 0.05F;
public TileEngineWood() {
super(0);
}
@Override
public String getTextureFile() {
return DefaultProps.TEXTURE_PATH_BLOCKS + "/base_wood.png";
}
@Override
public float explosionRange() {
return 1;
}
@Override
public float minEnergyReceived() {
return 0;
}
@Override
public float maxEnergyReceived() {
return 50;
}
@Override
protected EnergyStage computeEnergyStage() {
float energyLevel = getEnergyLevel();
if (energyLevel < 0.25f) {
return EnergyStage.BLUE;
} else if (energyLevel < 0.5f) {
return EnergyStage.GREEN;
} else if (energyLevel < 0.75f) {
return EnergyStage.YELLOW;
} else {
return EnergyStage.RED;
}
}
@Override
public float getPistonSpeed() {
if (CoreProxy.proxy.isSimulating(worldObj)) {
return Math.max(0.8f * getHeatLevel(), 0.01f);
}
switch (getEnergyStage()) {
case BLUE:
return 0.01F;
case GREEN:
return 0.02F;
case YELLOW:
return 0.04F;
case RED:
return 0.08F;
default:
return 0;
}
}
@Override
public void engineUpdate() {
super.engineUpdate();
if (isRedstonePowered) {
if (worldObj.getWorldTime() % 20 == 0) {
addEnergy(1);
}
}
}
@Override
public boolean isPipeConnected(ForgeDirection with) {
return false;
}
@Override
public boolean isBurning() {
return isRedstonePowered;
}
@Override
public int getScaledBurnTime(int i) {
return 0;
}
@Override
public float getMaxEnergy() {
return 100;
}
@Override
public float getCurrentOutput() {
return OUTPUT;
}
@Override
public float maxEnergyExtracted() {
return 1;
}
}

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.energy; package buildcraft.energy;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -14,12 +12,14 @@ import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.gates.ITriggerParameter; import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.triggers.ActionTriggerIconProvider; import buildcraft.core.triggers.ActionTriggerIconProvider;
import buildcraft.core.triggers.BCTrigger; import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
import buildcraft.energy.TileEngine.EnergyStage;
public class TriggerEngineHeat extends BCTrigger { public class TriggerEngineHeat extends BCTrigger {
public Engine.EnergyStage stage; public EnergyStage stage;
public TriggerEngineHeat(int id, Engine.EnergyStage stage) { public TriggerEngineHeat(int id, EnergyStage stage) {
super(id); super(id);
this.stage = stage; this.stage = stage;
@ -28,23 +28,23 @@ public class TriggerEngineHeat extends BCTrigger {
@Override @Override
public String getDescription() { public String getDescription() {
switch (stage) { switch (stage) {
case Blue: case BLUE:
return "Engine Blue"; return StringUtils.localize("gate.engine.blue");
case Green: case GREEN:
return "Engine Green"; return StringUtils.localize("gate.engine.green");
case Yellow: case YELLOW:
return "Engine Yellow"; return StringUtils.localize("gate.engine.yellow");
default: default:
return "Engine Red"; return StringUtils.localize("gate.engine.red");
} }
} }
@Override @Override
public boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter) { public boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter) {
if (tile instanceof TileEngine) { if (tile instanceof TileEngine) {
Engine engine = ((TileEngine) tile).engine; TileEngine engine = ((TileEngine) tile);
return engine != null && engine.getEnergyStage() == stage; return engine.getEnergyStage() == stage;
} }
return false; return false;
@ -53,11 +53,11 @@ public class TriggerEngineHeat extends BCTrigger {
@Override @Override
public int getIconIndex() { public int getIconIndex() {
switch (stage) { switch (stage) {
case Blue: case BLUE:
return ActionTriggerIconProvider.Trigger_EngineHeat_Blue; return ActionTriggerIconProvider.Trigger_EngineHeat_Blue;
case Green: case GREEN:
return ActionTriggerIconProvider.Trigger_EngineHeat_Green; return ActionTriggerIconProvider.Trigger_EngineHeat_Green;
case Yellow: case YELLOW:
return ActionTriggerIconProvider.Trigger_EngineHeat_Yellow; return ActionTriggerIconProvider.Trigger_EngineHeat_Yellow;
default: default:
return ActionTriggerIconProvider.Trigger_EngineHeat_Red; return ActionTriggerIconProvider.Trigger_EngineHeat_Red;

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.energy.gui; package buildcraft.energy.gui;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -14,7 +12,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import buildcraft.core.gui.BuildCraftContainer; import buildcraft.core.gui.BuildCraftContainer;
import buildcraft.energy.EngineStone; import buildcraft.energy.TileEngineStone;
import buildcraft.energy.TileEngine; import buildcraft.energy.TileEngine;
public class ContainerEngine extends BuildCraftContainer { public class ContainerEngine extends BuildCraftContainer {
@ -26,7 +24,7 @@ public class ContainerEngine extends BuildCraftContainer {
engine = tileEngine; engine = tileEngine;
if (tileEngine.engine instanceof EngineStone) { if (tileEngine instanceof TileEngineStone) {
addSlotToContainer(new Slot(tileEngine, 0, 80, 41)); addSlotToContainer(new Slot(tileEngine, 0, 80, 41));
} else { } else {
addSlotToContainer(new Slot(tileEngine, 0, 52, 41)); addSlotToContainer(new Slot(tileEngine, 0, 52, 41));
@ -49,15 +47,13 @@ public class ContainerEngine extends BuildCraftContainer {
super.detectAndSendChanges(); super.detectAndSendChanges();
for (int i = 0; i < crafters.size(); i++) { for (int i = 0; i < crafters.size(); i++) {
engine.engine.sendGUINetworkData(this, (ICrafting) crafters.get(i)); engine.sendGUINetworkData(this, (ICrafting) crafters.get(i));
} }
} }
@Override @Override
public void updateProgressBar(int i, int j) { public void updateProgressBar(int i, int j) {
if (engine.engine != null) { engine.getGUINetworkData(i, j);
engine.engine.getGUINetworkData(i, j);
}
} }
public boolean isUsableByPlayer(EntityPlayer entityplayer) { public boolean isUsableByPlayer(EntityPlayer entityplayer) {

View file

@ -19,7 +19,7 @@ import org.lwjgl.opengl.GL11;
import buildcraft.core.DefaultProps; import buildcraft.core.DefaultProps;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
import buildcraft.energy.EngineIron; import buildcraft.energy.TileEngineIron;
import buildcraft.energy.TileEngine; import buildcraft.energy.TileEngine;
public class GuiCombustionEngine extends GuiEngine { public class GuiCombustionEngine extends GuiEngine {
@ -44,15 +44,14 @@ public class GuiCombustionEngine extends GuiEngine {
int k = (height - ySize) / 2; int k = (height - ySize) / 2;
drawTexturedModalRect(j, k, 0, 0, xSize, ySize); drawTexturedModalRect(j, k, 0, 0, xSize, ySize);
TileEngine engine = (TileEngine) tile; TileEngineIron engine = (TileEngineIron) tile;
EngineIron engineIron = ((EngineIron) engine.engine);
if (engine.getScaledBurnTime(58) > 0) { if (engine.getScaledBurnTime(58) > 0) {
displayGauge(j, k, 19, 104, engine.getScaledBurnTime(58), engineIron.getFuel()); displayGauge(j, k, 19, 104, engine.getScaledBurnTime(58), engine.getFuel());
} }
if (engineIron.getScaledCoolant(58) > 0) { if (engine.getScaledCoolant(58) > 0) {
displayGauge(j, k, 19, 122, engineIron.getScaledCoolant(58), engineIron.getCoolant()); displayGauge(j, k, 19, 122, engine.getScaledCoolant(58), engine.getCoolant());
} }
} }

View file

@ -7,19 +7,18 @@ import buildcraft.core.CoreIconProvider;
import buildcraft.core.gui.BuildCraftContainer; import buildcraft.core.gui.BuildCraftContainer;
import buildcraft.core.gui.GuiBuildCraft; import buildcraft.core.gui.GuiBuildCraft;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
import buildcraft.energy.Engine;
import buildcraft.energy.TileEngine; import buildcraft.energy.TileEngine;
public abstract class GuiEngine extends GuiBuildCraft { public abstract class GuiEngine extends GuiBuildCraft {
protected class EngineLedger extends Ledger { protected class EngineLedger extends Ledger {
Engine engine; TileEngine engine;
int headerColour = 0xe1c92f; int headerColour = 0xe1c92f;
int subheaderColour = 0xaaafb8; int subheaderColour = 0xaaafb8;
int textColour = 0x000000; int textColour = 0x000000;
public EngineLedger(Engine engine) { public EngineLedger(TileEngine engine) {
this.engine = engine; this.engine = engine;
maxHeight = 94; maxHeight = 94;
overlayColor = 0xd46c1f; overlayColor = 0xd46c1f;
@ -40,17 +39,17 @@ public abstract class GuiEngine extends GuiBuildCraft {
fontRenderer.drawStringWithShadow(StringUtils.localize("gui.energy"), x + 22, y + 8, headerColour); fontRenderer.drawStringWithShadow(StringUtils.localize("gui.energy"), x + 22, y + 8, headerColour);
fontRenderer.drawStringWithShadow(StringUtils.localize("gui.currentOutput") + ":", x + 22, y + 20, subheaderColour); fontRenderer.drawStringWithShadow(StringUtils.localize("gui.currentOutput") + ":", x + 22, y + 20, subheaderColour);
fontRenderer.drawString(String.format("%.1f MJ/t", engine.getCurrentOutput()), x + 22, y + 32, textColour); fontRenderer.drawString(String.format("%.1f MJ/t", engine.currentOutput), x + 22, y + 32, textColour);
fontRenderer.drawStringWithShadow(StringUtils.localize("gui.stored") + ":", x + 22, y + 44, subheaderColour); fontRenderer.drawStringWithShadow(StringUtils.localize("gui.stored") + ":", x + 22, y + 44, subheaderColour);
fontRenderer.drawString(String.format("%.1f MJ", engine.getEnergyStored()), x + 22, y + 56, textColour); fontRenderer.drawString(String.format("%.1f MJ", engine.getEnergyStored()), x + 22, y + 56, textColour);
fontRenderer.drawStringWithShadow(StringUtils.localize("gui.heat") + ":", x + 22, y + 68, subheaderColour); fontRenderer.drawStringWithShadow(StringUtils.localize("gui.heat") + ":", x + 22, y + 68, subheaderColour);
fontRenderer.drawString(String.format("%.2f \u00B0C", (engine.getHeat() / 100.0) + 20.0), x + 22, y + 80, textColour); fontRenderer.drawString(String.format("%.2f \u00B0C", engine.getHeat()), x + 22, y + 80, textColour);
} }
@Override @Override
public String getTooltip() { public String getTooltip() {
return engine.getCurrentOutput() + " MJ/t"; return String.format("%.1f MJ/t", engine.currentOutput);
} }
} }
@ -61,6 +60,6 @@ public abstract class GuiEngine extends GuiBuildCraft {
@Override @Override
protected void initLedgers(IInventory inventory) { protected void initLedgers(IInventory inventory) {
super.initLedgers(inventory); super.initLedgers(inventory);
ledgerManager.add(new EngineLedger(((TileEngine) tile).engine)); ledgerManager.add(new EngineLedger((TileEngine) tile));
} }
} }

View file

@ -26,9 +26,8 @@ import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftCore.RenderMode; import buildcraft.BuildCraftCore.RenderMode;
import buildcraft.core.DefaultProps; import buildcraft.core.DefaultProps;
import buildcraft.core.IInventoryRenderer; import buildcraft.core.IInventoryRenderer;
import buildcraft.energy.Engine; import buildcraft.energy.TileEngine;
import buildcraft.energy.Engine.EnergyStage; import buildcraft.energy.TileEngine.EnergyStage;
import buildcraft.energy.IEngineProvider;
public class RenderEngine extends TileEntitySpecialRenderer implements IInventoryRenderer { public class RenderEngine extends TileEntitySpecialRenderer implements IInventoryRenderer {
@ -86,13 +85,13 @@ public class RenderEngine extends TileEntitySpecialRenderer implements IInventor
@Override @Override
public void inventoryRender(double x, double y, double z, float f, float f1) { public void inventoryRender(double x, double y, double z, float f, float f1) {
render(EnergyStage.Blue, 0.25F, ForgeDirection.UP, baseTexture, x, y, z); render(EnergyStage.BLUE, 0.25F, ForgeDirection.UP, baseTexture, x, y, z);
} }
@Override @Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) { public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
Engine engine = ((IEngineProvider) tileentity).getEngine(); TileEngine engine = ((TileEngine) tileentity);
if (engine != null) { if (engine != null) {
render(engine.getEnergyStage(), engine.progress, engine.orientation, engine.getTextureFile(), x, y, z); render(engine.getEnergyStage(), engine.progress, engine.orientation, engine.getTextureFile(), x, y, z);
@ -181,13 +180,13 @@ public class RenderEngine extends TileEntitySpecialRenderer implements IInventor
String texture = ""; String texture = "";
switch (energy) { switch (energy) {
case Blue: case BLUE:
texture = DefaultProps.TEXTURE_PATH_BLOCKS + "/trunk_blue.png"; texture = DefaultProps.TEXTURE_PATH_BLOCKS + "/trunk_blue.png";
break; break;
case Green: case GREEN:
texture = DefaultProps.TEXTURE_PATH_BLOCKS + "/trunk_green.png"; texture = DefaultProps.TEXTURE_PATH_BLOCKS + "/trunk_green.png";
break; break;
case Yellow: case YELLOW:
texture = DefaultProps.TEXTURE_PATH_BLOCKS + "/trunk_yellow.png"; texture = DefaultProps.TEXTURE_PATH_BLOCKS + "/trunk_yellow.png";
break; break;
default: default:

View file

@ -1,24 +0,0 @@
/**
* 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.factory;
import buildcraft.api.power.IPowerProvider;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
public abstract class TileMachine extends TileBuildCraft implements IMachine, IPowerReceptor {
@Override
public int powerRequest(ForgeDirection from) {
IPowerProvider p = getPowerProvider();
float needed = p.getMaxEnergyStored() - p.getEnergyStored();
return (int) Math.ceil(Math.min(p.getMaxEnergyReceived(), needed));
}
}

View file

@ -16,23 +16,25 @@ import net.minecraftforge.common.ForgeDirection;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftFactory; import buildcraft.BuildCraftFactory;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.api.transport.IPipeConnection; import buildcraft.api.transport.IPipeConnection;
import buildcraft.core.IMachine; import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.utils.BlockUtil; import buildcraft.core.utils.BlockUtil;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
public class TileMiningWell extends TileMachine implements IMachine, IPowerReceptor, IPipeConnection { public class TileMiningWell extends TileBuildCraft implements IMachine, IPowerReceptor, IPipeConnection {
boolean isDigging = true; boolean isDigging = true;
IPowerProvider powerProvider; private PowerHandler powerHandler;
public TileMiningWell() { public TileMiningWell() {
powerProvider = PowerFramework.currentFramework.createPowerProvider(); powerHandler = new PowerHandler(this, Type.MACHINE);
powerProvider.configure(50, 100, 100, 60, 1000); powerHandler.configure(100, 100, 60, 1000);
powerProvider.configurePowerPerdition(1, 1); powerHandler.configurePowerPerdition(1, 1);
} }
/** /**
@ -40,8 +42,8 @@ public class TileMiningWell extends TileMachine implements IMachine, IPowerRecep
* bedrock, lava or goes below 0, it's considered done. * bedrock, lava or goes below 0, it's considered done.
*/ */
@Override @Override
public void doWork() { public void doWork(PowerHandler workProvider) {
if (powerProvider.useEnergy(60, 60, true) != 60) if (powerHandler.useEnergy(60, 60, true) != 60)
return; return;
World world = worldObj; World world = worldObj;
@ -114,13 +116,8 @@ public class TileMiningWell extends TileMachine implements IMachine, IPowerRecep
} }
@Override @Override
public void setPowerProvider(IPowerProvider provider) { public PowerReceiver getPowerReceiver(ForgeDirection side) {
powerProvider = provider; return powerHandler.getPowerReceiver();
}
@Override
public IPowerProvider getPowerProvider() {
return powerProvider;
} }
@Override @Override

View file

@ -26,18 +26,20 @@ import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftFactory; import buildcraft.BuildCraftFactory;
import buildcraft.api.core.Position; import buildcraft.api.core.Position;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.core.BlockIndex; import buildcraft.core.BlockIndex;
import buildcraft.core.EntityBlock; import buildcraft.core.EntityBlock;
import buildcraft.core.IMachine; import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.network.PacketPayload; import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.PacketUpdate;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
public class TilePump extends TileMachine implements IMachine, IPowerReceptor, ITankContainer { public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor, ITankContainer {
public static int MAX_LIQUID = LiquidContainerRegistry.BUCKET_VOLUME; public static int MAX_LIQUID = LiquidContainerRegistry.BUCKET_VOLUME;
EntityBlock tube; EntityBlock tube;
@ -45,17 +47,17 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I
LiquidTank tank; LiquidTank tank;
double tubeY = Double.NaN; double tubeY = Double.NaN;
int aimY = 0; int aimY = 0;
private IPowerProvider powerProvider; private PowerHandler powerHandler;
public TilePump() { public TilePump() {
powerProvider = PowerFramework.currentFramework.createPowerProvider(); powerHandler = new PowerHandler(this, Type.MACHINE);
initPowerProvider(); initPowerProvider();
tank = new LiquidTank(MAX_LIQUID); tank = new LiquidTank(MAX_LIQUID);
} }
private void initPowerProvider() { private void initPowerProvider() {
powerProvider.configure(20, 1, 8, 10, 100); powerHandler.configure(1, 8, 10, 100);
powerProvider.configurePowerPerdition(1, 100); powerHandler.configurePowerPerdition(1, 100);
} }
// TODO, manage this by different levels (pump what's above first...) // TODO, manage this by different levels (pump what's above first...)
@ -87,7 +89,7 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I
if (tank.fill(liquidToPump, false) == liquidToPump.amount) { if (tank.fill(liquidToPump, false) == liquidToPump.amount) {
if (powerProvider.useEnergy(10, 10, true) == 10) { if (powerHandler.useEnergy(10, 10, true) == 10) {
index = getNextIndexToPump(true); index = getNextIndexToPump(true);
if (liquidToPump.itemID != Block.waterStill.blockID || BuildCraftCore.consumeWaterSources) { if (liquidToPump.itemID != Block.waterStill.blockID || BuildCraftCore.consumeWaterSources) {
@ -286,7 +288,7 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I
tubeY = nbttagcompound.getFloat("tubeY"); tubeY = nbttagcompound.getFloat("tubeY");
PowerFramework.currentFramework.loadPowerProvider(this, nbttagcompound); powerHandler.readFromNBT(nbttagcompound);
initPowerProvider(); initPowerProvider();
} }
@ -294,7 +296,7 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I
public void writeToNBT(NBTTagCompound nbttagcompound) { public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound); super.writeToNBT(nbttagcompound);
PowerFramework.currentFramework.savePowerProvider(this, nbttagcompound); powerHandler.writeToNBT(nbttagcompound);
if (tank.getLiquid() != null) { if (tank.getLiquid() != null) {
nbttagcompound.setTag("tank", tank.getLiquid().writeToNBT(new NBTTagCompound())); nbttagcompound.setTag("tank", tank.getLiquid().writeToNBT(new NBTTagCompound()));
@ -315,17 +317,12 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I
} }
@Override @Override
public void setPowerProvider(IPowerProvider provider) { public PowerReceiver getPowerReceiver(ForgeDirection side) {
powerProvider = provider; return powerHandler.getPowerReceiver();
} }
@Override @Override
public IPowerProvider getPowerProvider() { public void doWork(PowerHandler workProvider) {
return powerProvider;
}
@Override
public void doWork() {
} }
@Override @Override

View file

@ -27,15 +27,16 @@ import buildcraft.BuildCraftFactory;
import buildcraft.api.core.IAreaProvider; import buildcraft.api.core.IAreaProvider;
import buildcraft.api.core.LaserKind; import buildcraft.api.core.LaserKind;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.transport.IPipeConnection; import buildcraft.api.transport.IPipeConnection;
import buildcraft.core.Box; import buildcraft.core.Box;
import buildcraft.core.DefaultAreaProvider; import buildcraft.core.DefaultAreaProvider;
import buildcraft.core.EntityRobot; import buildcraft.core.EntityRobot;
import buildcraft.core.IBuilderInventory; import buildcraft.core.IBuilderInventory;
import buildcraft.core.IMachine; import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.blueprints.BptBlueprint; import buildcraft.core.blueprints.BptBlueprint;
import buildcraft.core.blueprints.BptBuilderBase; import buildcraft.core.blueprints.BptBuilderBase;
import buildcraft.core.blueprints.BptBuilderBlueprint; import buildcraft.core.blueprints.BptBuilderBlueprint;
@ -51,7 +52,7 @@ import com.google.common.collect.Sets;
import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player; import cpw.mods.fml.common.network.Player;
public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor, IPipeConnection, IBuilderInventory { public class TileQuarry extends TileBuildCraft implements IMachine, IPowerReceptor, IPipeConnection, IBuilderInventory {
public @TileNetworkData public @TileNetworkData
Box box = new Box(); Box box = new Box();
@ -68,18 +69,18 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
public EntityRobot builder; public EntityRobot builder;
BptBuilderBase bluePrintBuilder; BptBuilderBase bluePrintBuilder;
public EntityMechanicalArm arm; public EntityMechanicalArm arm;
public IPowerProvider powerProvider; public PowerHandler powerHandler;
boolean isDigging = false; boolean isDigging = false;
public static final int MAX_ENERGY = 15000; public static final int MAX_ENERGY = 15000;
public TileQuarry() { public TileQuarry() {
powerProvider = PowerFramework.currentFramework.createPowerProvider(); powerHandler = new PowerHandler(this, PowerHandler.Type.MACHINE);
initPowerProvider(); initPowerProvider();
} }
private void initPowerProvider() { private void initPowerProvider() {
powerProvider.configure(20, 50, 100, 25, MAX_ENERGY); powerHandler.configure(50, 100, 25, MAX_ENERGY);
powerProvider.configurePowerPerdition(2, 1); powerHandler.configurePowerPerdition(2, 1);
} }
public void createUtilsIfNeeded() { public void createUtilsIfNeeded() {
@ -146,9 +147,9 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
} }
super.updateEntity(); super.updateEntity();
if (inProcess) { if (inProcess) {
float energyToUse = 2 + powerProvider.getEnergyStored() / 500; float energyToUse = 2 + powerHandler.getEnergyStored() / 500;
float energy = powerProvider.useEnergy(energyToUse, energyToUse, true); float energy = powerHandler.useEnergy(energyToUse, energyToUse, true);
if (energy > 0) { if (energy > 0) {
moveHead(0.1 + energy / 200F); moveHead(0.1 + energy / 200F);
@ -189,17 +190,15 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
} }
@Override @Override
public void doWork() { public void doWork(PowerHandler workProvider) {
} }
protected void buildFrame() { protected void buildFrame() {
powerProvider.configure(20, 50, 100, 25, MAX_ENERGY); powerHandler.configure(50, 100, 25, MAX_ENERGY);
if (powerProvider.useEnergy(25, 25, true) != 25) if (powerHandler.useEnergy(25, 25, true) != 25)
return; return;
powerProvider.getTimeTracker().markTime(worldObj);
if (builder == null) { if (builder == null) {
builder = new EntityRobot(worldObj, box); builder = new EntityRobot(worldObj, box);
worldObj.spawnEntityInWorld(builder); worldObj.spawnEntityInWorld(builder);
@ -211,8 +210,8 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
} }
protected void dig() { protected void dig() {
powerProvider.configure(20, 100, 500, 60, MAX_ENERGY); powerHandler.configure(100, 500, 60, MAX_ENERGY);
if (powerProvider.useEnergy(60, 60, true) != 60) if (powerHandler.useEnergy(60, 60, true) != 60)
return; return;
if (!findTarget(true)) { if (!findTarget(true)) {
@ -336,7 +335,7 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
public void readFromNBT(NBTTagCompound nbttagcompound) { public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound); super.readFromNBT(nbttagcompound);
PowerFramework.currentFramework.loadPowerProvider(this, nbttagcompound); powerHandler.readFromNBT(nbttagcompound);
initPowerProvider(); initPowerProvider();
if (nbttagcompound.hasKey("box")) { if (nbttagcompound.hasKey("box")) {
@ -374,7 +373,7 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
public void writeToNBT(NBTTagCompound nbttagcompound) { public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound); super.writeToNBT(nbttagcompound);
PowerFramework.currentFramework.savePowerProvider(this, nbttagcompound); powerHandler.writeToNBT(nbttagcompound);
nbttagcompound.setInteger("targetX", targetX); nbttagcompound.setInteger("targetX", targetX);
nbttagcompound.setInteger("targetY", targetY); nbttagcompound.setInteger("targetY", targetY);
@ -402,7 +401,6 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
int blockId = worldObj.getBlockId(i, j, k); int blockId = worldObj.getBlockId(i, j, k);
if (isQuarriableBlock(i, j, k)) { if (isQuarriableBlock(i, j, k)) {
powerProvider.getTimeTracker().markTime(worldObj);
// Share this with mining well! // Share this with mining well!
@ -666,15 +664,10 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
isDigging = true; isDigging = true;
} }
@Override
public void setPowerProvider(IPowerProvider provider) {
powerProvider = provider;
}
@Override @Override
public IPowerProvider getPowerProvider() { public PowerReceiver getPowerReceiver(ForgeDirection side) {
return powerProvider; return powerHandler.getPowerReceiver();
} }
@Override @Override

View file

@ -22,16 +22,18 @@ import net.minecraftforge.liquids.LiquidTank;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.api.recipes.RefineryRecipe; import buildcraft.api.recipes.RefineryRecipe;
import buildcraft.core.IMachine; import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.network.PacketPayload; import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.PacketUpdate;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
public class TileRefinery extends TileMachine implements ITankContainer, IPowerReceptor, IInventory, IMachine { public class TileRefinery extends TileBuildCraft implements ITankContainer, IPowerReceptor, IInventory, IMachine {
private int[] filters = new int[2]; private int[] filters = new int[2];
private int[] filtersMeta = new int[2]; private int[] filtersMeta = new int[2];
@ -43,11 +45,11 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
private int animationStage = 0; private int animationStage = 0;
SafeTimeTracker time = new SafeTimeTracker(); SafeTimeTracker time = new SafeTimeTracker();
SafeTimeTracker updateNetworkTime = new SafeTimeTracker(); SafeTimeTracker updateNetworkTime = new SafeTimeTracker();
IPowerProvider powerProvider; private PowerHandler powerHandler;
private boolean isActive; private boolean isActive;
public TileRefinery() { public TileRefinery() {
powerProvider = PowerFramework.currentFramework.createPowerProvider(); powerHandler = new PowerHandler(this, Type.MACHINE);
initPowerProvider(); initPowerProvider();
filters[0] = 0; filters[0] = 0;
@ -57,8 +59,8 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
} }
private void initPowerProvider() { private void initPowerProvider() {
powerProvider.configure(20, 25, 100, 25, 1000); powerHandler.configure(25, 100, 25, 1000);
powerProvider.configurePowerPerdition(1, 1); powerHandler.configurePowerPerdition(1, 1);
} }
@Override @Override
@ -106,17 +108,12 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
} }
@Override @Override
public void setPowerProvider(IPowerProvider provider) { public PowerReceiver getPowerReceiver(ForgeDirection side) {
powerProvider = provider; return powerHandler.getPowerReceiver();
} }
@Override @Override
public IPowerProvider getPowerProvider() { public void doWork(PowerHandler workProvider) {
return powerProvider;
}
@Override
public void doWork() {
} }
@Override @Override
@ -157,7 +154,7 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
isActive = true; isActive = true;
if (powerProvider.getEnergyStored() >= currentRecipe.energy) { if (powerHandler.getEnergyStored() >= currentRecipe.energy) {
increaseAnimation(); increaseAnimation();
} else { } else {
decreaseAnimation(); decreaseAnimation();
@ -166,7 +163,7 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
if (!time.markTimeIfDelay(worldObj, currentRecipe.delay)) if (!time.markTimeIfDelay(worldObj, currentRecipe.delay))
return; return;
float energyUsed = powerProvider.useEnergy(currentRecipe.energy, currentRecipe.energy, true); float energyUsed = powerHandler.useEnergy(currentRecipe.energy, currentRecipe.energy, true);
if (energyUsed != 0) { if (energyUsed != 0) {
if (consumeInput(currentRecipe.ingredient1) && consumeInput(currentRecipe.ingredient2)) { if (consumeInput(currentRecipe.ingredient1) && consumeInput(currentRecipe.ingredient2)) {
@ -255,7 +252,7 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
animationStage = nbttagcompound.getInteger("animationStage"); animationStage = nbttagcompound.getInteger("animationStage");
animationSpeed = nbttagcompound.getFloat("animationSpeed"); animationSpeed = nbttagcompound.getFloat("animationSpeed");
PowerFramework.currentFramework.loadPowerProvider(this, nbttagcompound); powerHandler.readFromNBT(nbttagcompound);
initPowerProvider(); initPowerProvider();
filters[0] = nbttagcompound.getInteger("filters_0"); filters[0] = nbttagcompound.getInteger("filters_0");
@ -282,7 +279,7 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR
nbttagcompound.setInteger("animationStage", animationStage); nbttagcompound.setInteger("animationStage", animationStage);
nbttagcompound.setFloat("animationSpeed", animationSpeed); nbttagcompound.setFloat("animationSpeed", animationSpeed);
PowerFramework.currentFramework.savePowerProvider(this, nbttagcompound); powerHandler.writeToNBT(nbttagcompound);
nbttagcompound.setInteger("filters_0", filters[0]); nbttagcompound.setInteger("filters_0", filters[0]);
nbttagcompound.setInteger("filters_1", filters[1]); nbttagcompound.setInteger("filters_1", filters[1]);

View file

@ -17,36 +17,38 @@ import buildcraft.api.core.Position;
import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import buildcraft.api.gates.IActionReceptor; import buildcraft.api.gates.IActionReceptor;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.core.BlockIndex; import buildcraft.core.BlockIndex;
import buildcraft.core.EntityEnergyLaser; import buildcraft.core.EntityEnergyLaser;
import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.triggers.ActionMachineControl; import buildcraft.core.triggers.ActionMachineControl;
import buildcraft.factory.TileMachine;
public class TileLaser extends TileMachine implements IPowerReceptor, IActionReceptor { public class TileLaser extends TileBuildCraft implements IPowerReceptor, IActionReceptor, IMachine {
private EntityEnergyLaser laser = null; private EntityEnergyLaser laser = null;
private final SafeTimeTracker laserTickTracker = new SafeTimeTracker(); private final SafeTimeTracker laserTickTracker = new SafeTimeTracker();
private final SafeTimeTracker searchTracker = new SafeTimeTracker(); private final SafeTimeTracker searchTracker = new SafeTimeTracker();
private final SafeTimeTracker networkTracker = new SafeTimeTracker(); private final SafeTimeTracker networkTracker = new SafeTimeTracker();
private ILaserTarget laserTarget; private ILaserTarget laserTarget;
public IPowerProvider powerProvider; private PowerHandler powerHandler;
private int nextNetworkUpdate = 3; private int nextNetworkUpdate = 3;
private int nextLaserUpdate = 10; private int nextLaserUpdate = 10;
private int nextLaserSearch = 100; private int nextLaserSearch = 100;
private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown; private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown;
public TileLaser() { public TileLaser() {
powerProvider = PowerFramework.currentFramework.createPowerProvider(); powerHandler = new PowerHandler(this, Type.MACHINE);
initPowerProvider(); initPowerProvider();
} }
private void initPowerProvider() { private void initPowerProvider() {
powerProvider.configure(20, 25, 25, 25, 1000); powerHandler.configure(25, 150, 25, 1000);
powerProvider.configurePowerPerdition(1, 1); powerHandler.configurePowerPerdition(1, 1);
} }
@Override @Override
@ -57,7 +59,7 @@ public class TileLaser extends TileMachine implements IPowerReceptor, IActionRec
return; return;
// Disable the laser and do nothing if no energy is available. // Disable the laser and do nothing if no energy is available.
if (powerProvider.getEnergyStored() == 0) { if (powerHandler.getEnergyStored() == 0) {
removeLaser(); removeLaser();
return; return;
} }
@ -93,7 +95,7 @@ public class TileLaser extends TileMachine implements IPowerReceptor, IActionRec
} }
// Consume power and transfer it to the table. // Consume power and transfer it to the table.
float power = powerProvider.useEnergy(0, 4, true); float power = powerHandler.useEnergy(0, 4, true);
laserTarget.receiveLaserEnergy(power); laserTarget.receiveLaserEnergy(power);
if (laser != null) { if (laser != null) {
@ -231,17 +233,12 @@ public class TileLaser extends TileMachine implements IPowerReceptor, IActionRec
} }
@Override @Override
public void setPowerProvider(IPowerProvider provider) { public PowerReceiver getPowerReceiver(ForgeDirection side) {
powerProvider = provider; return powerHandler.getPowerReceiver();
} }
@Override @Override
public IPowerProvider getPowerProvider() { public void doWork(PowerHandler workProvider) {
return powerProvider;
}
@Override
public void doWork() {
} }
@Override @Override
@ -255,7 +252,7 @@ public class TileLaser extends TileMachine implements IPowerReceptor, IActionRec
public void readFromNBT(NBTTagCompound nbttagcompound) { public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound); super.readFromNBT(nbttagcompound);
PowerFramework.currentFramework.loadPowerProvider(this, nbttagcompound); powerHandler.readFromNBT(nbttagcompound);
initPowerProvider(); initPowerProvider();
} }
@ -263,7 +260,7 @@ public class TileLaser extends TileMachine implements IPowerReceptor, IActionRec
public void writeToNBT(NBTTagCompound nbttagcompound) { public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound); super.writeToNBT(nbttagcompound);
PowerFramework.currentFramework.savePowerProvider(this, nbttagcompound); powerHandler.writeToNBT(nbttagcompound);
} }
@Override @Override

View file

@ -914,7 +914,7 @@ public class BlockGenericPipe extends BlockContainer {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public Icon getIcon(int par1, int par2) { public Icon getIcon(int par1, int par2) {
return BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.Stripes); return BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.Stripes.ordinal());
} }
/** /**

View file

@ -3,6 +3,7 @@ package buildcraft.transport;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler.Type;
public class EnergyPulser { public class EnergyPulser {
@ -26,7 +27,7 @@ public class EnergyPulser {
return; return;
if (!singlePulse || !hasPulsed) { if (!singlePulse || !hasPulsed) {
powerReceptor.getPowerProvider().receiveEnergy(Math.min(1 << (pulseCount - 1), 64), ForgeDirection.WEST); powerReceptor.getPowerReceiver(null).receiveEnergy(Type.GATE, Math.min(1 << (pulseCount - 1), 64), ForgeDirection.WEST);
hasPulsed = true; hasPulsed = true;
} }
} }

View file

@ -13,7 +13,7 @@ import net.minecraftforge.common.ForgeDirection;
public interface IPipeTransportPowerHook { public interface IPipeTransportPowerHook {
public double receiveEnergy(ForgeDirection from, double val); public float receiveEnergy(ForgeDirection from, float val);
public void requestEnergy(ForgeDirection from, int i); public void requestEnergy(ForgeDirection from, float amount);
} }

View file

@ -729,4 +729,8 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
} }
public World getWorldObj(){
return worldObj;
}
} }

View file

@ -8,114 +8,81 @@ import cpw.mods.fml.relauncher.SideOnly;
public class PipeIconProvider implements IIconProvider { public class PipeIconProvider implements IIconProvider {
public static final int PipeStructureCobblestone = 0; public enum TYPE {
public static final int PipeItemsCobbleStone = 1;
public static final int PipeItemsDiamond_Center = 2;
public static final int PipeItemsDiamond_Down = 3;
public static final int PipeItemsDiamond_Up = 4;
public static final int PipeItemsDiamond_North = 5;
public static final int PipeItemsDiamond_South = 6;
public static final int PipeItemsDiamond_West = 7;
public static final int PipeItemsDiamond_East = 8;
public static final int PipeItemsWood_Standard = 9;
public static final int PipeAllWood_Solid = 10;
public static final int PipeItemsEmerald_Standard = 11;
public static final int PipeAllEmerald_Solid = 12;
public static final int PipeItemsGold = 13;
public static final int PipeItemsIron_Standard = 14;
public static final int PipeAllIron_Solid = 15;
public static final int PipeItemsObsidian = 16;
public static final int PipeItemsSandstone = 17;
public static final int PipeItemsStone = 18;
public static final int PipeItemsVoid = 19;
public static final int PipeLiquidsCobblestone = 20;
public static final int PipeLiquidsWood_Standard = 21;
public static final int PipeLiquidsEmerald_Standard = 22;
public static final int PipeLiquidsGold = 23;
public static final int PipeLiquidsIron_Standard = 24;
public static final int PipeLiquidsSandstone = 25;
public static final int PipeLiquidsStone = 26;
public static final int PipeLiquidsVoid = 27;
public static final int PipePowerGold = 28;
public static final int PipePowerStone = 29;
public static final int PipePowerWood_Standard = 30;
public static final int Power_Normal = 31; PipeStructureCobblestone("pipeStructureCobblestone"),
public static final int Power_Overload = 32; //
PipeItemsCobbleStone("pipeItemsCobblestone"),
//
PipeItemsDiamond_Center("pipeItemsDiamond_center"),
PipeItemsDiamond_Down("pipeItemsDiamond_down"),
PipeItemsDiamond_Up("pipeItemsDiamond_up"),
PipeItemsDiamond_North("pipeItemsDiamond_north"),
PipeItemsDiamond_South("pipeItemsDiamond_south"),
PipeItemsDiamond_West("pipeItemsDiamond_west"),
PipeItemsDiamond_East("pipeItemsDiamond_east"),
//
PipeItemsWood_Standard("pipeItemsWood_standard"),
PipeAllWood_Solid("pipeAllWood_solid"),
//
PipeItemsEmerald_Standard("pipeItemsEmerald_standard"),
PipeAllEmerald_Solid("pipeAllEmerald_solid"),
//
PipeItemsGold("pipeItemsGold"),
//
PipeItemsIron_Standard("pipeItemsIron_standard"),
PipeAllIron_Solid("pipeAllIron_solid"),
//
PipeItemsObsidian("pipeItemsObsidian"),
PipeItemsSandstone("pipeItemsSandstone"),
PipeItemsStone("pipeItemsStone"),
PipeItemsQuartz("pipeItemsQuartz"),
PipeItemsVoid("pipeItemsVoid"),
//
PipeLiquidsCobblestone("pipeLiquidsCobblestone"),
PipeLiquidsWood_Standard("pipeLiquidsWood_standard"),
PipeLiquidsEmerald_Standard("pipeLiquidsEmerald_standard"),
PipeLiquidsGold("pipeLiquidsGold"),
PipeLiquidsIron_Standard("pipeLiquidsIron_standard"),
PipeLiquidsSandstone("pipeLiquidsSandstone"),
PipeLiquidsStone("pipeLiquidsStone"),
PipeLiquidsVoid("pipeLiquidsVoid"),
//
PipePowerDiamond("pipePowerDiamond"),
PipePowerGold("pipePowerGold"),
PipePowerQuartz("pipePowerQuartz"),
PipePowerStone("pipePowerStone"),
PipePowerCobblestone("pipePowerCobblestone"),
PipePowerWood_Standard("pipePowerWood_standard"),
//
Power_Normal("texture_cyan"),
Power_Overload("texture_red_lit"),
Stripes("pipeStripes");
//
public static final TYPE[] VALUES = values();
private final String iconTag;
private Icon icon;
public static final int Stripes = 33; private TYPE(String iconTag) {
this.iconTag = iconTag;
}
public static final int PipePowerCobblestone = 34; private void registerIcon(IconRegister iconRegister) {
public static final int PipePowerDiamond = 35; icon = iconRegister.registerIcon("buildcraft:" + iconTag);
public static final int PipePowerQuartz = 36; }
public static final int PipeItemsQuartz = 37; }
public static final int MAX = 38;
@SideOnly(Side.CLIENT)
private Icon[] _icons;
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public Icon getIcon(int pipeIconIndex) { public Icon getIcon(int pipeIconIndex) {
return _icons[pipeIconIndex]; return TYPE.VALUES[pipeIconIndex].icon;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) { public void registerIcons(IconRegister iconRegister) {
for (TYPE type : TYPE.VALUES) {
_icons = new Icon[PipeIconProvider.MAX]; type.registerIcon(iconRegister);
}
_icons[PipeIconProvider.PipeStructureCobblestone] = iconRegister.registerIcon("buildcraft:pipeStructureCobblestone");
_icons[PipeIconProvider.PipeItemsCobbleStone] = iconRegister.registerIcon("buildcraft:pipeItemsCobblestone");
_icons[PipeIconProvider.PipeItemsDiamond_Center] = iconRegister.registerIcon("buildcraft:pipeItemsDiamond_center");
_icons[PipeIconProvider.PipeItemsDiamond_Down] = iconRegister.registerIcon("buildcraft:pipeItemsDiamond_down");
_icons[PipeIconProvider.PipeItemsDiamond_Up] = iconRegister.registerIcon("buildcraft:pipeItemsDiamond_up");
_icons[PipeIconProvider.PipeItemsDiamond_North] = iconRegister.registerIcon("buildcraft:pipeItemsDiamond_north");
_icons[PipeIconProvider.PipeItemsDiamond_South] = iconRegister.registerIcon("buildcraft:pipeItemsDiamond_south");
_icons[PipeIconProvider.PipeItemsDiamond_West] = iconRegister.registerIcon("buildcraft:pipeItemsDiamond_west");
_icons[PipeIconProvider.PipeItemsDiamond_East] = iconRegister.registerIcon("buildcraft:pipeItemsDiamond_east");
_icons[PipeIconProvider.PipeItemsWood_Standard] = iconRegister.registerIcon("buildcraft:pipeItemsWood_standard");
_icons[PipeIconProvider.PipeAllWood_Solid] = iconRegister.registerIcon("buildcraft:pipeAllWood_solid");
_icons[PipeIconProvider.PipeItemsEmerald_Standard] = iconRegister.registerIcon("buildcraft:pipeItemsEmerald_standard");
_icons[PipeIconProvider.PipeAllEmerald_Solid] = iconRegister.registerIcon("buildcraft:pipeAllEmerald_solid");
_icons[PipeIconProvider.PipeItemsGold] = iconRegister.registerIcon("buildcraft:pipeItemsGold");
_icons[PipeIconProvider.PipeItemsIron_Standard] = iconRegister.registerIcon("buildcraft:pipeItemsIron_standard");
_icons[PipeIconProvider.PipeAllIron_Solid] = iconRegister.registerIcon("buildcraft:pipeAllIron_solid");
_icons[PipeIconProvider.PipeItemsObsidian] = iconRegister.registerIcon("buildcraft:pipeItemsObsidian");
_icons[PipeIconProvider.PipeItemsSandstone] = iconRegister.registerIcon("buildcraft:pipeItemsSandstone");
_icons[PipeIconProvider.PipeItemsStone] = iconRegister.registerIcon("buildcraft:pipeItemsStone");
_icons[PipeIconProvider.PipeItemsQuartz] = iconRegister.registerIcon("buildcraft:pipeItemsQuartz");
_icons[PipeIconProvider.PipeItemsVoid] = iconRegister.registerIcon("buildcraft:pipeItemsVoid");
_icons[PipeIconProvider.PipeLiquidsCobblestone] = iconRegister.registerIcon("buildcraft:pipeLiquidsCobblestone");
_icons[PipeIconProvider.PipeLiquidsWood_Standard] = iconRegister.registerIcon("buildcraft:pipeLiquidsWood_standard");
_icons[PipeIconProvider.PipeLiquidsEmerald_Standard] = iconRegister.registerIcon("buildcraft:pipeLiquidsEmerald_standard");
_icons[PipeIconProvider.PipeLiquidsGold] = iconRegister.registerIcon("buildcraft:pipeLiquidsGold");
_icons[PipeIconProvider.PipeLiquidsIron_Standard] = iconRegister.registerIcon("buildcraft:pipeLiquidsIron_standard");
_icons[PipeIconProvider.PipeLiquidsSandstone] = iconRegister.registerIcon("buildcraft:pipeLiquidsSandstone");
_icons[PipeIconProvider.PipeLiquidsStone] = iconRegister.registerIcon("buildcraft:pipeLiquidsStone");
_icons[PipeIconProvider.PipeLiquidsVoid] = iconRegister.registerIcon("buildcraft:pipeLiquidsVoid");
_icons[PipeIconProvider.PipePowerDiamond] = iconRegister.registerIcon("buildcraft:pipePowerDiamond");
_icons[PipeIconProvider.PipePowerGold] = iconRegister.registerIcon("buildcraft:pipePowerGold");
_icons[PipeIconProvider.PipePowerQuartz] = iconRegister.registerIcon("buildcraft:pipePowerQuartz");
_icons[PipeIconProvider.PipePowerStone] = iconRegister.registerIcon("buildcraft:pipePowerStone");
_icons[PipeIconProvider.PipePowerCobblestone] = iconRegister.registerIcon("buildcraft:pipePowerCobblestone");
_icons[PipeIconProvider.PipePowerWood_Standard] = iconRegister.registerIcon("buildcraft:pipePowerWood_standard");
_icons[PipeIconProvider.Power_Normal] = iconRegister.registerIcon("buildcraft:texture_cyan");
_icons[PipeIconProvider.Power_Overload] = iconRegister.registerIcon("buildcraft:texture_red_lit");
_icons[PipeIconProvider.Stripes] = iconRegister.registerIcon("buildcraft:pipeStripes");
} }
} }

View file

@ -13,10 +13,11 @@ import net.minecraftforge.common.ForgeDirection;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITrigger;
import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerEmitter;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.core.DefaultProps; import buildcraft.core.DefaultProps;
import buildcraft.core.IMachine;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import buildcraft.transport.network.PacketPowerUpdate; import buildcraft.transport.network.PacketPowerUpdate;
@ -42,15 +43,15 @@ public class PipeTransportPower extends PipeTransport {
} }
private boolean needsInit = true; private boolean needsInit = true;
private TileEntity[] tiles = new TileEntity[6]; private TileEntity[] tiles = new TileEntity[6];
public double[] displayPower = new double[6]; public float[] displayPower = new float[6];
public double[] prevDisplayPower = new double[6]; public float[] prevDisplayPower = new float[6];
public short[] clientDisplayPower = new short[6]; public short[] clientDisplayPower = new short[6];
public int overload; public int overload;
public int[] powerQuery = new int[6]; public int[] powerQuery = new int[6];
public int[] nextPowerQuery = new int[6]; public int[] nextPowerQuery = new int[6];
public long currentDate; public long currentDate;
public double[] internalPower = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; public float[] internalPower = new float[6];
public double[] internalNextPower = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; public float[] internalNextPower = new float[6];
public int maxPower = 8; public int maxPower = 8;
public PipeTransportPower() { public PipeTransportPower() {
@ -70,9 +71,23 @@ public class PipeTransportPower extends PipeTransport {
Pipe pipe2 = ((TileGenericPipe) tile).pipe; Pipe pipe2 = ((TileGenericPipe) tile).pipe;
if (BlockGenericPipe.isValid(pipe2) && !(pipe2.transport instanceof PipeTransportPower)) if (BlockGenericPipe.isValid(pipe2) && !(pipe2.transport instanceof PipeTransportPower))
return false; return false;
return true;
} }
return tile instanceof TileGenericPipe || tile instanceof IMachine || tile instanceof IPowerReceptor; if (tile instanceof IPowerReceptor) {
IPowerReceptor receptor = (IPowerReceptor) tile;
PowerReceiver receiver = receptor.getPowerReceiver(side.getOpposite());
if (receiver != null && receiver.getType().canReceiveFromPipes())
return true;
}
if (container.pipe instanceof PipePowerWood && tile instanceof IPowerEmitter) {
IPowerEmitter emitter = (IPowerEmitter) tile;
if (emitter.canEmitPowerFrom(side.getOpposite()))
return true;
}
return false;
} }
@Override @Override
@ -114,11 +129,11 @@ public class PipeTransportPower extends PipeTransport {
// Send the power to nearby pipes who requested it // Send the power to nearby pipes who requested it
System.arraycopy(displayPower, 0, prevDisplayPower, 0, 6); System.arraycopy(displayPower, 0, prevDisplayPower, 0, 6);
Arrays.fill(displayPower, 0.0); Arrays.fill(displayPower, 0.0F);
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 6; ++i) {
if (internalPower[i] > 0) { if (internalPower[i] > 0) {
double totalPowerQuery = 0; float totalPowerQuery = 0;
for (int j = 0; j < 6; ++j) { for (int j = 0; j < 6; ++j) {
if (j != i && powerQuery[j] > 0) if (j != i && powerQuery[j] > 0)
@ -129,27 +144,21 @@ public class PipeTransportPower extends PipeTransport {
for (int j = 0; j < 6; ++j) { for (int j = 0; j < 6; ++j) {
if (j != i && powerQuery[j] > 0) { if (j != i && powerQuery[j] > 0) {
double watts = 0.0; float watts = 0.0F;
if (tiles[j] instanceof TileGenericPipe) { PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[j]);
watts = (internalPower[i] / totalPowerQuery * powerQuery[j]); if (prov != null && prov.powerRequest() > 0) {
watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
watts = prov.receiveEnergy(Type.PIPE, watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
internalPower[i] -= watts;
} else if (tiles[j] instanceof TileGenericPipe) {
watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
TileGenericPipe nearbyTile = (TileGenericPipe) tiles[j]; TileGenericPipe nearbyTile = (TileGenericPipe) tiles[j];
PipeTransportPower nearbyTransport = (PipeTransportPower) nearbyTile.pipe.transport; PipeTransportPower nearbyTransport = (PipeTransportPower) nearbyTile.pipe.transport;
watts = nearbyTransport.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), watts); watts = nearbyTransport.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), watts);
internalPower[i] -= watts; internalPower[i] -= watts;
} else if (tiles[j] instanceof IPowerReceptor) {
IPowerReceptor pow = (IPowerReceptor) tiles[j];
if (pow.powerRequest(ForgeDirection.VALID_DIRECTIONS[j].getOpposite()) > 0) {
watts = (internalPower[i] / totalPowerQuery * powerQuery[j]);
IPowerProvider prov = pow.getPowerProvider();
if (prov != null) {
prov.receiveEnergy((float) watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
internalPower[i] -= watts;
}
}
} }
displayPower[j] += watts; displayPower[j] += watts;
@ -161,7 +170,7 @@ public class PipeTransportPower extends PipeTransport {
double highestPower = 0; double highestPower = 0;
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
displayPower[i] = (prevDisplayPower[i] * (DISPLAY_SMOOTHING - 1.0) + displayPower[i]) / DISPLAY_SMOOTHING; displayPower[i] = (prevDisplayPower[i] * (DISPLAY_SMOOTHING - 1.0F) + displayPower[i]) / DISPLAY_SMOOTHING;
if (displayPower[i] > highestPower) { if (displayPower[i] > highestPower) {
highestPower = displayPower[i]; highestPower = displayPower[i];
} }
@ -175,12 +184,12 @@ public class PipeTransportPower extends PipeTransport {
overload = OVERLOAD_TICKS; overload = OVERLOAD_TICKS;
} }
// Compute the tiles requesting energy that are not pipes // Compute the tiles requesting energy that are not power pipes
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 6; ++i) {
if (tiles[i] instanceof IPowerReceptor && !(tiles[i] instanceof TileGenericPipe)) { PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[i]);
IPowerReceptor receptor = (IPowerReceptor) tiles[i]; if (prov != null) {
int request = receptor.powerRequest(ForgeDirection.VALID_DIRECTIONS[i].getOpposite()); float request = prov.powerRequest();
if (request > 0) { if (request > 0) {
requestEnergy(ForgeDirection.VALID_DIRECTIONS[i], request); requestEnergy(ForgeDirection.VALID_DIRECTIONS[i], request);
@ -240,6 +249,19 @@ public class PipeTransportPower extends PipeTransport {
} }
private PowerReceiver getReceiverOnSide(ForgeDirection side) {
TileEntity tile = tiles[side.ordinal()];
if (!(tile instanceof IPowerReceptor))
return null;
IPowerReceptor receptor = (IPowerReceptor) tile;
PowerReceiver receiver = receptor.getPowerReceiver(side.getOpposite());
if (receiver == null)
return null;
if (!receiver.getType().canReceiveFromPipes())
return null;
return receiver;
}
public boolean isOverloaded() { public boolean isOverloaded() {
return overload >= OVERLOAD_TICKS; return overload >= OVERLOAD_TICKS;
} }
@ -251,7 +273,7 @@ public class PipeTransportPower extends PipeTransport {
powerQuery = nextPowerQuery; powerQuery = nextPowerQuery;
nextPowerQuery = new int[6]; nextPowerQuery = new int[6];
double[] next = internalPower; float[] next = internalPower;
internalPower = internalNextPower; internalPower = internalNextPower;
internalNextPower = next; internalNextPower = next;
// for (int i = 0; i < powerQuery.length; i++) { // for (int i = 0; i < powerQuery.length; i++) {
@ -268,7 +290,12 @@ public class PipeTransportPower extends PipeTransport {
} }
} }
public double receiveEnergy(ForgeDirection from, double val) { /**
* Do NOT ever call this from outside Buildcraft unless you are a pipe mod.
* It is NOT part of the API. All power input MUST go through designated
* input pipes, such as Wooden Power Pipes.
*/
public float receiveEnergy(ForgeDirection from, float val) {
step(); step();
if (this.container.pipe instanceof IPipeTransportPowerHook) { if (this.container.pipe instanceof IPipeTransportPowerHook) {
return ((IPipeTransportPowerHook) this.container.pipe).receiveEnergy(from, val); return ((IPipeTransportPowerHook) this.container.pipe).receiveEnergy(from, val);
@ -283,7 +310,7 @@ public class PipeTransportPower extends PipeTransport {
return val; return val;
} }
public void requestEnergy(ForgeDirection from, int amount) { public void requestEnergy(ForgeDirection from, float amount) {
step(); step();
if (this.container.pipe instanceof IPipeTransportPowerHook) { if (this.container.pipe instanceof IPipeTransportPowerHook) {
((IPipeTransportPowerHook) this.container.pipe).requestEnergy(from, amount); ((IPipeTransportPowerHook) this.container.pipe).requestEnergy(from, amount);
@ -304,8 +331,8 @@ public class PipeTransportPower extends PipeTransport {
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 6; ++i) {
powerQuery[i] = nbttagcompound.getInteger("powerQuery[" + i + "]"); powerQuery[i] = nbttagcompound.getInteger("powerQuery[" + i + "]");
nextPowerQuery[i] = nbttagcompound.getInteger("nextPowerQuery[" + i + "]"); nextPowerQuery[i] = nbttagcompound.getInteger("nextPowerQuery[" + i + "]");
internalPower[i] = nbttagcompound.getDouble("internalPower[" + i + "]"); internalPower[i] = (float) nbttagcompound.getDouble("internalPower[" + i + "]");
internalNextPower[i] = nbttagcompound.getDouble("internalNextPower[" + i + "]"); internalNextPower[i] = (float) nbttagcompound.getDouble("internalNextPower[" + i + "]");
} }
} }

View file

@ -29,8 +29,9 @@ import buildcraft.api.core.Position;
import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.IOverrideDefaultTriggers; import buildcraft.api.gates.IOverrideDefaultTriggers;
import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITrigger;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.transport.IPipe; import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.IPipeConnection; import buildcraft.api.transport.IPipeConnection;
import buildcraft.api.transport.IPipeEntry; import buildcraft.api.transport.IPipeEntry;
@ -179,10 +180,10 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
refreshRenderState = false; refreshRenderState = false;
} }
IPowerProvider provider = getPowerProvider(); PowerReceiver provider = getPowerReceiver(null);
if (provider != null) { if (provider != null) {
provider.update(this); provider.update();
} }
if (pipe != null) { if (pipe != null) {
@ -319,25 +320,17 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
} }
@Override @Override
public void setPowerProvider(IPowerProvider provider) { public PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side) {
if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) {
((IPowerReceptor) pipe).setPowerProvider(provider);
}
}
@Override
public IPowerProvider getPowerProvider() {
if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor)
return ((IPowerReceptor) pipe).getPowerProvider(); return ((IPowerReceptor) pipe).getPowerReceiver(null);
else else
return null; return null;
} }
@Override @Override
public void doWork() { public void doWork(PowerHandler workProvider) {
if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) { if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) {
((IPowerReceptor) pipe).doWork(); ((IPowerReceptor) pipe).doWork(workProvider);
} }
} }
@ -412,13 +405,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
return packet.getPacket(); return packet.getPacket();
} }
@Override
public int powerRequest(ForgeDirection from) {
if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor)
return ((IPowerReceptor) pipe).powerRequest(from);
return 0;
}
@Override @Override
public LinkedList<ITrigger> getTriggers() { public LinkedList<ITrigger> getTriggers() {
LinkedList<ITrigger> result = new LinkedList<ITrigger>(); LinkedList<ITrigger> result = new LinkedList<ITrigger>();

View file

@ -32,7 +32,7 @@ public class PipeItemsCobblestone extends Pipe {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeItemsCobbleStone; return PipeIconProvider.TYPE.PipeItemsCobbleStone.ordinal();
} }
} }

View file

@ -45,13 +45,13 @@ public class PipeItemsDiamond extends Pipe implements IPipeTransportItemsHook, I
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
switch(direction){ switch(direction){
case UNKNOWN: return PipeIconProvider.PipeItemsDiamond_Center; case UNKNOWN: return PipeIconProvider.TYPE.PipeItemsDiamond_Center.ordinal();
case DOWN: return PipeIconProvider.PipeItemsDiamond_Down; case DOWN: return PipeIconProvider.TYPE.PipeItemsDiamond_Down.ordinal();
case UP: return PipeIconProvider.PipeItemsDiamond_Up; case UP: return PipeIconProvider.TYPE.PipeItemsDiamond_Up.ordinal();
case NORTH: return PipeIconProvider.PipeItemsDiamond_North; case NORTH: return PipeIconProvider.TYPE.PipeItemsDiamond_North.ordinal();
case SOUTH: return PipeIconProvider.PipeItemsDiamond_South; case SOUTH: return PipeIconProvider.TYPE.PipeItemsDiamond_South.ordinal();
case WEST: return PipeIconProvider.PipeItemsDiamond_West; case WEST: return PipeIconProvider.TYPE.PipeItemsDiamond_West.ordinal();
case EAST: return PipeIconProvider.PipeItemsDiamond_East; case EAST: return PipeIconProvider.TYPE.PipeItemsDiamond_East.ordinal();
default: throw new IllegalArgumentException("direction out of bounds"); default: throw new IllegalArgumentException("direction out of bounds");
} }
} }

View file

@ -40,8 +40,8 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState {
protected PipeItemsEmerald(int itemID, PipeTransportItems transport) { protected PipeItemsEmerald(int itemID, PipeTransportItems transport) {
super(transport, new PipeLogicEmerald(), itemID); super(transport, new PipeLogicEmerald(), itemID);
standardIconIndex = PipeIconProvider.PipeItemsEmerald_Standard; standardIconIndex = PipeIconProvider.TYPE.PipeItemsEmerald_Standard.ordinal();
solidIconIndex = PipeIconProvider.PipeAllEmerald_Solid; solidIconIndex = PipeIconProvider.TYPE.PipeAllEmerald_Solid.ordinal();
} }
public PipeItemsEmerald(int itemID) { public PipeItemsEmerald(int itemID) {
@ -77,11 +77,11 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState {
/* ISELECTIVEINVENTORY */ /* ISELECTIVEINVENTORY */
if (inventory instanceof ISelectiveInventory) { if (inventory instanceof ISelectiveInventory) {
ItemStack[] stacks = ((ISelectiveInventory) inventory).extractItem(new ItemStack[]{getCurrentFilter()}, false, doRemove, from, (int) getPowerProvider().getEnergyStored()); ItemStack[] stacks = ((ISelectiveInventory) inventory).extractItem(new ItemStack[]{getCurrentFilter()}, false, doRemove, from, (int) powerHandler.getEnergyStored());
if (doRemove) { if (doRemove) {
for (ItemStack stack : stacks) { for (ItemStack stack : stacks) {
if (stack != null) { if (stack != null) {
getPowerProvider().useEnergy(stack.stackSize, stack.stackSize, true); powerHandler.useEnergy(stack.stackSize, stack.stackSize, true);
} }
} }
incrementFilter(); incrementFilter();
@ -90,7 +90,7 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState {
/* ISPECIALINVENTORY */ /* ISPECIALINVENTORY */
} else if (inventory instanceof ISpecialInventory) { } else if (inventory instanceof ISpecialInventory) {
ItemStack[] stacks = ((ISpecialInventory) inventory).extractItem(false, from, (int) getPowerProvider().getEnergyStored()); ItemStack[] stacks = ((ISpecialInventory) inventory).extractItem(false, from, (int) powerHandler.getEnergyStored());
if (stacks != null) { if (stacks != null) {
for (ItemStack stack : stacks) { for (ItemStack stack : stacks) {
if(stack == null) if(stack == null)
@ -109,10 +109,10 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState {
} }
} }
if (doRemove) { if (doRemove) {
stacks = ((ISpecialInventory) inventory).extractItem(true, from, (int) getPowerProvider().getEnergyStored()); stacks = ((ISpecialInventory) inventory).extractItem(true, from, (int) powerHandler.getEnergyStored());
for (ItemStack stack : stacks) { for (ItemStack stack : stacks) {
if (stack != null) { if (stack != null) {
getPowerProvider().useEnergy(stack.stackSize, stack.stackSize, true); powerHandler.useEnergy(stack.stackSize, stack.stackSize, true);
} }
} }
} }
@ -168,7 +168,7 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState {
} }
if (doRemove) { if (doRemove) {
incrementFilter(); incrementFilter();
return inventory.decrStackSize(i, (int) getPowerProvider().useEnergy(1, stack.stackSize, true)); return inventory.decrStackSize(i, (int) powerHandler.useEnergy(1, stack.stackSize, true));
} else { } else {
return stack; return stack;
} }

View file

@ -37,7 +37,7 @@ public class PipeItemsGold extends Pipe implements IPipeTransportItemsHook {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeItemsGold; return PipeIconProvider.TYPE.PipeItemsGold.ordinal();
} }
@Override @Override

View file

@ -19,8 +19,8 @@ import cpw.mods.fml.relauncher.SideOnly;
public class PipeItemsIron extends Pipe { public class PipeItemsIron extends Pipe {
private int standardIconIndex = PipeIconProvider.PipeItemsIron_Standard; private int standardIconIndex = PipeIconProvider.TYPE.PipeItemsIron_Standard.ordinal();
private int solidIconIndex = PipeIconProvider.PipeAllIron_Solid; private int solidIconIndex = PipeIconProvider.TYPE.PipeAllIron_Solid.ordinal();
public PipeItemsIron(int itemID) { public PipeItemsIron(int itemID) {
super(new PipeTransportItems(), new PipeLogicIron(), itemID); super(new PipeTransportItems(), new PipeLogicIron(), itemID);
@ -35,7 +35,7 @@ public class PipeItemsIron extends Pipe {
else { else {
int metadata = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); int metadata = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
if (metadata == direction.ordinal()) if (metadata != direction.ordinal())
return solidIconIndex; return solidIconIndex;
else else
return standardIconIndex; return standardIconIndex;

View file

@ -22,9 +22,10 @@ import net.minecraftforge.common.ForgeDirection;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider; import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position; import buildcraft.api.core.Position;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.api.transport.IPipedItem; import buildcraft.api.transport.IPipedItem;
import buildcraft.core.EntityPassiveItem; import buildcraft.core.EntityPassiveItem;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
@ -37,7 +38,7 @@ import cpw.mods.fml.relauncher.SideOnly;
public class PipeItemsObsidian extends Pipe implements IPowerReceptor { public class PipeItemsObsidian extends Pipe implements IPowerReceptor {
private IPowerProvider powerProvider; private PowerHandler powerHandler;
private int[] entitiesDropped; private int[] entitiesDropped;
private int entitiesDroppedIndex = 0; private int entitiesDroppedIndex = 0;
@ -51,9 +52,9 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor {
entitiesDropped[i] = -1; entitiesDropped[i] = -1;
} }
powerProvider = PowerFramework.currentFramework.createPowerProvider(); powerHandler = new PowerHandler(this, Type.MACHINE);
powerProvider.configure(25, 1, 64, 1, 256); powerHandler.configure(1, 64, 1, 256);
powerProvider.configurePowerPerdition(1, 1); powerHandler.configurePowerPerdition(1, 1);
} }
@Override @Override
@ -64,7 +65,7 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeItemsObsidian; return PipeIconProvider.TYPE.PipeItemsObsidian.ordinal();
} }
@Override @Override
@ -145,12 +146,12 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor {
} }
@Override @Override
public void doWork() { public void doWork(PowerHandler workProvider) {
for (int j = 1; j < 5; ++j) for (int j = 1; j < 5; ++j)
if (trySucc(j)) if (trySucc(j))
return; return;
powerProvider.useEnergy(1, 1, true); powerHandler.useEnergy(1, 1, true);
} }
private boolean trySucc(int distance) { private boolean trySucc(int distance) {
@ -175,7 +176,7 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor {
EntityMinecartChest cart = (EntityMinecartChest) list.get(g); EntityMinecartChest cart = (EntityMinecartChest) list.get(g);
if (!cart.isDead) { if (!cart.isDead) {
ItemStack stack = checkExtractGeneric(cart, true, getOpenOrientation()); ItemStack stack = checkExtractGeneric(cart, true, getOpenOrientation());
if (stack != null && powerProvider.useEnergy(1, 1, true) == 1) { if (stack != null && powerHandler.useEnergy(1, 1, true) == 1) {
EntityItem entityitem = new EntityItem(worldObj, cart.posX, cart.posY + 0.3F, cart.posZ, stack); EntityItem entityitem = new EntityItem(worldObj, cart.posX, cart.posY + 0.3F, cart.posZ, stack);
entityitem.delayBeforeCanPickup = 10; entityitem.delayBeforeCanPickup = 10;
worldObj.spawnEntityInWorld(entityitem); worldObj.spawnEntityInWorld(entityitem);
@ -224,7 +225,7 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor {
CoreProxy.proxy.obsidianPipePickup(worldObj, item, this.container); CoreProxy.proxy.obsidianPipePickup(worldObj, item, this.container);
float energyUsed = powerProvider.useEnergy(distance, contained.stackSize * distance, true); float energyUsed = powerHandler.useEnergy(distance, contained.stackSize * distance, true);
if (distance == 0 || energyUsed / distance == contained.stackSize) { if (distance == 0 || energyUsed / distance == contained.stackSize) {
stack = contained; stack = contained;
@ -240,7 +241,7 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor {
speed = 0.01; speed = 0.01;
} }
} else if (entity instanceof EntityArrow) { } else if (entity instanceof EntityArrow) {
powerProvider.useEnergy(distance, distance, true); powerHandler.useEnergy(distance, distance, true);
stack = new ItemStack(Item.arrow, 1); stack = new ItemStack(Item.arrow, 1);
CoreProxy.proxy.removeEntity(entity); CoreProxy.proxy.removeEntity(entity);
} }
@ -277,25 +278,15 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor {
if (item.entityId == entitiesDropped[i]) if (item.entityId == entitiesDropped[i])
return false; return false;
return powerProvider.useEnergy(1, distance, false) >= distance; return powerHandler.useEnergy(1, distance, false) >= distance;
} else if (entity instanceof EntityArrow) } else if (entity instanceof EntityArrow)
return powerProvider.useEnergy(1, distance, false) >= distance; return powerHandler.useEnergy(1, distance, false) >= distance;
else else
return false; return false;
} }
@Override @Override
public void setPowerProvider(IPowerProvider provider) { public PowerReceiver getPowerReceiver(ForgeDirection side) {
powerProvider = provider; return powerHandler.getPowerReceiver();
}
@Override
public IPowerProvider getPowerProvider() {
return powerProvider;
}
@Override
public int powerRequest(ForgeDirection from) {
return getPowerProvider().getMaxEnergyReceived();
} }
} }

View file

@ -37,7 +37,7 @@ public class PipeItemsQuartz extends Pipe implements IPipeTransportItemsHook {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeItemsQuartz; return PipeIconProvider.TYPE.PipeItemsQuartz.ordinal();
} }
@Override @Override

View file

@ -31,6 +31,6 @@ public class PipeItemsSandstone extends Pipe {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeItemsSandstone; return PipeIconProvider.TYPE.PipeItemsSandstone.ordinal();
} }
} }

View file

@ -38,7 +38,7 @@ public class PipeItemsStone extends Pipe implements IPipeTransportItemsHook {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeItemsStone; return PipeIconProvider.TYPE.PipeItemsStone.ordinal();
} }
@Override @Override

View file

@ -36,7 +36,7 @@ public class PipeItemsVoid extends Pipe implements IItemTravelingHook {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeItemsVoid; return PipeIconProvider.TYPE.PipeItemsVoid.ordinal();
} }
// This is called if the void pipe is only connected to one pipe // This is called if the void pipe is only connected to one pipe

View file

@ -11,19 +11,18 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider; import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position; import buildcraft.api.core.Position;
import buildcraft.api.inventory.ISpecialInventory; import buildcraft.api.inventory.ISpecialInventory;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.api.transport.IPipedItem; import buildcraft.api.transport.IPipedItem;
import buildcraft.api.transport.PipeManager; import buildcraft.api.transport.PipeManager;
import buildcraft.core.EntityPassiveItem; import buildcraft.core.EntityPassiveItem;
import buildcraft.core.RedstonePowerFramework;
import buildcraft.core.inventory.InventoryWrapper; import buildcraft.core.inventory.InventoryWrapper;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
@ -34,16 +33,16 @@ import cpw.mods.fml.relauncher.SideOnly;
public class PipeItemsWood extends Pipe implements IPowerReceptor { public class PipeItemsWood extends Pipe implements IPowerReceptor {
private IPowerProvider powerProvider; protected PowerHandler powerHandler;
protected int standardIconIndex = PipeIconProvider.PipeItemsWood_Standard; protected int standardIconIndex = PipeIconProvider.TYPE.PipeItemsWood_Standard.ordinal();
protected int solidIconIndex = PipeIconProvider.PipeAllWood_Solid; protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllWood_Solid.ordinal();
protected PipeItemsWood(PipeTransportItems transport, PipeLogic logic, int itemID) { protected PipeItemsWood(PipeTransportItems transport, PipeLogic logic, int itemID) {
super(transport, logic, itemID); super(transport, logic, itemID);
powerProvider = PowerFramework.currentFramework.createPowerProvider(); powerHandler = new PowerHandler(this, Type.MACHINE);
powerProvider.configure(50, 1, 64, 1, 64); powerHandler.configure(1, 64, 1, 64);
powerProvider.configurePowerPerdition(64, 1); powerHandler.configurePowerPerdition(0, 0);
} }
protected PipeItemsWood(int itemID, PipeTransportItems transport) { protected PipeItemsWood(int itemID, PipeTransportItems transport) {
@ -75,33 +74,31 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
} }
@Override @Override
public void setPowerProvider(IPowerProvider provider) { public PowerReceiver getPowerReceiver(ForgeDirection side) {
powerProvider = provider; return powerHandler.getPowerReceiver();
} }
@Override @Override
public IPowerProvider getPowerProvider() { public void doWork(PowerHandler workProvider) {
return powerProvider; if (powerHandler.getEnergyStored() <= 0)
}
@Override
public void doWork() {
if (powerProvider.getEnergyStored() <= 0)
return; return;
World w = worldObj; extractItems();
powerHandler.setEnergy(0);
}
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); private void extractItems() {
int meta = container.getBlockMetadata();
if (meta > 5) if (meta > 5)
return; return;
Position pos = new Position(xCoord, yCoord, zCoord, ForgeDirection.getOrientation(meta)); Position pos = new Position(xCoord, yCoord, zCoord, ForgeDirection.getOrientation(meta));
pos.moveForwards(1); pos.moveForwards(1);
TileEntity tile = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
if (tile instanceof IInventory) { if (tile instanceof IInventory) {
if (!PipeManager.canExtractItems(this, w, (int) pos.x, (int) pos.y, (int) pos.z)) if (!PipeManager.canExtractItems(this, worldObj, (int) pos.x, (int) pos.y, (int) pos.z))
return; return;
IInventory inventory = (IInventory) tile; IInventory inventory = (IInventory) tile;
@ -112,7 +109,7 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
for (ItemStack stack : extracted) { for (ItemStack stack : extracted) {
if (stack == null || stack.stackSize == 0) { if (stack == null || stack.stackSize == 0) {
powerProvider.useEnergy(1, 1, false); powerHandler.useEnergy(1, 1, true);
continue; continue;
} }
@ -120,7 +117,7 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
entityPos.moveForwards(0.6); entityPos.moveForwards(0.6);
IPipedItem entity = new EntityPassiveItem(w, entityPos.x, entityPos.y, entityPos.z, stack); IPipedItem entity = new EntityPassiveItem(worldObj, entityPos.x, entityPos.y, entityPos.z, stack);
((PipeTransportItems) transport).entityEntering(entity, entityPos.orientation); ((PipeTransportItems) transport).entityEntering(entity, entityPos.orientation);
} }
@ -136,11 +133,11 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
/* ISPECIALINVENTORY */ /* ISPECIALINVENTORY */
if (inventory instanceof ISpecialInventory) { if (inventory instanceof ISpecialInventory) {
ItemStack[] stacks = ((ISpecialInventory) inventory).extractItem(doRemove, from, (int) powerProvider.getEnergyStored()); ItemStack[] stacks = ((ISpecialInventory) inventory).extractItem(doRemove, from, (int) powerHandler.getEnergyStored());
if (stacks != null && doRemove) { if (stacks != null && doRemove) {
for (ItemStack stack : stacks) { for (ItemStack stack : stacks) {
if (stack != null) { if (stack != null) {
powerProvider.useEnergy(stack.stackSize, stack.stackSize, true); powerHandler.useEnergy(stack.stackSize, stack.stackSize, true);
} }
} }
} }
@ -168,7 +165,7 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
if (slot != null && slot.stackSize > 0 && inventory.canExtractItem(k, slot, from.ordinal())) { if (slot != null && slot.stackSize > 0 && inventory.canExtractItem(k, slot, from.ordinal())) {
if (doRemove) { if (doRemove) {
return inventory.decrStackSize(k, (int) powerProvider.useEnergy(1, slot.stackSize, true)); return inventory.decrStackSize(k, (int) powerHandler.useEnergy(1, slot.stackSize, true));
} else { } else {
return slot; return slot;
} }
@ -177,16 +174,4 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
return null; return null;
} }
@Override
public int powerRequest(ForgeDirection from) {
return getPowerProvider().getMaxEnergyReceived();
}
@Override
public boolean canConnectRedstone() {
if (PowerFramework.currentFramework instanceof RedstonePowerFramework)
return true;
return super.canConnectRedstone();
}
} }

View file

@ -31,6 +31,6 @@ public class PipeLiquidsCobblestone extends Pipe {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeLiquidsCobblestone; return PipeIconProvider.TYPE.PipeLiquidsCobblestone.ordinal();
} }
} }

View file

@ -20,8 +20,8 @@ public class PipeLiquidsEmerald extends PipeLiquidsWood {
public PipeLiquidsEmerald(int itemID) { public PipeLiquidsEmerald(int itemID) {
super(new PipeLogicEmerald(), itemID); super(new PipeLogicEmerald(), itemID);
standardIconIndex = PipeIconProvider.PipeLiquidsEmerald_Standard; standardIconIndex = PipeIconProvider.TYPE.PipeLiquidsEmerald_Standard.ordinal();
solidIconIndex = PipeIconProvider.PipeAllEmerald_Solid; solidIconIndex = PipeIconProvider.TYPE.PipeAllEmerald_Solid.ordinal();
((PipeTransportLiquids) transport).flowRate = 40; ((PipeTransportLiquids) transport).flowRate = 40;
((PipeTransportLiquids) transport).travelDelay = 4; ((PipeTransportLiquids) transport).travelDelay = 4;

View file

@ -34,7 +34,7 @@ public class PipeLiquidsGold extends Pipe {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeLiquidsGold; return PipeIconProvider.TYPE.PipeLiquidsGold.ordinal();
} }
} }

View file

@ -19,8 +19,8 @@ import cpw.mods.fml.relauncher.SideOnly;
public class PipeLiquidsIron extends Pipe { public class PipeLiquidsIron extends Pipe {
protected int standardIconIndex = PipeIconProvider.PipeLiquidsIron_Standard; protected int standardIconIndex = PipeIconProvider.TYPE.PipeLiquidsIron_Standard.ordinal();
protected int solidIconIndex = PipeIconProvider.PipeAllIron_Solid; protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllIron_Solid.ordinal();
public PipeLiquidsIron(int itemID) { public PipeLiquidsIron(int itemID) {

View file

@ -34,7 +34,7 @@ public class PipeLiquidsSandstone extends Pipe implements IPipeTransportLiquidsH
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeLiquidsSandstone; return PipeIconProvider.TYPE.PipeLiquidsSandstone.ordinal();
} }
@Override @Override

View file

@ -33,7 +33,7 @@ public class PipeLiquidsStone extends Pipe {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeLiquidsStone; return PipeIconProvider.TYPE.PipeLiquidsStone.ordinal();
} }
} }

View file

@ -34,7 +34,7 @@ public class PipeLiquidsVoid extends Pipe implements IPipeTransportLiquidsHook {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeLiquidsVoid; return PipeIconProvider.TYPE.PipeLiquidsVoid.ordinal();
} }
@Override @Override

View file

@ -17,11 +17,11 @@ import net.minecraftforge.liquids.LiquidStack;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider; import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position; import buildcraft.api.core.Position;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.api.transport.PipeManager; import buildcraft.api.transport.PipeManager;
import buildcraft.core.RedstonePowerFramework;
import buildcraft.core.network.TileNetworkData; import buildcraft.core.network.TileNetworkData;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeIconProvider;
@ -34,10 +34,10 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor {
public @TileNetworkData public @TileNetworkData
int liquidToExtract; int liquidToExtract;
private IPowerProvider powerProvider; private PowerHandler powerHandler;
protected int standardIconIndex = PipeIconProvider.PipeLiquidsWood_Standard; protected int standardIconIndex = PipeIconProvider.TYPE.PipeLiquidsWood_Standard.ordinal();
protected int solidIconIndex = PipeIconProvider.PipeAllWood_Solid; protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllWood_Solid.ordinal();
long lastMining = 0; long lastMining = 0;
boolean lastPower = false; boolean lastPower = false;
@ -49,17 +49,17 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor {
protected PipeLiquidsWood(PipeLogic logic, int itemID) { protected PipeLiquidsWood(PipeLogic logic, int itemID) {
super(new PipeTransportLiquids(), logic, itemID); super(new PipeTransportLiquids(), logic, itemID);
powerProvider = PowerFramework.currentFramework.createPowerProvider(); powerHandler = new PowerHandler(this, Type.MACHINE);
powerProvider.configure(50, 1, 100, 1, 250); powerHandler.configure(1, 100, 1, 250);
powerProvider.configurePowerPerdition(1, 1); powerHandler.configurePowerPerdition(0, 0);
} }
/** /**
* Extracts a random piece of item outside of a nearby chest. * Extracts a random piece of item outside of a nearby chest.
*/ */
@Override @Override
public void doWork() { public void doWork(PowerHandler workProvider) {
if (powerProvider.getEnergyStored() <= 0) if (powerHandler.getEnergyStored() <= 0)
return; return;
World w = worldObj; World w = worldObj;
@ -78,19 +78,15 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor {
return; return;
if (liquidToExtract <= LiquidContainerRegistry.BUCKET_VOLUME) { if (liquidToExtract <= LiquidContainerRegistry.BUCKET_VOLUME) {
liquidToExtract += powerProvider.useEnergy(1, 1, true) * LiquidContainerRegistry.BUCKET_VOLUME; liquidToExtract += powerHandler.useEnergy(1, 1, true) * LiquidContainerRegistry.BUCKET_VOLUME;
} }
} }
powerHandler.useEnergy(1, 1, true);
} }
@Override @Override
public void setPowerProvider(IPowerProvider provider) { public PowerReceiver getPowerReceiver(ForgeDirection side) {
powerProvider = provider; return powerHandler.getPowerReceiver();
}
@Override
public IPowerProvider getPowerProvider() {
return powerProvider;
} }
@Override @Override
@ -143,16 +139,4 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor {
return standardIconIndex; return standardIconIndex;
} }
} }
@Override
public int powerRequest(ForgeDirection from) {
return getPowerProvider().getMaxEnergyReceived();
}
@Override
public boolean canConnectRedstone() {
if (PowerFramework.currentFramework instanceof RedstonePowerFramework)
return true;
return super.canConnectRedstone();
}
} }

View file

@ -31,6 +31,6 @@ public class PipePowerCobblestone extends Pipe {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipePowerCobblestone; return PipeIconProvider.TYPE.PipePowerCobblestone.ordinal();
} }
} }

View file

@ -31,6 +31,6 @@ public class PipePowerDiamond extends Pipe {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipePowerDiamond; return PipeIconProvider.TYPE.PipePowerDiamond.ordinal();
} }
} }

View file

@ -31,6 +31,6 @@ public class PipePowerGold extends Pipe {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipePowerGold; return PipeIconProvider.TYPE.PipePowerGold.ordinal();
} }
} }

View file

@ -31,6 +31,6 @@ public class PipePowerQuartz extends Pipe {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipePowerQuartz; return PipeIconProvider.TYPE.PipePowerQuartz.ordinal();
} }
} }

View file

@ -31,6 +31,6 @@ public class PipePowerStone extends Pipe {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipePowerStone; return PipeIconProvider.TYPE.PipePowerStone.ordinal();
} }
} }

View file

@ -10,38 +10,36 @@ package buildcraft.transport.pipes;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider; import buildcraft.api.core.IIconProvider;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerHandler;
import buildcraft.core.utils.Utils; import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportPower; import buildcraft.transport.PipeTransportPower;
import buildcraft.transport.TileGenericPipe;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
public class PipePowerWood extends Pipe implements IPowerReceptor { public class PipePowerWood extends Pipe implements IPowerReceptor {
private IPowerProvider powerProvider; private PowerHandler powerHandler;
protected int standardIconIndex = PipeIconProvider.PipePowerWood_Standard; protected int standardIconIndex = PipeIconProvider.TYPE.PipePowerWood_Standard.ordinal();
protected int solidIconIndex = PipeIconProvider.PipeAllWood_Solid; protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllWood_Solid.ordinal();
private boolean[] powerSources = new boolean[6]; private boolean[] powerSources = new boolean[6];
private boolean full; private boolean full;
public PipePowerWood(int itemID) { public PipePowerWood(int itemID) {
super(new PipeTransportPower(), new PipeLogicWood(), itemID); super(new PipeTransportPower(), new PipeLogicWood(), itemID);
powerProvider = PowerFramework.currentFramework.createPowerProvider(); powerHandler = new PowerHandler(this, Type.PIPE);
initPowerProvider(); initPowerProvider();
((PipeTransportPower) transport).initFromPipe(getClass()); ((PipeTransportPower) transport).initFromPipe(getClass());
} }
private void initPowerProvider() { private void initPowerProvider() {
powerProvider.configure(50, 2, 1000, 1, 1500); powerHandler.configure(2, 1000, 1, 1500);
powerProvider.configurePowerPerdition(1, 10); powerHandler.configurePowerPerdition(1, 10);
} }
@Override @Override
@ -52,31 +50,16 @@ public class PipePowerWood extends Pipe implements IPowerReceptor {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
if (direction == ForgeDirection.UNKNOWN)
return standardIconIndex;
else {
int metadata = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
if (metadata == direction.ordinal())
return solidIconIndex;
else
return standardIconIndex; return standardIconIndex;
} }
@Override
public PowerReceiver getPowerReceiver(ForgeDirection side) {
return powerHandler.getPowerReceiver();
} }
@Override @Override
public void setPowerProvider(IPowerProvider provider) { public void doWork(PowerHandler workProvider) {
powerProvider = provider;
}
@Override
public IPowerProvider getPowerProvider() {
return powerProvider;
}
@Override
public void doWork() {
// TODO Auto-generated method stub
} }
@Override @Override
@ -85,7 +68,7 @@ public class PipePowerWood extends Pipe implements IPowerReceptor {
if (worldObj.isRemote) if (worldObj.isRemote)
return; return;
if (powerProvider.getEnergyStored() <= 0) if (powerHandler.getEnergyStored() <= 0)
return; return;
int sources = 0; int sources = 0;
@ -94,7 +77,7 @@ public class PipePowerWood extends Pipe implements IPowerReceptor {
powerSources[o.ordinal()] = false; powerSources[o.ordinal()] = false;
continue; continue;
} }
if (powerProvider.isPowerSource(o)) { if (powerHandler.isPowerSource(o)) {
powerSources[o.ordinal()] = true; powerSources[o.ordinal()] = true;
} }
if (powerSources[o.ordinal()]) { if (powerSources[o.ordinal()]) {
@ -102,15 +85,17 @@ public class PipePowerWood extends Pipe implements IPowerReceptor {
} }
} }
if (sources <= 0) if (sources <= 0) {
powerHandler.useEnergy(5, 5, true);
return; return;
}
float energyToRemove; float energyToRemove;
if (powerProvider.getEnergyStored() > 40) { if (powerHandler.getEnergyStored() > 40) {
energyToRemove = powerProvider.getEnergyStored() / 40 + 4; energyToRemove = powerHandler.getEnergyStored() / 40 + 4;
} else if (powerProvider.getEnergyStored() > 10) { } else if (powerHandler.getEnergyStored() > 10) {
energyToRemove = powerProvider.getEnergyStored() / 10; energyToRemove = powerHandler.getEnergyStored() / 10;
} else { } else {
energyToRemove = 1; energyToRemove = 1;
} }
@ -122,42 +107,43 @@ public class PipePowerWood extends Pipe implements IPowerReceptor {
if (!powerSources[o.ordinal()]) if (!powerSources[o.ordinal()])
continue; continue;
float energyUsable = powerProvider.useEnergy(1, energyToRemove, false); float energyUsable = powerHandler.useEnergy(0, energyToRemove, false);
float energySend = (float) trans.receiveEnergy(o, energyUsable); float energySend = trans.receiveEnergy(o, energyUsable);
if (energySend > 0) { if (energySend > 0) {
powerProvider.useEnergy(1, energySend, true); powerHandler.useEnergy(0, energySend, true);
} }
} }
} }
public boolean requestsPower() { public boolean requestsPower() {
if (full) { if (full) {
boolean request = powerProvider.getEnergyStored() < powerProvider.getMaxEnergyStored() / 2; boolean request = powerHandler.getEnergyStored() < powerHandler.getMaxEnergyStored() / 2;
if (request) { if (request) {
full = false; full = false;
} }
return request; return request;
} }
full = powerProvider.getEnergyStored() >= powerProvider.getMaxEnergyStored() - 10; full = powerHandler.getEnergyStored() >= powerHandler.getMaxEnergyStored() - 10;
return !full; return !full;
} }
@Override
public int powerRequest(ForgeDirection from) {
return getPowerProvider().getMaxEnergyReceived();
}
@Override @Override
public void writeToNBT(NBTTagCompound data) { public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data); super.writeToNBT(data);
powerProvider.writeToNBT(data); powerHandler.writeToNBT(data);
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
data.setBoolean("powerSources[" + i + "]", powerSources[i]);
}
} }
@Override @Override
public void readFromNBT(NBTTagCompound data) { public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data); super.readFromNBT(data);
PowerFramework.currentFramework.loadPowerProvider(this, data); powerHandler.readFromNBT(data);
initPowerProvider(); initPowerProvider();
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
powerSources[i] = data.getBoolean("powerSources[" + i + "]");
}
} }
} }

View file

@ -23,6 +23,6 @@ public class PipeStructureCobblestone extends Pipe {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
return PipeIconProvider.PipeStructureCobblestone; return PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal();
} }
} }

View file

@ -72,7 +72,7 @@ public class FacadeItemRenderer implements IItemRenderer {
// Render StructurePipe // Render StructurePipe
block = BuildCraftTransport.genericPipeBlock; block = BuildCraftTransport.genericPipeBlock;
Icon textureID = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.PipeStructureCobblestone); // Structure pipe Icon textureID = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure pipe
block.setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos - 1F / 16F); block.setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos - 1F / 16F);
block.setBlockBoundsForItemRender(); block.setBlockBoundsForItemRender();

View file

@ -274,7 +274,7 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
zeroState[2][0] = Utils.pipeMinPos; zeroState[2][0] = Utils.pipeMinPos;
zeroState[2][1] = Utils.pipeMaxPos; zeroState[2][1] = Utils.pipeMaxPos;
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.PipeStructureCobblestone); // Structure Pipe state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure Pipe
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (state.facadeMatrix.getFacadeBlockId(direction) != 0 && !state.pipeConnectionMatrix.isConnected(direction)) { if (state.facadeMatrix.getFacadeBlockId(direction) != 0 && !state.pipeConnectionMatrix.isConnected(direction)) {
@ -303,7 +303,7 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
zeroState[2][0] = 0.25F + zFightOffset; zeroState[2][0] = 0.25F + zFightOffset;
zeroState[2][1] = 0.75F - zFightOffset; zeroState[2][1] = 0.75F - zFightOffset;
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.PipeStructureCobblestone); // Structure Pipe state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure Pipe
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (state.plugMatrix.isConnected(direction)) { if (state.plugMatrix.isConnected(direction)) {
@ -326,7 +326,7 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
zeroState[2][0] = 0.25F + 0.125F / 2; zeroState[2][0] = 0.25F + 0.125F / 2;
zeroState[2][1] = 0.75F - 0.125F / 2; zeroState[2][1] = 0.75F - 0.125F / 2;
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.PipeStructureCobblestone); // Structure Pipe state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure Pipe
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (state.plugMatrix.isConnected(direction)) { if (state.plugMatrix.isConnected(direction)) {

View file

@ -20,7 +20,7 @@ public class PlugItemRenderer implements IItemRenderer{
Tessellator tessellator = Tessellator.instance; Tessellator tessellator = Tessellator.instance;
block = BuildCraftTransport.genericPipeBlock; block = BuildCraftTransport.genericPipeBlock;
Icon textureID = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.PipeStructureCobblestone); // Structure pipe Icon textureID = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure pipe
block.setBlockBounds(0.25F, 0.25F, 0.25F, 0.75F, 0.375F, 0.75F); block.setBlockBounds(0.25F, 0.25F, 0.25F, 0.75F, 0.375F, 0.75F);
block.setBlockBoundsForItemRender(); block.setBlockBoundsForItemRender();

View file

@ -196,7 +196,7 @@ public class RenderPipe extends TileEntitySpecialRenderer {
initialized = true; initialized = true;
BlockInterface block = new BlockInterface(); BlockInterface block = new BlockInterface();
block.texture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.Power_Normal); block.texture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.Power_Normal.ordinal());
float size = Utils.pipeMaxPos - Utils.pipeMinPos; float size = Utils.pipeMaxPos - Utils.pipeMinPos;
@ -222,7 +222,7 @@ public class RenderPipe extends TileEntitySpecialRenderer {
GL11.glEndList(); GL11.glEndList();
} }
block.texture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.Power_Overload); block.texture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.Power_Overload.ordinal());
size = Utils.pipeMaxPos - Utils.pipeMinPos; size = Utils.pipeMaxPos - Utils.pipeMinPos;