Merge branch 'KingLemming-master'

This commit is contained in:
Christian 2012-11-15 06:44:43 -05:00
commit 8a1f589db2
3 changed files with 140 additions and 84 deletions

View file

@ -22,12 +22,12 @@ public class LiquidContainerData {
@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));
this(new LiquidStack(stillLiquidId, LiquidContainerRegistry.BUCKET_VOLUME), new LiquidStack(movingLiquidId, LiquidContainerRegistry.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));
this(new LiquidStack(stillLiquidId, LiquidContainerRegistry.BUCKET_VOLUME), new LiquidStack(movingLiquidId, LiquidContainerRegistry.BUCKET_VOLUME), filled, new ItemStack(Item.bucketEmpty));
}
public LiquidContainerData(LiquidStack stillLiquid, ItemStack filled, ItemStack container) {

View file

@ -0,0 +1,138 @@
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 LiquidContainerRegistry {
public static final int BUCKET_VOLUME = 1000;
public static final ItemStack EMPTY_BUCKET = new ItemStack(Item.bucketEmpty);
private static Map<List, LiquidContainerData> mapFilledItemFromLiquid = new HashMap();
private static Map<List, LiquidContainerData> mapLiquidFromFilledItem = new HashMap();
private static Set<List> setContainerValidation = new HashSet();
private static Set<List> setLiquidValidation = new HashSet();
private static ArrayList<LiquidContainerData> liquids = new ArrayList();
/**
* Default registrations
*/
static {
registerLiquid(new LiquidContainerData(new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack(Item.bucketWater), new ItemStack(Item.bucketEmpty)));
registerLiquid(new LiquidContainerData(new LiquidStack(Block.lavaStill, LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack(Item.bucketLava), new ItemStack(Item.bucketEmpty)));
registerLiquid(new LiquidContainerData(new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack(Item.potion), new ItemStack(Item.glassBottle)));
// registerLiquid(new LiquidContainerData(new LiquidStack(Item.bucketMilk, LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack(Item.bucketMilk), new ItemStack(Item.bucketEmpty)));
}
/**
* To register a container with a non-bucket size, the LiquidContainerData entry simply needs to use a size other than LiquidManager.BUCKET_VOLUME
*/
public static void registerLiquid(LiquidContainerData data) {
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()));
setLiquidValidation.add(Arrays.asList(data.stillLiquid.itemID, data.stillLiquid.itemMeta));
liquids.add(data);
}
public static LiquidStack getLiquidForFilledItem(ItemStack filledContainer) {
if (filledContainer == null) {
return null;
}
LiquidContainerData ret = mapLiquidFromFilledItem.get(Arrays.asList(filledContainer.itemID, filledContainer.getItemDamage()));
if (ret != null) {
return ret.stillLiquid.copy();
}
return null;
}
public static ItemStack fillLiquidContainer(LiquidStack liquid, ItemStack emptyContainer) {
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;
}
public static boolean containsLiquid(ItemStack filledContainer, LiquidStack liquid) {
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);
}
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;
}
public static boolean isLiquid(ItemStack item) {
if (item == null) {
return false;
}
return setLiquidValidation.contains(Arrays.asList(item.itemID, item.getItemDamage()));
}
public static LiquidContainerData[] getRegisteredLiquidContainerData() {
return liquids.toArray(new LiquidContainerData[0]);
}
}

View file

@ -1,82 +0,0 @@
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;
}
}