2012-11-14 23:55:08 +00:00
|
|
|
|
2012-11-11 02:23:16 +00:00
|
|
|
package net.minecraftforge.liquids;
|
|
|
|
|
2012-11-14 23:55:08 +00:00
|
|
|
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;
|
2012-11-11 02:23:16 +00:00
|
|
|
|
2012-11-14 23:55:08 +00:00
|
|
|
import net.minecraft.src.Block;
|
|
|
|
import net.minecraft.src.Item;
|
2012-11-11 02:23:16 +00:00
|
|
|
import net.minecraft.src.ItemStack;
|
|
|
|
|
2012-11-15 02:22:44 +00:00
|
|
|
public class LiquidItemRegistry {
|
2012-11-11 02:23:16 +00:00
|
|
|
|
2012-11-14 23:55:08 +00:00
|
|
|
public static final int BUCKET_VOLUME = 1000;
|
2012-11-15 06:05:23 +00:00
|
|
|
public static final ItemStack EMPTY_BUCKET = new ItemStack(Item.bucketEmpty);
|
2012-11-14 23:55:08 +00:00
|
|
|
|
2012-11-15 06:05:23 +00:00
|
|
|
private static Map<List, LiquidContainerData> mapFilledItemFromLiquid = new HashMap();
|
|
|
|
private static Map<List, LiquidContainerData> mapLiquidFromFilledItem = new HashMap();
|
|
|
|
private static Set<List> setContainerValidation = new HashSet();
|
2012-11-14 23:55:08 +00:00
|
|
|
private static Set<List> setLiquidValidation = new HashSet();
|
2012-11-15 02:22:44 +00:00
|
|
|
private static ArrayList<LiquidContainerData> liquids = new ArrayList();
|
2012-11-14 23:55:08 +00:00
|
|
|
|
2012-11-15 06:05:23 +00:00
|
|
|
/**
|
|
|
|
* Default registrations
|
|
|
|
*/
|
2012-11-14 23:55:08 +00:00
|
|
|
static {
|
2012-11-15 06:05:23 +00:00
|
|
|
registerLiquid(new LiquidContainerData(new LiquidStack(Block.waterStill, LiquidItemRegistry.BUCKET_VOLUME), new LiquidStack(Block.waterMoving,
|
|
|
|
LiquidItemRegistry.BUCKET_VOLUME), new ItemStack(Item.bucketWater), new ItemStack(Item.bucketEmpty)));
|
|
|
|
registerLiquid(new LiquidContainerData(new LiquidStack(Block.lavaStill, LiquidItemRegistry.BUCKET_VOLUME), new LiquidStack(Block.lavaMoving,
|
|
|
|
LiquidItemRegistry.BUCKET_VOLUME), new ItemStack(Item.bucketLava), new ItemStack(Item.bucketEmpty)));
|
|
|
|
registerLiquid(new LiquidContainerData(new LiquidStack(Block.waterStill, LiquidItemRegistry.BUCKET_VOLUME), new LiquidStack(Block.waterMoving,
|
|
|
|
LiquidItemRegistry.BUCKET_VOLUME), new ItemStack(Item.potion), new ItemStack(Item.glassBottle)));
|
|
|
|
// registerLiquid(new LiquidContainerData(new LiquidStack(Item.bucketMilk, LiquidItemRegistry.BUCKET_VOLUME), new ItemStack(Item.bucketMilk), new
|
|
|
|
// ItemStack(Item.bucketEmpty)));
|
|
|
|
}
|
2012-11-15 02:22:44 +00:00
|
|
|
|
2012-11-15 06:05:23 +00:00
|
|
|
/**
|
|
|
|
* To register a container with a non-bucket size, the LiquidContainerData entry simply needs to use a size other than LiquidManager.BUCKET_VOLUME
|
|
|
|
*/
|
2012-11-15 02:22:44 +00:00
|
|
|
public static void registerLiquid(LiquidContainerData data) {
|
2012-11-14 23:55:08 +00:00
|
|
|
|
2012-11-15 06:05:23 +00:00
|
|
|
mapFilledItemFromLiquid.put(Arrays.asList(data.container.itemID, data.container.getItemDamage(), data.stillLiquid.itemID, data.stillLiquid.itemMeta), data);
|
|
|
|
mapLiquidFromFilledItem.put(Arrays.asList(data.filled.itemID, data.filled.getItemDamage()), data);
|
|
|
|
setContainerValidation.add(Arrays.asList(data.container.itemID, data.container.getItemDamage()));
|
2012-11-14 23:55:08 +00:00
|
|
|
setLiquidValidation.add(Arrays.asList(data.stillLiquid.itemID, data.stillLiquid.itemMeta));
|
|
|
|
|
|
|
|
liquids.add(data);
|
|
|
|
}
|
|
|
|
|
2012-11-15 06:05:23 +00:00
|
|
|
public static LiquidStack getLiquidForFilledItem(ItemStack filledContainer) {
|
2012-11-14 23:55:08 +00:00
|
|
|
|
2012-11-15 06:05:23 +00:00
|
|
|
if (filledContainer == null) {
|
2012-11-14 23:55:08 +00:00
|
|
|
return null;
|
|
|
|
}
|
2012-11-15 06:05:23 +00:00
|
|
|
LiquidContainerData ret = mapLiquidFromFilledItem.get(Arrays.asList(filledContainer.itemID, filledContainer.getItemDamage()));
|
|
|
|
if (ret != null) {
|
|
|
|
return ret.stillLiquid.copy();
|
|
|
|
}
|
|
|
|
return null;
|
2012-11-14 23:55:08 +00:00
|
|
|
}
|
|
|
|
|
2012-11-15 06:05:23 +00:00
|
|
|
public static ItemStack fillLiquidContainer(LiquidStack liquid, ItemStack emptyContainer) {
|
2012-11-14 23:55:08 +00:00
|
|
|
|
2012-11-15 06:05:23 +00:00
|
|
|
if (emptyContainer == null || liquid == null) {
|
|
|
|
return emptyContainer;
|
|
|
|
}
|
|
|
|
LiquidContainerData ret = mapFilledItemFromLiquid.get(Arrays.asList(emptyContainer.itemID, emptyContainer.getItemDamage(), liquid.itemID, liquid.itemMeta));
|
|
|
|
if (ret != null) {
|
|
|
|
if (liquid.amount >= ret.stillLiquid.amount) {
|
|
|
|
return ret.filled.copy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return emptyContainer;
|
2012-11-14 23:55:08 +00:00
|
|
|
}
|
|
|
|
|
2012-11-15 06:05:23 +00:00
|
|
|
public static boolean containsLiquid(ItemStack filledContainer, LiquidStack liquid) {
|
2012-11-14 23:55:08 +00:00
|
|
|
|
2012-11-15 06:05:23 +00:00
|
|
|
if (filledContainer == null || liquid == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
LiquidContainerData ret = mapLiquidFromFilledItem.get(Arrays.asList(filledContainer.itemID, filledContainer.getItemDamage()));
|
|
|
|
if (ret != null) {
|
|
|
|
return ret.stillLiquid.isLiquidEqual(liquid);
|
2012-11-14 23:55:08 +00:00
|
|
|
}
|
2012-11-15 06:05:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isBucket(ItemStack container) {
|
|
|
|
|
|
|
|
if (container == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (container.isItemEqual(EMPTY_BUCKET)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
LiquidContainerData ret = mapLiquidFromFilledItem.get(Arrays.asList(container.itemID, container.getItemDamage()));
|
|
|
|
if (ret != null) {
|
|
|
|
return ret.container.isItemEqual(EMPTY_BUCKET);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isContainer(ItemStack container) {
|
|
|
|
|
|
|
|
return isEmptyContainer(container) || isFilledContainer(container);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isEmptyContainer(ItemStack emptyContainer) {
|
|
|
|
|
|
|
|
if (emptyContainer == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return setContainerValidation.contains(Arrays.asList(emptyContainer.itemID, emptyContainer.getItemDamage()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isFilledContainer(ItemStack filledContainer) {
|
|
|
|
|
|
|
|
if (filledContainer == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return getLiquidForFilledItem(filledContainer) != null;
|
2012-11-14 23:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isLiquid(ItemStack block) {
|
|
|
|
|
2012-11-15 06:05:23 +00:00
|
|
|
if (block == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-14 23:55:08 +00:00
|
|
|
return setLiquidValidation.contains(Arrays.asList(block.itemID, block.getItemDamage()));
|
|
|
|
}
|
|
|
|
|
2012-11-15 06:05:23 +00:00
|
|
|
public static LiquidContainerData[] getRegisteredLiquidContainerData() {
|
|
|
|
|
|
|
|
return liquids.toArray(new LiquidContainerData[0]);
|
2012-11-14 23:55:08 +00:00
|
|
|
}
|
2012-11-11 02:23:16 +00:00
|
|
|
}
|