mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 19:59:42 +00:00
As agreed, liquid API from BuildCraft has been migrated to minecraft forge. There will be cleanups to follow,
including sided handling and client rendering tweaks. Stay tuned! Tweak forgedirection for a couple of naming constants
This commit is contained in:
1 parent
477e9bfc2b
commit
58fc306bf2
10 files changed
+473
-5
No files matched your search
@@ -30,8 +30,8 @@ public enum ForgeDirection
|
||||
public final int offsetZ;
|
||||
public final int flag;
|
||||
public static final ForgeDirection[] VALID_DIRECTIONS = {DOWN, UP, NORTH, SOUTH, WEST, EAST};
|
||||
public static final int[] opposite = {1, 0, 3, 2, 5, 4, 6};
|
||||
public static final int[] toLeft = {0, 1, 5, 4, 3, 2, 6};
|
||||
public static final int[] OPPOSITES = {1, 0, 3, 2, 5, 4, 6};
|
||||
public static final int[] TO_LEFT = {0, 1, 5, 4, 3, 2, 6};
|
||||
|
||||
private ForgeDirection(int x, int y, int z)
|
||||
{
|
||||
@@ -52,11 +52,11 @@ public enum ForgeDirection
|
||||
|
||||
public ForgeDirection getOpposite()
|
||||
{
|
||||
return getOrientation(opposite[ordinal()]);
|
||||
return getOrientation(OPPOSITES[ordinal()]);
|
||||
}
|
||||
|
||||
public ForgeDirection getLeftRotation()
|
||||
{
|
||||
return getOrientation(toLeft[ordinal()]);
|
||||
return getOrientation(TO_LEFT[ordinal()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
public interface ILiquid {
|
||||
|
||||
public int stillLiquidId();
|
||||
|
||||
public boolean isMetaSensitive();
|
||||
|
||||
public int stillLiquidMeta();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.minecraftforge.liquids;
|
||||
|
||||
public interface ILiquidTank {
|
||||
|
||||
/**
|
||||
* @return LiquidStack representing the liquid contained in the tank, null if empty.
|
||||
*/
|
||||
LiquidStack getLiquid();
|
||||
void setLiquid(LiquidStack liquid);
|
||||
void setCapacity(int capacity);
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.minecraftforge.liquids;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
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 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(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 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(int tankIndex, int maxDrain, boolean doDrain);
|
||||
|
||||
/**
|
||||
* @return Array of {@link LiquidTank}s contained in this ITankContainer
|
||||
*/
|
||||
ILiquidTank[] getTanks();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package net.minecraftforge.liquids;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When creating liquids you should register them with this class.
|
||||
*
|
||||
* @author CovertJaguar <railcraft.wikispaces.com>
|
||||
*/
|
||||
public abstract class LiquidDictionary
|
||||
{
|
||||
|
||||
private static Map<String, LiquidStack> liquids = new HashMap<String, LiquidStack>();
|
||||
|
||||
/**
|
||||
* When creating liquids you should call this function.
|
||||
*
|
||||
* Upon passing it a name and liquid item it will return either
|
||||
* a preexisting implementation of that liquid or the liquid passed in.
|
||||
*
|
||||
*
|
||||
* @param name the name of the liquid
|
||||
* @param liquid the liquid to use if one doesn't exist
|
||||
* @return
|
||||
*/
|
||||
public static LiquidStack getOrCreateLiquid(String name, LiquidStack liquid)
|
||||
{
|
||||
LiquidStack existing = liquids.get(name);
|
||||
if(existing != null) {
|
||||
return existing.copy();
|
||||
}
|
||||
liquids.put(name, liquid.copy());
|
||||
return liquid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the liquid matching the name,
|
||||
* if such a liquid exists.
|
||||
*
|
||||
* Can return null.
|
||||
*
|
||||
* @param name the name of the liquid
|
||||
* @param amount the amout of liquid
|
||||
* @return
|
||||
*/
|
||||
public static LiquidStack getLiquid(String name, int amount)
|
||||
{
|
||||
LiquidStack liquid = liquids.get(name);
|
||||
if(liquid == null)
|
||||
return null;
|
||||
|
||||
liquid = liquid.copy();
|
||||
liquid.amount = amount;
|
||||
return liquid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package net.minecraftforge.liquids;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* ItemStack substitute for liquids
|
||||
* @author SirSengir
|
||||
*/
|
||||
public class LiquidStack {
|
||||
public int itemID;
|
||||
public int amount;
|
||||
public int itemMeta;
|
||||
|
||||
private LiquidStack() {
|
||||
}
|
||||
|
||||
public LiquidStack(int itemID, int amount) {
|
||||
this(itemID, amount, 0);
|
||||
}
|
||||
|
||||
public LiquidStack(Item item, int amount) {
|
||||
this(item.shiftedIndex, amount, 0);
|
||||
}
|
||||
|
||||
public LiquidStack(Block block, int amount) {
|
||||
this(block.blockID, amount, 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);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
itemID = nbttagcompound.getShort("Id");
|
||||
amount = nbttagcompound.getInteger("Amount");
|
||||
itemMeta = nbttagcompound.getShort("Meta");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A copy of this LiquidStack
|
||||
*/
|
||||
public LiquidStack copy() {
|
||||
return new LiquidStack(itemID, amount, itemMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other
|
||||
* @return true if this LiquidStack contains the same liquid as the one passed in.
|
||||
*/
|
||||
public boolean isLiquidEqual(LiquidStack other) {
|
||||
if(other == null)
|
||||
return false;
|
||||
|
||||
return itemID == other.itemID && itemMeta == other.itemMeta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other
|
||||
* @return true if this LiquidStack contains the other liquid (liquids are equal and amount >= other.amount).
|
||||
*/
|
||||
public boolean containsLiquid(LiquidStack other) {
|
||||
if(!isLiquidEqual(other))
|
||||
return false;
|
||||
|
||||
return amount >= other.amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other ItemStack containing liquids.
|
||||
* @return true if this LiquidStack contains the same liquid as the one passed in.
|
||||
*/
|
||||
public boolean isLiquidEqual(ItemStack other) {
|
||||
if(other == null)
|
||||
return false;
|
||||
|
||||
return itemID == other.itemID && itemMeta == other.getItemDamage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package net.minecraftforge.liquids;
|
||||
|
||||
/**
|
||||
* Reference implementation of ILiquidTank. Use this or implement your own.
|
||||
*/
|
||||
public class LiquidTank implements ILiquidTank {
|
||||
private LiquidStack liquid;
|
||||
private int capacity;
|
||||
|
||||
public LiquidTank(int capacity) {
|
||||
this(null, capacity);
|
||||
}
|
||||
|
||||
public LiquidTank(int liquidId, int quantity, int capacity) {
|
||||
this(new LiquidStack(liquidId, quantity), capacity);
|
||||
}
|
||||
public LiquidTank(LiquidStack liquid, int capacity) {
|
||||
this.liquid = liquid;
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiquidStack getLiquid() {
|
||||
return this.liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLiquid(LiquidStack liquid) {
|
||||
this.liquid = liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCapacity(int capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(LiquidStack resource, boolean doFill) {
|
||||
if(resource == null || resource.itemID <= 0)
|
||||
return 0;
|
||||
|
||||
if(liquid == null || liquid.itemID <= 0) {
|
||||
if(resource.amount <= capacity) {
|
||||
if(doFill)
|
||||
this.liquid = resource.copy();
|
||||
return resource.amount;
|
||||
} else {
|
||||
if(doFill) {
|
||||
this.liquid = resource.copy();
|
||||
this.liquid.amount = capacity;
|
||||
}
|
||||
return capacity;
|
||||
}
|
||||
}
|
||||
|
||||
if(!liquid.isLiquidEqual(resource))
|
||||
return 0;
|
||||
|
||||
int space = capacity - liquid.amount;
|
||||
if(resource.amount <= space) {
|
||||
if(doFill)
|
||||
this.liquid.amount += resource.amount;
|
||||
return resource.amount;
|
||||
} else {
|
||||
|
||||
if(doFill)
|
||||
this.liquid.amount = capacity;
|
||||
return space;
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public LiquidStack drain(int maxDrain, boolean doDrain) {
|
||||
if(liquid == null || liquid.itemID <= 0)
|
||||
return null;
|
||||
if(liquid.amount <= 0)
|
||||
return null;
|
||||
|
||||
int used = maxDrain;
|
||||
if(liquid.amount < used)
|
||||
used = liquid.amount;
|
||||
|
||||
if(doDrain) {
|
||||
liquid.amount -= used;
|
||||
}
|
||||
|
||||
LiquidStack drained = new LiquidStack(liquid.itemID, used, liquid.itemMeta);
|
||||
|
||||
// Reset liquid if emptied
|
||||
if(liquid.amount <= 0)
|
||||
liquid = null;
|
||||
|
||||
return drained;
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@
|
||||
<variableList>
|
||||
<variable>
|
||||
<name>MCP_LOC</name>
|
||||
<value>$%7BPARENT-2-WORKSPACE_LOC%7D</value>
|
||||
<value>$%7BPARENT-3-PROJECT_LOC%7D</value>
|
||||
</variable>
|
||||
</variableList>
|
||||
</projectDescription>
|
||||
Reference in new issue
Block a user