Engine rewrite

Killed Engine class, merged into TileEngine and subclasses.
Converted to Forge rotation API.
Split heat from stored energy and set proper temp bounds.
Rewrote IronEngineCoolant API, changed to degree based temp reductions
(its 0.0025 times the previous values). Added support for solid coolants
(they have to melt into a liquid coolant, like Ice to Water).
There is a commented out alternative implementation for constant power
output instead of pulsed.
This commit is contained in:
CovertJaguar 2013-06-29 01:33:21 -07:00
parent f9374eb0e5
commit b25b08c827
28 changed files with 1337 additions and 1515 deletions

View file

@ -6,6 +6,10 @@ gate.pipe.containsLiquids=Liquid Traversing
gate.pipe.containsEnergy=Power Traversing
gate.pipe.requestsEnergy=Power Requested
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.del=Del
gui.filling.resources=Filling Resources

View file

@ -42,11 +42,11 @@ import buildcraft.energy.BlockOilFlowing;
import buildcraft.energy.BlockOilStill;
import buildcraft.energy.BptBlockEngine;
import buildcraft.energy.EnergyProxy;
import buildcraft.energy.Engine.EnergyStage;
import buildcraft.energy.GuiHandler;
import buildcraft.energy.ItemBucketOil;
import buildcraft.energy.ItemEngine;
import buildcraft.energy.OilBucketHandler;
import buildcraft.energy.TileEngine.EnergyStage;
import buildcraft.energy.worldgen.BiomeGenOilDesert;
import buildcraft.energy.worldgen.OilPopulate;
import buildcraft.energy.TriggerEngineHeat;
@ -86,10 +86,10 @@ public class BuildCraftEnergy {
public static LiquidStack fuelLiquid;
public static boolean canOilBurn;
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 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 triggerRedEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_RED_ENGINE_HEAT, EnergyStage.Red);
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 triggerYellowEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_YELLOW_ENGINE_HEAT, EnergyStage.YELLOW);
public static BCTrigger triggerRedEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_RED_ENGINE_HEAT, EnergyStage.RED);
@Instance("BuildCraft|Energy")
public static BuildCraftEnergy instance;
@ -177,7 +177,8 @@ public class BuildCraftEnergy {
IronEngineFuel.fuels.add(new IronEngineFuel(LiquidDictionary.getLiquid("Fuel", LiquidContainerRegistry.BUCKET_VOLUME), 6, 100000));
// 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.0025F);
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(
bucketOil), new ItemStack(Item.bucketEmpty)));

View file

@ -1,32 +1,95 @@
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;
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)
return null;
if (liquid.itemID <= 0)
return null;
for (IronEngineCoolant coolant : coolants)
if (coolant.liquid.isLiquidEqual(liquid))
return coolant;
String fluidId = LiquidDictionary.findLiquidName(liquid);
if (fluidId != null) {
return liquidCoolants.get(fluidId);
}
return null;
}
public final LiquidStack liquid;
public final float coolingPerUnit;
public IronEngineCoolant(LiquidStack liquid, float coolingPerUnit) {
this.liquid = liquid;
this.coolingPerUnit = coolingPerUnit;
private IronEngineCoolant() {
}
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

@ -15,9 +15,8 @@ public final class PowerProvider {
public static class PerditionCalculator {
public static final float DEFAULT_POWERLOSS = 10F;
public static final float DEFAULT_POWERLOSS = 1F;
public static final float MIN_POWERLOSS = 0.01F;
protected final SafeTimeTracker energyLossTracker = new SafeTimeTracker();
private final float powerLoss;
public PerditionCalculator() {
@ -40,14 +39,13 @@ public final class PowerProvider {
}
}
public static final PerditionCalculator DEFUALT_PERDITION = new PerditionCalculator();
private int minEnergyReceived;
private int maxEnergyReceived;
private int maxEnergyStored;
private int activationEnergy;
private float minEnergyReceived;
private float maxEnergyReceived;
private float maxEnergyStored;
private float activationEnergy;
private float energyStored = 0;
public final boolean canAcceptPowerFromPipes;
private final SafeTimeTracker doWorkTracker = new SafeTimeTracker();
private final SafeTimeTracker energyLossTracker = new SafeTimeTracker();
public final int[] powerSources = {0, 0, 0, 0, 0, 0};
public final IPowerReceptor receptor;
private PerditionCalculator perdition;
@ -61,19 +59,19 @@ public final class PowerProvider {
this.receptor = receptor;
}
public int getMinEnergyReceived() {
public float getMinEnergyReceived() {
return this.minEnergyReceived;
}
public int getMaxEnergyReceived() {
public float getMaxEnergyReceived() {
return this.maxEnergyReceived;
}
public int getMaxEnergyStored() {
public float getMaxEnergyStored() {
return this.maxEnergyStored;
}
public int getActivationEnergy() {
public float getActivationEnergy() {
return this.activationEnergy;
}
@ -99,7 +97,7 @@ public final class PowerProvider {
* store. Values tend to range between 100 and 5000. With 1000 and 1500
* being common.
*/
public void configure(int minEnergyReceived, int maxEnergyReceived, int activationEnergy, int maxStoredEnergy) {
public void configure(float minEnergyReceived, float maxEnergyReceived, float activationEnergy, float maxStoredEnergy) {
if (minEnergyReceived > maxEnergyReceived) {
maxEnergyReceived = minEnergyReceived;
}
@ -140,7 +138,6 @@ public final class PowerProvider {
private void applyPerdition() {
if (energyStored > 0) {
if (energyLossTracker.markTimeIfDelay(receptor.getWorldObj(), 10)) {
float newEnergy = getPerdition().applyPerdition(this, energyStored);
if (newEnergy == 0 || newEnergy < energyStored) {
energyStored = newEnergy;
@ -149,7 +146,6 @@ public final class PowerProvider {
}
}
}
}
private void applyWork() {
if (energyStored >= activationEnergy) {
@ -216,6 +212,10 @@ public final class PowerProvider {
return Math.min(maxEnergyReceived, maxEnergyStored - energyStored);
}
public float receiveEnergy(float quantity, ForgeDirection from) {
return receiveEnergy(quantity, from, false);
}
/**
* Add power to the Provider from an external source.
*
@ -223,9 +223,14 @@ public final class PowerProvider {
* @param from
* @return the amount of power used
*/
public float receiveEnergy(float quantity, ForgeDirection from) {
public float receiveEnergy(float quantity, ForgeDirection from, boolean boundsCheck) {
if (boundsCheck) {
if (quantity < minEnergyReceived) {
quantity = minEnergyReceived;
}
if (quantity > maxEnergyReceived) {
quantity -= quantity - maxEnergyReceived;
quantity = maxEnergyReceived;
}
}
if (from != null)
powerSources[from.ordinal()] = 2;

View file

@ -55,7 +55,7 @@ public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowe
}
private void initPowerProvider() {
powerProvider.configure(25, 50, 25, 100);
powerProvider.configure(30, 50, 25, 100);
powerProvider.configurePowerPerdition(1, 1);
}
@ -95,7 +95,7 @@ public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowe
}
if (powerProvider.getEnergyStored() >= 25) {
doWork(null);
doWork(powerProvider);
}
}
@ -137,7 +137,7 @@ public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowe
}
if (powerProvider.getEnergyStored() >= 25) {
doWork(null);
doWork(workProvider);
}
}

View file

@ -15,23 +15,16 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftEnergy;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.GuiIds;
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.SideOnly;
import net.minecraftforge.liquids.LiquidContainerRegistry;
public class BlockEngine extends BlockContainer {
@ -71,15 +64,20 @@ public class BlockEngine extends BlockContainer {
}
@Override
public TileEntity createNewTileEntity(World var1) {
return new TileEngine();
public TileEntity createTileEntity(World world, int metadata) {
if (metadata == 1)
return new TileEngineStone();
else if (metadata == 2)
return new TileEngineIron();
else
return new TileEngineWood();
}
@Override
public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side) {
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileEngine) {
return ForgeDirection.getOrientation(((TileEngine) tile).orientation).getOpposite() == side;
return ((TileEngine) tile).orientation.getOpposite() == side;
}
return false;
}
@ -94,6 +92,15 @@ public class BlockEngine extends BlockContainer {
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
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())
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
if (player.getCurrentEquippedItem() != null) {
if (player.getCurrentEquippedItem().getItem() instanceof IItemPipe) {
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;
@ -155,7 +127,7 @@ public class BlockEngine extends BlockContainer {
@Override
public void onPostBlockPlaced(World world, int x, int y, int z, int par5) {
TileEngine tile = (TileEngine) world.getBlockTileEntity(x, y, z);
tile.orientation = ForgeDirection.UP.ordinal();
tile.orientation = ForgeDirection.UP;
tile.switchOrientation();
}
@ -215,4 +187,9 @@ public class BlockEngine extends BlockContainer {
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) {
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
@ -46,7 +46,7 @@ public class BptBlockEngine extends BptBlock {
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

View file

@ -8,7 +8,10 @@ public class EnergyProxy {
public static EnergyProxy proxy;
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() {

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,12 +1,10 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
* 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
* 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 java.util.LinkedList;
@ -15,14 +13,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
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.api.core.Position;
import buildcraft.api.gates.IOverrideDefaultTriggers;
@ -30,49 +22,130 @@ import buildcraft.api.gates.ITrigger;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerProvider;
import buildcraft.api.transport.IPipeConnection;
import buildcraft.core.IBuilderInventory;
import buildcraft.core.TileBuffer;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.network.TileNetworkData;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.energy.gui.ContainerEngine;
import net.minecraft.inventory.ICrafting;
//TODO: All Engines need to take func_48081_b into account
public abstract class TileEngine extends TileBuildCraft implements IPowerReceptor, IInventory, IOverrideDefaultTriggers, IPipeConnection {
public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInventory, ITankContainer, IEngineProvider, IOverrideDefaultTriggers,
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;
PowerProvider provider;
public enum EnergyStage {
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 PowerProvider provider;
public float currentOutput = 0;
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 = new PowerProvider(this, false);
provider.configurePowerPerdition(1, 100);
inv = new SimpleInventory(invSize, "Engine", 64);
}
@Override
public void initialize() {
if (!CoreProxy.proxy.isRenderWorld(worldObj)) {
if (engine == null) {
createEngineIfNeeded();
tileCache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, true);
provider.configure(minEnergyReceived(), maxEnergyReceived(), 1, getMaxEnergy());
checkRedstonePower();
}
}
engine.orientation = ForgeDirection.VALID_DIRECTIONS[orientation];
provider.configure(engine.minEnergyReceived(), engine.maxEnergyReceived(), 1, engine.maxEnergy);
checkRedstonePower();
public abstract String getTextureFile();
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;
}
}
@ -80,222 +153,212 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
public void updateEntity() {
super.updateEntity();
if (engine == null)
return;
if (CoreProxy.proxy.isRenderWorld(worldObj)) {
if (progressPart != 0) {
engine.progress += serverPistonSpeed;
progress += getPistonSpeed();
if (engine.progress > 1) {
if (progress > 1) {
progressPart = 0;
engine.progress = 0;
progress = 0;
}
} else if (this.isActive) {
} else if (this.isPumping) {
progressPart = 1;
}
return;
}
engine.update();
updateHeatLevel();
engineUpdate();
float newPistonSpeed = engine.getPistonSpeed();
if (newPistonSpeed != serverPistonSpeed) {
serverPistonSpeed = newPistonSpeed;
sendNetworkUpdate();
}
TileEntity tile = tileCache[orientation.ordinal()].getTile();
if (progressPart != 0) {
engine.progress += engine.getPistonSpeed();
progress += getPistonSpeed();
if (engine.progress > 0.5 && progressPart == 1) {
if (progress > 0.5 && progressPart == 1) {
progressPart = 2;
Position pos = new Position(xCoord, yCoord, zCoord, engine.orientation);
pos.moveForwards(1.0);
TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
if (isPoweredTile(tile)) {
PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(engine.orientation.getOpposite());
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;
sendPower(); // Comment out for constant power
} else if (progress >= 1) {
progress = 0;
progressPart = 0;
}
} else if (isRedstonePowered && engine.isActive()) {
Position pos = new Position(xCoord, yCoord, zCoord, engine.orientation);
pos.moveForwards(1.0);
TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
if (isPoweredTile(tile)) {
PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(engine.orientation.getOpposite());
if (engine.extractEnergy(receptor.getMinEnergyReceived(), receptor.getMaxEnergyReceived(), false) > 0) {
} else if (isRedstonePowered && isActive()) {
if (isPoweredTile(tile, orientation)) {
if (getPowerToExtract() > 0) {
progressPart = 1;
setActive(true);
setPumping(true);
} else {
setActive(false);
setPumping(false);
}
} else {
setActive(false);
setPumping(false);
}
} else {
setActive(false);
setPumping(false);
}
engine.burn();
// Uncomment for constant power
// if (isRedstonePowered && isActive()) {
// sendPower();
// } else currentOutput = 0;
burn();
}
private void setActive(boolean isActive) {
if (this.isActive == isActive)
private float getPowerToExtract() {
TileEntity tile = tileCache[orientation.ordinal()].getTile();
PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(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)) {
PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(orientation.getOpposite());
float extracted = getPowerToExtract();
if (extracted > 0) {
float needed = receptor.receiveEnergy(extracted, orientation.getOpposite(), true);
extractEnergy(receptor.getMinEnergyReceived(), needed, true); // Comment out for constant power
// 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;
this.isActive = isActive;
this.isPumping = isActive;
sendNetworkUpdate();
}
private void createEngineIfNeeded() {
if (engine == null) {
int kind = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
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];
public boolean switchOrientation() {
for (int i = orientation.ordinal() + 1; i <= orientation.ordinal() + 6; ++i) {
ForgeDirection o = ForgeDirection.VALID_DIRECTIONS[i % 6];
Position pos = new Position(xCoord, yCoord, zCoord, o);
pos.moveForwards(1);
TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
if (isPoweredTile(tile)) {
if (engine != null) {
engine.orientation = o;
}
orientation = o.ordinal();
if (isPoweredTile(tile, o)) {
orientation = o;
worldObj.markBlockForUpdate(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");
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;
}
}
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 */
@Override
public int getSizeInventory() {
if (engine != null)
return engine.getSizeInventory();
else
return 0;
return inv.getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int i) {
if (engine != null)
return engine.getStackInSlot(i);
else
return null;
public ItemStack getStackInSlot(int slot) {
return inv.getStackInSlot(slot);
}
@Override
public ItemStack decrStackSize(int i, int j) {
if (engine != null)
return engine.decrStackSize(i, j);
else
return null;
public ItemStack decrStackSize(int slot, int amount) {
return inv.decrStackSize(slot, amount);
}
@Override
public ItemStack getStackInSlotOnClosing(int i) {
if (engine != null)
return engine.getStackInSlotOnClosing(i);
else
return null;
public ItemStack getStackInSlotOnClosing(int slot) {
return inv.getStackInSlotOnClosing(slot);
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
if (engine != null) {
engine.setInventorySlotContents(i, itemstack);
}
public void setInventorySlotContents(int slot, ItemStack itemstack) {
inv.setInventorySlotContents(slot, itemstack);
}
@Override
public boolean isStackValidForSlot(int i, ItemStack itemstack) {
if (engine != null){
return engine.isStackValidForSlot(i, itemstack);
return true;
}
return false;
public void delete() {
Utils.dropItems(worldObj, inv, xCoord, yCoord, zCoord);
}
@Override
@ -314,47 +377,9 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
}
/* STATE INFORMATION */
public boolean isBurning() {
return engine != null && engine.isBurning();
}
public abstract boolean isBurning();
public int getScaledBurnTime(int i) {
if (engine != null)
return engine.getScaledBurnTime(i);
else
return 0;
}
/* SMP UPDATING */
@Override
public Packet getDescriptionPacket() {
createEngineIfNeeded();
return super.getDescriptionPacket();
}
@Override
public Packet getUpdatePacket() {
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);
}
public abstract int getScaledBurnTime(int scale);
@Override
public PowerProvider getPowerProvider(ForgeDirection side) {
@ -366,12 +391,56 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
if (CoreProxy.proxy.isRenderWorld(worldObj))
return;
engine.addEnergy(provider.useEnergy(1, engine.maxEnergyReceived(), true) * 0.95F);
addEnergy(provider.useEnergy(1, maxEnergyReceived(), true) * 0.95F);
}
public boolean isPoweredTile(TileEntity tile) {
public void addEnergy(float addition) {
energy += addition;
if (getEnergyStage() == EnergyStage.OVERHEAT) {
worldObj.createExplosion(null, xCoord, yCoord, zCoord, explosionRange(), true);
}
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) {
PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(engine.orientation.getOpposite());
PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(side.getOpposite());
return receptor != null;
}
@ -381,19 +450,30 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
@Override
public void openChest() {
}
@Override
public void closeChest() {
}
@Override
public Engine getEngine() {
return engine;
public abstract float getMaxEnergy();
public float minEnergyReceived() {
return 2;
}
public abstract float maxEnergyReceived();
public abstract float maxEnergyExtracted();
public abstract float explosionRange();
public float getEnergyStored() {
return energy;
}
public abstract float getCurrentOutput();
@Override
public LinkedList<ITrigger> getTriggers() {
LinkedList<ITrigger> triggers = new LinkedList<ITrigger>();
@ -403,73 +483,15 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
triggers.add(BuildCraftEnergy.triggerYellowEngineHeat);
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;
}
@Override
public boolean isPipeConnected(ForgeDirection with) {
if (engine instanceof EngineWood)
return false;
return with.ordinal() != orientation;
}
@Override
public boolean isBuildingMaterial(int i) {
return false;
return with != orientation;
}
public void checkRedstonePower() {
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.01F;
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 > 0 && (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,77 @@
/**
* 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.BuildCraftEnergy;
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 {
public TileEngineLegacy() {
super(0);
}
@Override
public void updateEntity() {
int meta = getBlockMetadata();
NBTTagCompound nbt = new NBTTagCompound();
writeToNBT(nbt);
TileEntity newTile = BuildCraftEnergy.engineBlock.createTileEntity(worldObj, meta);
newTile.readFromNBT(nbt);
worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, newTile);
}
@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
* http://www.mod-buildcraft.com
* 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
* 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.tileentity.TileEntity;
@ -14,12 +12,14 @@ import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.triggers.ActionTriggerIconProvider;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
import buildcraft.energy.TileEngine.EnergyStage;
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);
this.stage = stage;
@ -28,23 +28,23 @@ public class TriggerEngineHeat extends BCTrigger {
@Override
public String getDescription() {
switch (stage) {
case Blue:
return "Engine Blue";
case Green:
return "Engine Green";
case Yellow:
return "Engine Yellow";
case BLUE:
return StringUtils.localize("gate.engine.blue");
case GREEN:
return StringUtils.localize("gate.engine.green");
case YELLOW:
return StringUtils.localize("gate.engine.yellow");
default:
return "Engine Red";
return StringUtils.localize("gate.engine.red");
}
}
@Override
public boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter) {
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;
@ -53,11 +53,11 @@ public class TriggerEngineHeat extends BCTrigger {
@Override
public int getIconIndex() {
switch (stage) {
case Blue:
case BLUE:
return ActionTriggerIconProvider.Trigger_EngineHeat_Blue;
case Green:
case GREEN:
return ActionTriggerIconProvider.Trigger_EngineHeat_Green;
case Yellow:
case YELLOW:
return ActionTriggerIconProvider.Trigger_EngineHeat_Yellow;
default:
return ActionTriggerIconProvider.Trigger_EngineHeat_Red;

View file

@ -1,12 +1,10 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
* 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
* 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.gui;
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.Slot;
import buildcraft.core.gui.BuildCraftContainer;
import buildcraft.energy.EngineStone;
import buildcraft.energy.TileEngineStone;
import buildcraft.energy.TileEngine;
public class ContainerEngine extends BuildCraftContainer {
@ -26,7 +24,7 @@ public class ContainerEngine extends BuildCraftContainer {
engine = tileEngine;
if (tileEngine.engine instanceof EngineStone) {
if (tileEngine instanceof TileEngineStone) {
addSlotToContainer(new Slot(tileEngine, 0, 80, 41));
} else {
addSlotToContainer(new Slot(tileEngine, 0, 52, 41));
@ -49,15 +47,13 @@ public class ContainerEngine extends BuildCraftContainer {
super.detectAndSendChanges();
for (int i = 0; i < crafters.size(); i++) {
engine.engine.sendGUINetworkData(this, (ICrafting) crafters.get(i));
engine.sendGUINetworkData(this, (ICrafting) crafters.get(i));
}
}
@Override
public void updateProgressBar(int i, int j) {
if (engine.engine != null) {
engine.engine.getGUINetworkData(i, j);
}
engine.getGUINetworkData(i, j);
}
public boolean isUsableByPlayer(EntityPlayer entityplayer) {

View file

@ -19,7 +19,7 @@ import org.lwjgl.opengl.GL11;
import buildcraft.core.DefaultProps;
import buildcraft.core.utils.StringUtils;
import buildcraft.energy.EngineIron;
import buildcraft.energy.TileEngineIron;
import buildcraft.energy.TileEngine;
public class GuiCombustionEngine extends GuiEngine {
@ -44,15 +44,14 @@ public class GuiCombustionEngine extends GuiEngine {
int k = (height - ySize) / 2;
drawTexturedModalRect(j, k, 0, 0, xSize, ySize);
TileEngine engine = (TileEngine) tile;
EngineIron engineIron = ((EngineIron) engine.engine);
TileEngineIron engine = (TileEngineIron) tile;
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) {
displayGauge(j, k, 19, 122, engineIron.getScaledCoolant(58), engineIron.getCoolant());
if (engine.getScaledCoolant(58) > 0) {
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.GuiBuildCraft;
import buildcraft.core.utils.StringUtils;
import buildcraft.energy.Engine;
import buildcraft.energy.TileEngine;
public abstract class GuiEngine extends GuiBuildCraft {
protected class EngineLedger extends Ledger {
Engine engine;
TileEngine engine;
int headerColour = 0xe1c92f;
int subheaderColour = 0xaaafb8;
int textColour = 0x000000;
public EngineLedger(Engine engine) {
public EngineLedger(TileEngine engine) {
this.engine = engine;
maxHeight = 94;
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.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.drawString(String.format("%.1f MJ", engine.getEnergyStored()), x + 22, y + 56, textColour);
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
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
protected void initLedgers(IInventory 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.core.DefaultProps;
import buildcraft.core.IInventoryRenderer;
import buildcraft.energy.Engine;
import buildcraft.energy.Engine.EnergyStage;
import buildcraft.energy.IEngineProvider;
import buildcraft.energy.TileEngine;
import buildcraft.energy.TileEngine.EnergyStage;
public class RenderEngine extends TileEntitySpecialRenderer implements IInventoryRenderer {
@ -86,13 +85,13 @@ public class RenderEngine extends TileEntitySpecialRenderer implements IInventor
@Override
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
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) {
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 = "";
switch (energy) {
case Blue:
case BLUE:
texture = DefaultProps.TEXTURE_PATH_BLOCKS + "/trunk_blue.png";
break;
case Green:
case GREEN:
texture = DefaultProps.TEXTURE_PATH_BLOCKS + "/trunk_green.png";
break;
case Yellow:
case YELLOW:
texture = DefaultProps.TEXTURE_PATH_BLOCKS + "/trunk_yellow.png";
break;
default:

View file

@ -45,7 +45,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction
}
private void initPowerProvider() {
powerProvider.configure(25, 25, 25, 1000);
powerProvider.configure(25, 150, 25, 1000);
powerProvider.configurePowerPerdition(1, 1);
}

View file

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

View file

@ -16,7 +16,6 @@ import buildcraft.api.gates.ITrigger;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerProvider;
import buildcraft.core.DefaultProps;
import buildcraft.core.IMachine;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.transport.network.PacketPowerUpdate;
@ -42,15 +41,15 @@ public class PipeTransportPower extends PipeTransport {
}
private boolean needsInit = true;
private TileEntity[] tiles = new TileEntity[6];
public double[] displayPower = new double[6];
public double[] prevDisplayPower = new double[6];
public float[] displayPower = new float[6];
public float[] prevDisplayPower = new float[6];
public short[] clientDisplayPower = new short[6];
public int overload;
public int[] powerQuery = new int[6];
public int[] nextPowerQuery = new int[6];
public long currentDate;
public double[] internalPower = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
public double[] internalNextPower = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
public float[] internalPower = new float[6];
public float[] internalNextPower = new float[6];
public int maxPower = 8;
public PipeTransportPower() {
@ -124,11 +123,11 @@ public class PipeTransportPower extends PipeTransport {
// Send the power to nearby pipes who requested it
System.arraycopy(displayPower, 0, prevDisplayPower, 0, 6);
Arrays.fill(displayPower, 0.0);
Arrays.fill(displayPower, 0.0F);
for (int i = 0; i < 6; ++i) {
if (internalPower[i] > 0) {
double totalPowerQuery = 0;
float totalPowerQuery = 0;
for (int j = 0; j < 6; ++j) {
if (j != i && powerQuery[j] > 0)
@ -139,10 +138,10 @@ public class PipeTransportPower extends PipeTransport {
for (int j = 0; j < 6; ++j) {
if (j != i && powerQuery[j] > 0) {
double watts = 0.0;
float watts = 0.0F;
if (tiles[j] instanceof TileGenericPipe) {
watts = (internalPower[i] / totalPowerQuery * powerQuery[j]);
watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
TileGenericPipe nearbyTile = (TileGenericPipe) tiles[j];
PipeTransportPower nearbyTransport = (PipeTransportPower) nearbyTile.pipe.transport;
@ -154,8 +153,8 @@ public class PipeTransportPower extends PipeTransport {
PowerProvider prov = pow.getPowerProvider(ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
if (prov != null && prov.canAcceptPowerFromPipes && prov.powerRequest() > 0) {
watts = (internalPower[i] / totalPowerQuery * powerQuery[j]);
prov.receiveEnergy((float) watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
watts = prov.receiveEnergy(watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
internalPower[i] -= watts;
}
}
@ -169,7 +168,7 @@ public class PipeTransportPower extends PipeTransport {
double highestPower = 0;
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) {
highestPower = displayPower[i];
}
@ -262,7 +261,7 @@ public class PipeTransportPower extends PipeTransport {
powerQuery = nextPowerQuery;
nextPowerQuery = new int[6];
double[] next = internalPower;
float[] next = internalPower;
internalPower = internalNextPower;
internalNextPower = next;
// for (int i = 0; i < powerQuery.length; i++) {
@ -279,7 +278,7 @@ public class PipeTransportPower extends PipeTransport {
}
}
public double receiveEnergy(ForgeDirection from, double val) {
public float receiveEnergy(ForgeDirection from, float val) {
step();
if (this.container.pipe instanceof IPipeTransportPowerHook) {
return ((IPipeTransportPowerHook) this.container.pipe).receiveEnergy(from, val);
@ -315,8 +314,8 @@ public class PipeTransportPower extends PipeTransport {
for (int i = 0; i < 6; ++i) {
powerQuery[i] = nbttagcompound.getInteger("powerQuery[" + i + "]");
nextPowerQuery[i] = nbttagcompound.getInteger("nextPowerQuery[" + i + "]");
internalPower[i] = nbttagcompound.getDouble("internalPower[" + i + "]");
internalNextPower[i] = nbttagcompound.getDouble("internalNextPower[" + i + "]");
internalPower[i] = (float) nbttagcompound.getDouble("internalPower[" + i + "]");
internalNextPower[i] = (float) nbttagcompound.getDouble("internalNextPower[" + i + "]");
}
}

View file

@ -82,19 +82,22 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
if (powerProvider.getEnergyStored() <= 0)
return;
World w = worldObj;
extractItems();
powerProvider.setEnergy(0);
}
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
private void extractItems() {
int meta = container.getBlockMetadata();
if (meta > 5)
return;
Position pos = new Position(xCoord, yCoord, zCoord, ForgeDirection.getOrientation(meta));
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 (!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;
IInventory inventory = (IInventory) tile;
@ -113,12 +116,11 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
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);
}
}
powerProvider.setEnergy(0);
}
/**

View file

@ -113,11 +113,11 @@ public class PipePowerWood extends Pipe implements IPowerReceptor {
if (!powerSources[o.ordinal()])
continue;
float energyUsable = powerProvider.useEnergy(1, energyToRemove, false);
float energyUsable = powerProvider.useEnergy(0, energyToRemove, false);
float energySend = (float) trans.receiveEnergy(o, energyUsable);
float energySend = trans.receiveEnergy(o, energyUsable);
if (energySend > 0) {
powerProvider.useEnergy(1, energySend, true);
powerProvider.useEnergy(0, energySend, true);
}
}
}