Skip to content

Commit

Permalink
Re-added deprecated liquids system. To be removed next major MC versi…
Browse files Browse the repository at this point in the history
…ons after issues with Fluids are fixed. (reverse-merged from commit 9b5208f)

This WILL be removed and should not be developed against aside for a temporary 1.6 release.
  • Loading branch information
LexManos committed Jul 22, 2013
1 parent 8c3ebc7 commit b6d543f
Show file tree
Hide file tree
Showing 10 changed files with 1,016 additions and 0 deletions.
59 changes: 59 additions & 0 deletions common/net/minecraftforge/liquids/IBlockLiquid.java
@@ -0,0 +1,59 @@
package net.minecraftforge.liquids;

import net.minecraft.nbt.NBTTagCompound;

/**
* Implementors of this interface are a liquid which may receive a block implementation and can be placed in the world.
*
* @author cpw
*
*/
@Deprecated //See new net.minecraftforge.fluids
public interface IBlockLiquid extends ILiquid {
/**
* Controls the type of block that is generated by this IBlockLiquid
*
*/
public enum BlockType {
/**
* No block. Completeness really.
*/
NONE,
/**
* Vanilla style block, up to 8 flowing states. May be able to generate new sources.
*/
VANILLA,
/**
* Finite liquid style, uses cellular automata to model flowing behaviour.
*/
FINITE;
}

/**
* Can this liquid, when placed in a specific configuration, generate new source blocks of the liquid.
* @return if this liquid will generate new sources
*/
public boolean willGenerateSources();

/**
* @return the distance this liquid will flow if placed in the world. Maximum of 7 levels for vanilla types.
*/
public int getFlowDistance();

/**
* @return the RGB rendering for this liquid
*/
public byte[] getLiquidRGB();

/**
* Get the texture file for rendering the liquid
* @return the texture file for this liquid
*/
public String getLiquidBlockTextureFile();
/**
* Custom properties of the liquid.
* @return a compound tag of custom liquid properties
*/
public NBTTagCompound getLiquidProperties();

}
36 changes: 36 additions & 0 deletions common/net/minecraftforge/liquids/ILiquid.java
@@ -0,0 +1,36 @@
/**
* 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;

/**
* Liquids implement this interface
*
*/
@Deprecated //See new net.minecraftforge.fluids
public interface ILiquid {

/**
* The itemId of the liquid item
* @return the itemId
*/
public int stillLiquidId();

/**
* Is this liquid a metadata based liquid
* @return if this is a metadata liquid
*/
public boolean isMetaSensitive();

/**
* The item metadata of the liquid
* @return the metadata of the liquid
*/
public int stillLiquidMeta();
}
45 changes: 45 additions & 0 deletions common/net/minecraftforge/liquids/ILiquidTank.java
@@ -0,0 +1,45 @@
package net.minecraftforge.liquids;

/**
* A tank is the unit of interaction with liquid inventories.
*
* @author cpw
*/
@Deprecated //See new net.minecraftforge.fluids
public interface ILiquidTank {

/**
* @return LiquidStack representing the liquid contained in the tank, null if empty.
*/
LiquidStack getLiquid();

/**
* @return capacity of this tank
*/
int getCapacity();

/**
*
* @param resource
* @param doFill
* @return Amount of liquid used for filling.
*/
int fill(LiquidStack resource, boolean doFill);
/**
*
* @param maxDrain
* @param doDrain
* @return Null if nothing was drained, otherwise a LiquidStack containing the drained.
*/
LiquidStack drain(int maxDrain, boolean doDrain);

/**
* Positive values indicate a positive liquid pressure (liquid wants to leave this tank)
* Negative values indicate a negative liquid pressure (liquid wants to fill this tank)
* Zero indicates no pressure
*
* @return a number indicating tank pressure
*/
public int getTankPressure();

}
56 changes: 56 additions & 0 deletions common/net/minecraftforge/liquids/ITankContainer.java
@@ -0,0 +1,56 @@
package net.minecraftforge.liquids;

import net.minecraftforge.common.ForgeDirection;
@Deprecated //See new net.minecraftforge.fluids
public interface ITankContainer {

/**
* Fills liquid into internal tanks, distribution is left to the ITankContainer.
* @param from Orientation the liquid is pumped in from.
* @param resource LiquidStack representing the maximum amount of liquid filled into the ITankContainer
* @param doFill If false filling will only be simulated.
* @return Amount of resource that was filled into internal tanks.
*/
int fill(ForgeDirection from, LiquidStack resource, boolean doFill);
/**
* Fills liquid into the specified internal tank.
* @param tankIndex the index of the tank to fill
* @param resource LiquidStack representing the maximum amount of liquid filled into the ITankContainer
* @param doFill If false filling will only be simulated.
* @return Amount of resource that was filled into internal tanks.
*/
int fill(int tankIndex, LiquidStack resource, boolean doFill);

/**
* Drains liquid out of internal tanks, distribution is left to the ITankContainer.
* @param from Orientation the liquid is drained to.
* @param maxDrain Maximum amount of liquid to drain.
* @param doDrain If false draining will only be simulated.
* @return LiquidStack representing the liquid and amount actually drained from the ITankContainer
*/
LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain);
/**
* Drains liquid out of the specified internal tank.
* @param tankIndex the index of the tank to drain
* @param maxDrain Maximum amount of liquid to drain.
* @param doDrain If false draining will only be simulated.
* @return LiquidStack representing the liquid and amount actually drained from the ITankContainer
*/
LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain);

/**
* @param direction tank side: UNKNOWN for default tank set
* @return Array of {@link LiquidTank}s contained in this ITankContainer for this direction
*/
ILiquidTank[] getTanks(ForgeDirection direction);

/**
* Return the tank that this tank container desired to be used for the specified liquid type from the specified direction
*
* @param direction the direction
* @param type the liquid type, null is always an acceptable value
* @return a tank or null for no such tank
*/
ILiquidTank getTank(ForgeDirection direction, LiquidStack type);

}
31 changes: 31 additions & 0 deletions common/net/minecraftforge/liquids/LiquidContainerData.java
@@ -0,0 +1,31 @@
/**
* 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.item.Item;
import net.minecraft.item.ItemStack;
@Deprecated //See new net.minecraftforge.fluids
public class LiquidContainerData {

public final LiquidStack stillLiquid;
public final ItemStack filled;
public final ItemStack container;


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");
}

}
131 changes: 131 additions & 0 deletions common/net/minecraftforge/liquids/LiquidContainerRegistry.java
@@ -0,0 +1,131 @@

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.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@Deprecated //See new net.minecraftforge.fluids
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()));
return ret == null ? null : ret.stillLiquid.copy();
}

public static ItemStack fillLiquidContainer(LiquidStack liquid, ItemStack emptyContainer)
{
if (emptyContainer == null || liquid == null)
{
return null;
}

LiquidContainerData ret = mapFilledItemFromLiquid.get(Arrays.asList(emptyContainer.itemID, emptyContainer.getItemDamage(), liquid.itemID, liquid.itemMeta));

if (ret != null && liquid.amount >= ret.stillLiquid.amount)
{
return ret.filled.copy();
}

return null;
}

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()));

return ret != null && ret.stillLiquid.isLiquidEqual(liquid);
}

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()));
return ret != null && ret.container.isItemEqual(EMPTY_BUCKET);
}

public static boolean isContainer(ItemStack container)
{
return isEmptyContainer(container) || isFilledContainer(container);
}

public static boolean isEmptyContainer(ItemStack emptyContainer)
{
return emptyContainer != null && setContainerValidation.contains(Arrays.asList(emptyContainer.itemID, emptyContainer.getItemDamage()));
}

public static boolean isFilledContainer(ItemStack filledContainer)
{
return filledContainer != null && getLiquidForFilledItem(filledContainer) != null;
}

public static boolean isLiquid(ItemStack item)
{
return item != null && setLiquidValidation.contains(Arrays.asList(item.itemID, item.getItemDamage()));
}

public static LiquidContainerData[] getRegisteredLiquidContainerData()
{
return liquids.toArray(new LiquidContainerData[liquids.size()]);
}
}

0 comments on commit b6d543f

Please sign in to comment.