Started refactor of liquid handling.
This commit is contained in:
parent
f1caf84953
commit
792f2bff5f
6 changed files with 204 additions and 10 deletions
|
@ -32,6 +32,7 @@ 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>();
|
||||
public static Trigger[] triggers = new Trigger[1024];
|
||||
|
@ -42,6 +43,7 @@ public class BuildCraftAPI {
|
|||
private static LinkedList<ITriggerProvider> triggerProviders = new LinkedList<ITriggerProvider>();
|
||||
private static LinkedList<IActionProvider> actionProviders = new LinkedList<IActionProvider>();
|
||||
|
||||
@Deprecated
|
||||
public static int getLiquidForFilledItem(ItemStack filledItem) {
|
||||
if (filledItem == null) {
|
||||
return 0;
|
||||
|
@ -56,6 +58,7 @@ public class BuildCraftAPI {
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ItemStack getFilledItemForLiquid(int liquidId) {
|
||||
for (LiquidData d : liquids) {
|
||||
if (d.liquidId == liquidId) {
|
||||
|
@ -66,15 +69,7 @@ public class BuildCraftAPI {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack fillLiquidContainer(int liquidId, ItemStack emptyContainer){
|
||||
for(LiquidData data : liquids) {
|
||||
if(data.liquidId == liquidId && data.container.isItemEqual(emptyContainer)) {
|
||||
return data.filled.copy();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean isLiquid(int blockId) {
|
||||
if (blockId == 0) {
|
||||
return false;
|
||||
|
|
|
@ -12,6 +12,7 @@ package net.minecraft.src.buildcraft.api;
|
|||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
@Deprecated
|
||||
public class LiquidData {
|
||||
|
||||
public final int liquidId;
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* 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.liquids;
|
||||
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
|
||||
|
||||
public class LiquidData {
|
||||
|
||||
public final LiquidStack stillLiquid;
|
||||
public final LiquidStack movingLiquid;
|
||||
|
||||
public final ItemStack filled;
|
||||
public final ItemStack container;
|
||||
|
||||
public LiquidData(int stillLiquidId, int movingLiquidId, Item filled) {
|
||||
this(new LiquidStack(stillLiquidId, BuildCraftAPI.BUCKET_VOLUME), new LiquidStack(movingLiquidId, BuildCraftAPI.BUCKET_VOLUME), new ItemStack(filled, 1), new ItemStack(Item.bucketEmpty));
|
||||
}
|
||||
|
||||
public LiquidData(int stillLiquidId, int movingLiquidId, ItemStack filled) {
|
||||
this(new LiquidStack(stillLiquidId, BuildCraftAPI.BUCKET_VOLUME), new LiquidStack(movingLiquidId, BuildCraftAPI.BUCKET_VOLUME), filled, new ItemStack(Item.bucketEmpty));
|
||||
}
|
||||
|
||||
public LiquidData(LiquidStack stillLiquid, LiquidStack movingLiquid, ItemStack filled, ItemStack container) {
|
||||
this.stillLiquid = stillLiquid;
|
||||
this.movingLiquid = movingLiquid;
|
||||
this.filled = filled;
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package net.minecraft.src.buildcraft.api.liquids;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class LiquidManager {
|
||||
|
||||
public static LinkedList<LiquidData> liquids = new LinkedList<LiquidData>();
|
||||
|
||||
public static LiquidStack getLiquidForFilledItem(ItemStack filledItem) {
|
||||
if (filledItem == null)
|
||||
return null;
|
||||
|
||||
for (LiquidData liquid : liquids)
|
||||
if (liquid.filled.isItemEqual(filledItem))
|
||||
return liquid.stillLiquid;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack getFilledItemForLiquid(LiquidStack liquid) {
|
||||
for (LiquidData data : liquids)
|
||||
if(data.stillLiquid.isLiquidEqual(liquid))
|
||||
return data.filled.copy();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack fillLiquidContainer(int liquidId, ItemStack emptyContainer) {
|
||||
return fillLiquidContainer(new LiquidStack(liquidId, 1, 0), emptyContainer);
|
||||
}
|
||||
|
||||
public static ItemStack fillLiquidContainer(LiquidStack liquid, ItemStack emptyContainer) {
|
||||
for(LiquidData data : liquids)
|
||||
if(data.stillLiquid.isLiquidEqual(liquid) && data.container.isItemEqual(emptyContainer))
|
||||
return data.filled.copy();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isLiquid(ItemStack block) {
|
||||
if (block.itemID == 0)
|
||||
return false;
|
||||
|
||||
for (LiquidData liquid : liquids)
|
||||
if (liquid.stillLiquid.isLiquidEqual(block) || liquid.movingLiquid.isLiquidEqual(block))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
104
common/net/minecraft/src/buildcraft/api/liquids/LiquidStack.java
Normal file
104
common/net/minecraft/src/buildcraft/api/liquids/LiquidStack.java
Normal file
|
@ -0,0 +1,104 @@
|
|||
package net.minecraft.src.buildcraft.api.liquids;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
|
||||
/**
|
||||
*
|
||||
* Forestry internal ItemStack substitute for liquids
|
||||
*
|
||||
* @author SirSengir
|
||||
*/
|
||||
public class LiquidStack {
|
||||
public int itemID;
|
||||
public int amount;
|
||||
public int itemMeta;
|
||||
|
||||
public NBTTagCompound stackTagCompound;
|
||||
|
||||
private LiquidStack() {
|
||||
}
|
||||
|
||||
public LiquidStack(int itemID, int liquidAmount) {
|
||||
this(itemID, liquidAmount, 0);
|
||||
}
|
||||
|
||||
public LiquidStack(Item item, int liquidAmount) {
|
||||
this(item.shiftedIndex, liquidAmount, 0);
|
||||
}
|
||||
|
||||
public LiquidStack(Block block, int liquidAmount) {
|
||||
this(block.blockID, liquidAmount, 0);
|
||||
}
|
||||
|
||||
public LiquidStack(int itemID, int amount, int itemDamage) {
|
||||
this.itemID = itemID;
|
||||
this.amount = amount;
|
||||
this.itemMeta = itemDamage;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setShort("Id", (short) itemID);
|
||||
nbttagcompound.setInteger("Amount", amount);
|
||||
nbttagcompound.setShort("Meta", (short) itemMeta);
|
||||
if (stackTagCompound != null)
|
||||
nbttagcompound.setTag("Tag", stackTagCompound);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
itemID = nbttagcompound.getShort("Id");
|
||||
amount = nbttagcompound.getInteger("Amount");
|
||||
itemMeta = nbttagcompound.getShort("Meta");
|
||||
if (nbttagcompound.hasKey("Tag"))
|
||||
stackTagCompound = nbttagcompound.getCompoundTag("tag");
|
||||
}
|
||||
|
||||
public LiquidStack copy() {
|
||||
LiquidStack copy = new LiquidStack(itemID, amount, itemMeta);
|
||||
if (stackTagCompound != null) {
|
||||
copy.stackTagCompound = (NBTTagCompound) stackTagCompound.copy();
|
||||
if (!copy.stackTagCompound.equals(stackTagCompound))
|
||||
return copy;
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
public NBTTagCompound getTagCompound() {
|
||||
return stackTagCompound;
|
||||
}
|
||||
|
||||
public void setTagCompound(NBTTagCompound nbttagcompound) {
|
||||
stackTagCompound = nbttagcompound;
|
||||
}
|
||||
|
||||
public boolean isLiquidEqual(LiquidStack other) {
|
||||
return itemID == other.itemID && itemMeta == other.itemMeta;
|
||||
}
|
||||
|
||||
public boolean isLiquidEqual(ItemStack other) {
|
||||
return itemID == other.itemID && itemMeta == other.getItemDamage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An ItemStack representation of this LiquidStack
|
||||
*/
|
||||
public ItemStack asItemStack() {
|
||||
return new ItemStack(itemID, 1, itemMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a liquid stack from the passed nbttagcompound and returns it.
|
||||
*
|
||||
* @param nbttagcompound
|
||||
* @return
|
||||
*/
|
||||
public static LiquidStack loadLiquidStackFromNBT(NBTTagCompound nbttagcompound) {
|
||||
LiquidStack liquidstack = new LiquidStack();
|
||||
liquidstack.readFromNBT(nbttagcompound);
|
||||
return liquidstack.itemID == 0 ? null : liquidstack;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,9 +10,11 @@
|
|||
package net.minecraft.src.buildcraft.factory;
|
||||
|
||||
import net.minecraft.src.BuildCraftFactory;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.buildcraft.api.BuildCraftAPI;
|
||||
import net.minecraft.src.buildcraft.api.liquids.LiquidManager;
|
||||
import net.minecraft.src.forge.IBucketHandler;
|
||||
|
||||
public class TankBucketHandler implements IBucketHandler {
|
||||
|
@ -25,7 +27,7 @@ public class TankBucketHandler implements IBucketHandler {
|
|||
|
||||
int qty = tank.empty(BuildCraftAPI.BUCKET_VOLUME, false);
|
||||
|
||||
ItemStack filledBucket = BuildCraftAPI.fillLiquidContainer(tank.getLiquidId(), new ItemStack(Item.bucketEmpty));
|
||||
ItemStack filledBucket = LiquidManager.fillLiquidContainer(tank.getLiquidId(), new ItemStack(Item.bucketEmpty));
|
||||
|
||||
if (qty >= BuildCraftAPI.BUCKET_VOLUME && filledBucket != null) {
|
||||
tank.empty(BuildCraftAPI.BUCKET_VOLUME, true);
|
||||
|
|
Loading…
Reference in a new issue