Merge branch 'KingLemming-master'

This commit is contained in:
Christian 2012-11-14 21:23:47 -05:00
commit a3a6f281e0
5 changed files with 154 additions and 109 deletions

View file

@ -1,13 +1,37 @@
package net.minecraftforge.liquids;
/**
* A tank is the unit of interaction with liquid inventories.
*
* @author cpw
*/
public interface ILiquidTank {
/**
* @return LiquidStack representing the liquid contained in the tank, null if empty.
*/
LiquidStack getLiquid();
/**
* These shouldn't be used to interact with a foreign tank. Use {@link #fill(LiquidStack, boolean)}
* and {@link #drain(int, boolean)}.
*
* @param liquid
*/
@Deprecated
void setLiquid(LiquidStack liquid);
/**
* This method should not be used to interact with a foreign tank. Use {@link #fill(LiquidStack, boolean)}
* and {@link #drain(int, boolean)}.
*
* @param capacity
*/
@Deprecated
void setCapacity(int capacity);
/**
* @return capacity of this tank
*/
int getCapacity();
/**

View file

@ -0,0 +1,48 @@
/**
* 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.minecraftforge.liquids;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
public class LiquidContainerData {
public final LiquidStack stillLiquid;
@Deprecated public LiquidStack movingLiquid;
public final ItemStack filled;
public final ItemStack container;
@Deprecated
public LiquidContainerData(int stillLiquidId, int movingLiquidId, Item filled) {
this(new LiquidStack(stillLiquidId, LiquidItemRegistry.BUCKET_VOLUME), new LiquidStack(movingLiquidId, LiquidItemRegistry.BUCKET_VOLUME), new ItemStack(filled, 1), new ItemStack(Item.bucketEmpty));
}
@Deprecated
public LiquidContainerData(int stillLiquidId, int movingLiquidId, ItemStack filled) {
this(new LiquidStack(stillLiquidId, LiquidItemRegistry.BUCKET_VOLUME), new LiquidStack(movingLiquidId, LiquidItemRegistry.BUCKET_VOLUME), filled, new ItemStack(Item.bucketEmpty));
}
public LiquidContainerData(LiquidStack stillLiquid, ItemStack filled, ItemStack container) {
this.stillLiquid = stillLiquid;
this.filled = filled;
this.container = container;
if(stillLiquid == null || filled == null || container == null)
throw new RuntimeException("stillLiquid, filled, or container is null, this is an error");
}
@Deprecated
public LiquidContainerData(LiquidStack stillLiquid, LiquidStack movingLiquid, ItemStack filled, ItemStack container) {
this(stillLiquid, filled, container);
this.movingLiquid = movingLiquid;
}
}

View file

@ -1,45 +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 net.minecraftforge.liquids;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
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, LiquidManager.BUCKET_VOLUME), new LiquidStack(movingLiquidId, LiquidManager.BUCKET_VOLUME), new ItemStack(filled, 1), new ItemStack(Item.bucketEmpty));
}
public LiquidData(int stillLiquidId, int movingLiquidId, ItemStack filled) {
this(new LiquidStack(stillLiquidId, LiquidManager.BUCKET_VOLUME), new LiquidStack(movingLiquidId, LiquidManager.BUCKET_VOLUME), filled, new ItemStack(Item.bucketEmpty));
}
public LiquidData(LiquidStack stillLiquid, ItemStack filled, ItemStack container) {
this(stillLiquid, stillLiquid, filled, container);
}
public LiquidData(LiquidStack stillLiquid, LiquidStack movingLiquid, ItemStack filled, ItemStack container) {
this.stillLiquid = stillLiquid;
this.movingLiquid = movingLiquid;
this.filled = filled;
this.container = container;
if(stillLiquid == null || filled == null || container == null)
throw new RuntimeException("stillLiquid, filled, or container is null, this is an error");
}
}

View file

@ -0,0 +1,82 @@
package net.minecraftforge.liquids;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
public class LiquidItemRegistry {
public static final int BUCKET_VOLUME = 1000;
private static Map<List, ItemStack> mapItemFromLiquid = new HashMap();
private static Map<List, LiquidStack> mapLiquidFromItem = new HashMap();
private static Set<List> setLiquidValidation = new HashSet();
private static ArrayList<LiquidContainerData> liquids = new ArrayList();
static {
registerLiquid(
new LiquidContainerData(
new LiquidStack(Block.waterStill, LiquidItemRegistry.BUCKET_VOLUME),
new ItemStack(Item.bucketWater), new ItemStack(Item.bucketEmpty)));
registerLiquid(
new LiquidContainerData(
new LiquidStack(Block.lavaStill, LiquidItemRegistry.BUCKET_VOLUME),
new ItemStack(Item.bucketLava), new ItemStack(Item.bucketEmpty)));
registerLiquid(
new LiquidContainerData(
new LiquidStack(Block.waterStill, LiquidItemRegistry.BUCKET_VOLUME),
new ItemStack(Item.potion), new ItemStack(Item.glassBottle)));
/* registerLiquid(
new LiquidContainerData(
new LiquidStack(Item.milk, LiquidItemRegistry.BUCKET_VOLUME),
new ItemStack(Item.potion), new ItemStack(Item.glassBottle)));
*/ }
public static void registerLiquid(LiquidContainerData data) {
mapItemFromLiquid.put(Arrays.asList(data.container.itemID, data.container.getItemDamage(), data.stillLiquid.itemID, data.stillLiquid.itemMeta), data.filled);
mapLiquidFromItem.put(Arrays.asList(data.filled.itemID, data.filled.getItemDamage()), data.stillLiquid);
setLiquidValidation.add(Arrays.asList(data.stillLiquid.itemID, data.stillLiquid.itemMeta));
liquids.add(data);
}
public static LiquidStack getLiquidForFilledItem(ItemStack filledItem) {
if (filledItem == null) {
return null;
}
return mapLiquidFromItem.get(Arrays.asList(filledItem.itemID, filledItem.getItemDamage()));
}
public static ItemStack fillLiquidContainer(int liquidId, int quantity, ItemStack emptyContainer) {
return fillLiquidContainer(new LiquidStack(liquidId, quantity, 0), emptyContainer);
}
public static ItemStack fillLiquidContainer(LiquidStack liquid, ItemStack emptyContainer) {
if (emptyContainer == null || liquid == null) {
return null;
}
return mapItemFromLiquid.get(Arrays.asList(emptyContainer.itemID, emptyContainer.getItemDamage(), liquid.itemID, liquid.itemMeta));
}
public static boolean isLiquid(ItemStack block) {
return setLiquidValidation.contains(Arrays.asList(block.itemID, block.getItemDamage()));
}
public static ArrayList<LiquidContainerData> getRegisteredLiquids() {
return liquids;
}
}

View file

@ -1,64 +0,0 @@
package net.minecraftforge.liquids;
import java.util.LinkedList;
import net.minecraft.src.ItemStack;
public class LiquidManager {
public static final int BUCKET_VOLUME = 1000;
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 int getLiquidIDForFilledItem(ItemStack filledItem) {
LiquidStack liquidForFilledItem = getLiquidForFilledItem(filledItem);
if (liquidForFilledItem == null)
return 0;
return liquidForFilledItem.itemID;
}
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, int quantity, ItemStack emptyContainer) {
return fillLiquidContainer(new LiquidStack(liquidId, quantity, 0), emptyContainer);
}
public static ItemStack fillLiquidContainer(LiquidStack liquid, ItemStack emptyContainer) {
for(LiquidData data : liquids)
if(liquid.containsLiquid(data.stillLiquid)
&& 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;
}
}