Refactored API for combustion engine fuels and refinery.

This commit is contained in:
SirSengir 2012-07-12 14:33:22 +02:00
parent c632f79150
commit 7f3163636f
13 changed files with 210 additions and 81 deletions

View file

@ -28,6 +28,7 @@ import net.minecraft.src.buildcraft.core.network.BuildCraftPacket;
import net.minecraft.src.forge.MinecraftForgeClient;
import net.minecraft.src.forge.NetworkMod;
import cpw.mods.fml.client.SpriteHelper;
import cpw.mods.fml.common.FMLCommonHandler;
public class CoreProxy {
@ -85,10 +86,6 @@ public class CoreProxy {
}
public static int addFuel(int id, int dmg) {
return ModLoader.addAllFuel(id, dmg);
}
/**
* Adds an override to the buildcraft texture file, mainly to provide pipes
* with icons.
@ -104,11 +101,6 @@ public class CoreProxy {
return ModLoader.addOverride(DefaultProps.TEXTURE_EXTERNAL, pathToTexture) + 256;
}
public static long getHash(IBlockAccess iBlockAccess) {
// return iBlockAccess.func_48454_a(x, z).hashCode();
return 0;
}
public static void TakenFromCrafting(EntityPlayer entityplayer, ItemStack itemstack, IInventory iinventory) {
ModLoader.takenFromCrafting(entityplayer, itemstack, iinventory);
}

View file

@ -12,8 +12,9 @@ package net.minecraft.src.buildcraft.factory;
import net.minecraft.src.InventoryPlayer;
import net.minecraft.src.ItemStack;
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
import net.minecraft.src.buildcraft.api.RefineryRecipe;
import net.minecraft.src.buildcraft.api.liquids.LiquidManager;
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
import net.minecraft.src.buildcraft.api.recipes.RefineryRecipe;
import net.minecraft.src.buildcraft.core.DefaultProps;
import net.minecraft.src.buildcraft.core.GuiAdvancedInterface;
import net.minecraft.src.buildcraft.core.utils.StringUtil;
@ -100,11 +101,11 @@ public class GuiRefinery extends GuiAdvancedInterface {
if (filter1 != null)
liquid1Id = filter1.itemID;
RefineryRecipe recipe = BuildCraftAPI.findRefineryRecipe(liquid0Id, BuildCraftAPI.BUCKET_VOLUME, liquid1Id,
BuildCraftAPI.BUCKET_VOLUME);
RefineryRecipe recipe = RefineryRecipe.findRefineryRecipe(new LiquidStack(liquid0Id, BuildCraftAPI.BUCKET_VOLUME, 0),
new LiquidStack(liquid1Id, BuildCraftAPI.BUCKET_VOLUME, 0));
if (recipe != null)
((ItemSlot) slots[2]).stack = new ItemStack(recipe.resultId, 1, 0);
((ItemSlot) slots[2]).stack = recipe.result.asItemStack();
else
((ItemSlot) slots[2]).stack = null;
}

View file

@ -81,24 +81,12 @@ public class CoreProxy {
return new File("buildcraft/");
}
public static void addLocalization(String s1, String string) {
// TODO Auto-generated method stub
}
public static int addFuel(int id, int dmg) {
return ModLoader.addAllFuel(id, dmg);
}
public static void addLocalization(String s1, String string) {}
public static int addCustomTexture(String pathToTexture) {
return 0;
}
public static long getHash(IBlockAccess iBlockAccess) {
// return iBlockAccess.hashCode();
return 0;
}
public static void TakenFromCrafting(EntityPlayer thePlayer, ItemStack itemstack, IInventory craftMatrix) {
ModLoader.takenFromCrafting(thePlayer, itemstack, craftMatrix);

View file

@ -12,10 +12,12 @@ import java.util.Random;
import java.util.TreeMap;
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
import net.minecraft.src.buildcraft.api.IronEngineFuel;
import net.minecraft.src.buildcraft.api.LiquidData;
import net.minecraft.src.buildcraft.api.RefineryRecipe;
import net.minecraft.src.buildcraft.api.Trigger;
import net.minecraft.src.buildcraft.api.fuels.IronEngineFuel;
import net.minecraft.src.buildcraft.api.liquids.LiquidData;
import net.minecraft.src.buildcraft.api.liquids.LiquidManager;
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
import net.minecraft.src.buildcraft.api.recipes.RefineryRecipe;
import net.minecraft.src.buildcraft.core.BlockIndex;
import net.minecraft.src.buildcraft.core.CoreProxy;
import net.minecraft.src.buildcraft.core.DefaultProps;
@ -126,14 +128,14 @@ public class BuildCraftEnergy {
.setMaxStackSize(1).setContainerItem(Item.bucketEmpty);
CoreProxy.addName(bucketFuel, "Fuel Bucket");
BuildCraftAPI.registerRefineryRecipe(new RefineryRecipe(oilStill.blockID, 1, 0, 0, 10, fuel.shiftedIndex, 1, 1));
RefineryRecipe.registerRefineryRecipe(new RefineryRecipe(new LiquidStack(oilStill.blockID, 1, 0), null, new LiquidStack(fuel.shiftedIndex, 1, 0), 10, 1));
BuildCraftAPI.ironEngineFuel.put(Block.lavaStill.blockID, new IronEngineFuel(oilStill.blockID, 1, 20000));
BuildCraftAPI.ironEngineFuel.put(oilStill.blockID, new IronEngineFuel(oilStill.blockID, 2, 10000));
BuildCraftAPI.ironEngineFuel.put(fuel.shiftedIndex, new IronEngineFuel(fuel.shiftedIndex, 5, 50000));
IronEngineFuel.fuels.add(new IronEngineFuel(oilStill.blockID, 1, 20000));
IronEngineFuel.fuels.add(new IronEngineFuel(oilStill.blockID, 2, 10000));
IronEngineFuel.fuels.add(new IronEngineFuel(fuel.shiftedIndex, 5, 50000));
BuildCraftAPI.liquids.add(new LiquidData(oilStill.blockID, oilMoving.blockID, bucketOil));
BuildCraftAPI.liquids.add(new LiquidData(fuel.shiftedIndex, 0, bucketFuel));
LiquidManager.liquids.add(new LiquidData(oilStill.blockID, oilMoving.blockID, bucketOil));
LiquidManager.liquids.add(new LiquidData(fuel.shiftedIndex, 0, bucketFuel));
BuildCraftAPI.softBlocks[oilMoving.blockID] = true;
BuildCraftAPI.softBlocks[oilStill.blockID] = true;

View file

@ -32,17 +32,28 @@ public class BuildCraftAPI {
// Other BuildCraft global data
@Deprecated
public static LinkedList<LiquidData> liquids = new LinkedList<LiquidData>();
public static HashMap<Integer, IronEngineFuel> ironEngineFuel = new HashMap<Integer, IronEngineFuel>();
/**
* This does not do anything anymore. Use buildcraft.api.liquids.LiquidManager!
*/
@Deprecated public static LinkedList<LiquidData> liquids = new LinkedList<LiquidData>();
/**
* This does not do anything anymore. Use buildcraft.api.fuels.IronEngineFuel!
*/
@Deprecated public static HashMap<Integer, IronEngineFuel> ironEngineFuel = new HashMap<Integer, IronEngineFuel>();
public static Trigger[] triggers = new Trigger[1024];
public static Action[] actions = new Action[1024];
private static EntityPlayer buildCraftPlayer;
private static LinkedList<RefineryRecipe> refineryRecipe = new LinkedList<RefineryRecipe>();
/**
* This does not do anything anymore. Use buildcraft.api.recipes.RefineryRecipe!
*/
@Deprecated private static LinkedList<RefineryRecipe> refineryRecipe = new LinkedList<RefineryRecipe>();
private static LinkedList<ITriggerProvider> triggerProviders = new LinkedList<ITriggerProvider>();
private static LinkedList<IActionProvider> actionProviders = new LinkedList<IActionProvider>();
/**
* This does not do anything anymore. Use buildcraft.api.liquids.LiquidManager!
*/
@Deprecated
public static int getLiquidForFilledItem(ItemStack filledItem) {
if (filledItem == null) {
@ -58,6 +69,9 @@ public class BuildCraftAPI {
return 0;
}
/**
* This does not do anything anymore. Use buildcraft.api.liquids.LiquidManager!
*/
@Deprecated
public static ItemStack getFilledItemForLiquid(int liquidId) {
for (LiquidData d : liquids) {
@ -69,6 +83,9 @@ public class BuildCraftAPI {
return null;
}
/**
* This does not do anything anymore. Use buildcraft.api.liquids.LiquidManager!
*/
@Deprecated
public static boolean isLiquid(int blockId) {
if (blockId == 0) {
@ -119,12 +136,20 @@ public class BuildCraftAPI {
return buildCraftPlayer;
}
/**
* This does not do anything anymore. Use buildcraft.api.recipes.RefineryRecipe!
*/
@Deprecated
public static void registerRefineryRecipe(RefineryRecipe recipe) {
if (!refineryRecipe.contains(recipe)) {
refineryRecipe.add(recipe);
}
}
/**
* This does not do anything anymore. Use buildcraft.api.recipes.RefineryRecipe!
*/
@Deprecated
public static RefineryRecipe findRefineryRecipe(int liquid1, int qty1, int liquid2, int qty2) {
int l1 = qty1 > 0 ? liquid1 : 0;
int l2 = qty2 > 0 ? liquid2 : 0;

View file

@ -9,6 +9,10 @@
package net.minecraft.src.buildcraft.api;
/**
* This does not do anything anymore. Use buildcraft.api.fuels.IronEngineFuel!
*/
@Deprecated
public class IronEngineFuel {
public final int fuelId;

View file

@ -9,6 +9,7 @@
package net.minecraft.src.buildcraft.api;
@Deprecated
public class RefineryRecipe {
public final int sourceId1;

View file

@ -0,0 +1,45 @@
/**
* 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 net.minecraft.src.buildcraft.api.fuels;
import java.util.HashMap;
import java.util.LinkedList;
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
public class IronEngineFuel {
public static LinkedList<IronEngineFuel> fuels = new LinkedList<IronEngineFuel>();
public static IronEngineFuel getFuelForLiquid(LiquidStack liquid) {
if(liquid == null)
return null;
for(IronEngineFuel fuel : fuels)
if(fuel.liquid.isLiquidEqual(liquid))
return fuel;
return null;
}
public final LiquidStack liquid;
public final int powerPerCycle;
public final int totalBurningTime;
public IronEngineFuel(int liquidId, int powerPerCycle, int totalBurningTime) {
this(new LiquidStack(liquidId, BuildCraftAPI.BUCKET_VOLUME, 0), powerPerCycle, totalBurningTime);
}
public IronEngineFuel(LiquidStack liquid, int powerPerCycle, int totalBurningTime) {
this.liquid = liquid;
this.powerPerCycle = powerPerCycle;
this.totalBurningTime = totalBurningTime;
}
}

View file

@ -86,6 +86,9 @@ public class LiquidStack {
* @return true if this LiquidStack contains the same liquid as the one passed in.
*/
public boolean isLiquidEqual(LiquidStack other) {
if(other == null)
return false;
return itemID == other.itemID && itemMeta == other.itemMeta;
}
@ -94,6 +97,9 @@ public class LiquidStack {
* @return true if this LiquidStack contains the same liquid as the one passed in.
*/
public boolean isLiquidEqual(ItemStack other) {
if(other == null)
return false;
return itemID == other.itemID && itemMeta == other.getItemDamage();
}

View file

@ -0,0 +1,73 @@
/**
* 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 net.minecraft.src.buildcraft.api.recipes;
import java.util.LinkedList;
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
public class RefineryRecipe {
private static LinkedList<RefineryRecipe> recipes = new LinkedList<RefineryRecipe>();
public static void registerRefineryRecipe(RefineryRecipe recipe) {
if (!recipes.contains(recipe)) {
recipes.add(recipe);
}
}
public static RefineryRecipe findRefineryRecipe(LiquidStack liquid1, LiquidStack liquid2) {
for(RefineryRecipe recipe : recipes)
if(recipe.matches(liquid1, liquid2))
return recipe;
return null;
}
public final LiquidStack ingredient1;
public final LiquidStack ingredient2;
public final LiquidStack result;
public final int energy;
public final int delay;
public RefineryRecipe(int ingredientId1, int ingredientQty1, int ingredientId2, int ingredientQty2, int resultId, int resultQty,
int energy, int delay) {
this(new LiquidStack(ingredientId1, ingredientQty1, 0), new LiquidStack(ingredientId2, ingredientQty2, 0), new LiquidStack(resultId, resultQty, 0), energy, delay);
}
public RefineryRecipe(LiquidStack ingredient1, LiquidStack ingredient2, LiquidStack result, int energy, int delay) {
this.ingredient1 = ingredient1;
this.ingredient2 = ingredient2;
this.result = result;
this.energy = energy;
this.delay = delay;
}
public boolean matches(LiquidStack liquid1, LiquidStack liquid2) {
if(liquid1 == null && liquid2 == null)
return false;
if((ingredient1 != null && ingredient2 != null)
&& (liquid1 == null || liquid2 == null))
return false;
if(liquid1 != null) {
if(liquid2 == null)
return liquid1.isLiquidEqual(ingredient1) || liquid1.isLiquidEqual(ingredient2);
else
return (liquid1.isLiquidEqual(ingredient1) && liquid2.isLiquidEqual(ingredient2))
|| (liquid2.isLiquidEqual(ingredient1) && liquid1.isLiquidEqual(ingredient2));
} else
return liquid2.isLiquidEqual(ingredient1) || liquid2.isLiquidEqual(ingredient2);
}
}

View file

@ -14,10 +14,11 @@ import net.minecraft.src.ICrafting;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
import net.minecraft.src.buildcraft.api.IronEngineFuel;
import net.minecraft.src.buildcraft.api.LiquidSlot;
import net.minecraft.src.buildcraft.api.Orientations;
import net.minecraft.src.buildcraft.api.fuels.IronEngineFuel;
import net.minecraft.src.buildcraft.api.liquids.LiquidManager;
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
import net.minecraft.src.buildcraft.core.DefaultProps;
import net.minecraft.src.buildcraft.core.Utils;
@ -75,9 +76,9 @@ public class EngineIron extends Engine {
return 0.06F;
case Red:
return 0.07F;
default:
return 0.0f;
}
return 0;
}
@Override
@ -88,7 +89,7 @@ public class EngineIron extends Engine {
@Override
public void burn() {
currentOutput = 0;
IronEngineFuel currentFuel = BuildCraftAPI.ironEngineFuel.get(liquidId);
IronEngineFuel currentFuel = IronEngineFuel.getFuelForLiquid(new LiquidStack(liquidId, liquidQty, 0));
if (currentFuel == null) {
return;
@ -188,9 +189,8 @@ public class EngineIron extends Engine {
return 0;
}
if (!BuildCraftAPI.ironEngineFuel.containsKey(id)) {
if (IronEngineFuel.getFuelForLiquid(new LiquidStack(id, quantity, 0)) == null)
return 0;
}
if (liquidQty + quantity <= MAX_LIQUID) {
if (doFill) {

View file

@ -9,6 +9,7 @@
package net.minecraft.src.buildcraft.energy;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.src.Block;
import net.minecraft.src.ICrafting;
import net.minecraft.src.Item;
@ -94,24 +95,10 @@ public class EngineStone extends Engine {
}
private int getItemBurnTime(ItemStack itemstack) {
if (itemstack == null) {
if (itemstack == null)
return 0;
}
int i = itemstack.getItem().shiftedIndex;
if (i < Block.blocksList.length && Block.blocksList[i] != null && Block.blocksList[i].blockMaterial == Material.wood) {
return 300;
}
if (i == Item.stick.shiftedIndex) {
return 100;
}
if (i == Item.coal.shiftedIndex) {
return 1600;
}
if (i == Item.bucketLava.shiftedIndex) {
return 20000;
} else {
return i == Block.sapling.blockID ? 100 : CoreProxy.addFuel(i, itemstack.getItemDamage());
}
return FMLCommonHandler.instance().fuelLookup(itemstack.getItem().shiftedIndex, itemstack.getItemDamage());
}
/* SAVING & LOADING */

View file

@ -24,9 +24,10 @@ import net.minecraft.src.buildcraft.api.LiquidSlot;
import net.minecraft.src.buildcraft.api.Orientations;
import net.minecraft.src.buildcraft.api.PowerFramework;
import net.minecraft.src.buildcraft.api.PowerProvider;
import net.minecraft.src.buildcraft.api.RefineryRecipe;
import net.minecraft.src.buildcraft.api.SafeTimeTracker;
import net.minecraft.src.buildcraft.api.TileNetworkData;
import net.minecraft.src.buildcraft.api.liquids.LiquidStack;
import net.minecraft.src.buildcraft.api.recipes.RefineryRecipe;
import net.minecraft.src.buildcraft.core.IMachine;
public class TileRefinery extends TileMachine implements ILiquidContainer, IPowerReceptor, IInventory, IMachine {
@ -234,19 +235,19 @@ public class TileRefinery extends TileMachine implements ILiquidContainer, IPowe
RefineryRecipe currentRecipe = null;
currentRecipe = BuildCraftAPI.findRefineryRecipe(slot1.liquidId, slot1.quantity, slot2.liquidId, slot2.quantity);
currentRecipe = RefineryRecipe.findRefineryRecipe(new LiquidStack(slot1.liquidId, slot1.quantity, 0), new LiquidStack(slot2.liquidId, slot2.quantity, 0));
if (currentRecipe == null) {
decreaseAnimation();
return;
}
if (result.quantity != 0 && result.liquidId != currentRecipe.resultId) {
if (result.quantity != 0 && result.liquidId != currentRecipe.result.itemID) {
decreaseAnimation();
return;
}
if (result.quantity + currentRecipe.resultQty > LIQUID_PER_SLOT) {
if (result.quantity + currentRecipe.result.amount > LIQUID_PER_SLOT) {
decreaseAnimation();
return;
}
@ -264,8 +265,8 @@ public class TileRefinery extends TileMachine implements ILiquidContainer, IPowe
return;
}
if (!containsInput(currentRecipe.sourceId1, currentRecipe.sourceQty1)
|| !containsInput(currentRecipe.sourceId2, currentRecipe.sourceQty2)) {
if (!containsInput(currentRecipe.ingredient1)
|| !containsInput(currentRecipe.ingredient2)) {
decreaseAnimation();
return;
}
@ -273,29 +274,33 @@ public class TileRefinery extends TileMachine implements ILiquidContainer, IPowe
float energyUsed = powerProvider.useEnergy(currentRecipe.energy, currentRecipe.energy, true);
if (energyUsed != 0) {
if (consumeInput(currentRecipe.sourceId1, currentRecipe.sourceQty1)
&& consumeInput(currentRecipe.sourceId2, currentRecipe.sourceQty2)) {
result.liquidId = currentRecipe.resultId;
result.quantity += currentRecipe.resultQty;
if (consumeInput(currentRecipe.ingredient1)
&& consumeInput(currentRecipe.ingredient2)) {
result.liquidId = currentRecipe.result.itemID;
result.quantity += currentRecipe.result.amount;
}
}
}
private boolean containsInput(int id, int qty) {
return id == 0 || (slot1.liquidId == id && slot1.quantity >= qty) || (slot2.liquidId == id && slot2.quantity >= qty);
private boolean containsInput(LiquidStack liquid) {
if(liquid == null)
return true;
return liquid.isLiquidEqual(new LiquidStack(slot1.liquidId, slot1.quantity, 0)) || liquid.isLiquidEqual(new LiquidStack(slot2.liquidId, slot2.quantity, 0));
}
private boolean consumeInput(int id, int qty) {
if (id == 0) {
private boolean consumeInput(LiquidStack liquid) {
if(liquid == null)
return true;
} else if (slot1.liquidId == id && slot1.quantity >= qty) {
slot1.quantity -= qty;
if(liquid.isLiquidEqual(new LiquidStack(slot1.liquidId, slot1.quantity, 0))) {
slot1.quantity -= liquid.amount;
return true;
} else if (slot2.liquidId == id && slot2.quantity >= qty) {
slot2.quantity -= qty;
} else if(liquid.isLiquidEqual(new LiquidStack(slot2.liquidId, slot2.quantity, 0))) {
slot2.quantity -= liquid.amount;
return true;
}
return false;
}