Remove deprecated Fluid stuff

This commit is contained in:
mezz 2016-09-26 22:51:01 -07:00 committed by LexManos
parent bf8fa5d286
commit 6f1a44a405
16 changed files with 90 additions and 1847 deletions

View file

@ -47,13 +47,10 @@ import net.minecraftforge.common.model.IModelPart;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.IFluidContainerItem;
import net.minecraftforge.fluids.capability.IFluidHandler;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Function;

View file

@ -1,439 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fluids;
import java.util.Map;
import java.util.Set;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
/**
* Register simple items that contain fluids here. Useful for buckets, bottles, and things that have
* ID/metadata mappings.
*
* @deprecated This will be removed soon. Create an item like {@link net.minecraftforge.fluids.capability.ItemFluidContainer}
*/
@Deprecated
public abstract class FluidContainerRegistry
{
// Holder object that implements HashCode for an ItemStack,
// the local maps are not guaranteed to have the same internal generic structure,
// but the external interface for checking ItemStacks will still exist.
private static class ContainerKey
{
ItemStack container;
FluidStack fluid;
private ContainerKey(ItemStack container)
{
this.container = container;
}
private ContainerKey(ItemStack container, FluidStack fluid)
{
this(container);
this.fluid = fluid;
}
@Override
public int hashCode()
{
int code = 1;
code = 31*code + container.getItem().hashCode();
code = 31*code + container.getItemDamage();
if (fluid != null)
code = 31*code + fluid.getFluid().hashCode();
return code;
}
@Override
public boolean equals(Object o)
{
if (!(o instanceof ContainerKey)) return false;
ContainerKey ck = (ContainerKey)o;
if (container.getItem() != ck.container.getItem()) return false;
if (container.getItemDamage() != ck.container.getItemDamage()) return false;
if (!ItemStack.areItemStackTagsEqual(container, ck.container)) return false;
if (fluid == null && ck.fluid != null) return false;
if (fluid != null && ck.fluid == null) return false;
if (fluid == null && ck.fluid == null) return true;
if (fluid.getFluid() != ck.fluid.getFluid()) return false;
return true;
}
}
private static Map<ContainerKey, FluidContainerData> containerFluidMap = Maps.newHashMap();
private static Map<ContainerKey, FluidContainerData> filledContainerMap = Maps.newHashMap();
private static Set<ContainerKey> emptyContainers = Sets.newHashSet();
@Deprecated
public static final int BUCKET_VOLUME = Fluid.BUCKET_VOLUME;
@Deprecated
public static final ItemStack EMPTY_BUCKET = new ItemStack(Items.BUCKET);
@Deprecated
public static final ItemStack EMPTY_BOTTLE = new ItemStack(Items.GLASS_BOTTLE);
private static final ItemStack NULL_EMPTYCONTAINER = new ItemStack(Items.BUCKET);
static
{
registerFluidContainer(FluidRegistry.WATER, new ItemStack(Items.WATER_BUCKET), EMPTY_BUCKET);
registerFluidContainer(FluidRegistry.LAVA, new ItemStack(Items.LAVA_BUCKET), EMPTY_BUCKET);
registerFluidContainer(FluidRegistry.WATER, new ItemStack(Items.POTIONITEM), EMPTY_BOTTLE);
}
private FluidContainerRegistry(){}
/**
* Register a new fluid containing item.
*
* @param stack
* FluidStack containing the type and amount of the fluid stored in the item.
* @param filledContainer
* ItemStack representing the container when it is full.
* @param emptyContainer
* ItemStack representing the container when it is empty.
* @return True if container was successfully registered; false if it already is.
*/
public static boolean registerFluidContainer(FluidStack stack, ItemStack filledContainer, ItemStack emptyContainer)
{
return registerFluidContainer(new FluidContainerData(stack, filledContainer, emptyContainer));
}
/**
* Register a new fluid containing item. The item is assumed to hold 1000 mB of fluid. Also
* registers the Fluid if possible.
*
* @param fluid
* Fluid type that is stored in the item.
* @param filledContainer
* ItemStack representing the container when it is full.
* @param emptyContainer
* ItemStack representing the container when it is empty.
* @return True if container was successfully registered; false if it already is.
*/
public static boolean registerFluidContainer(Fluid fluid, ItemStack filledContainer, ItemStack emptyContainer)
{
if (!FluidRegistry.isFluidRegistered(fluid))
{
FluidRegistry.registerFluid(fluid);
}
return registerFluidContainer(new FluidStack(fluid, BUCKET_VOLUME), filledContainer, emptyContainer);
}
/**
* Register a new fluid containing item that does not have an empty container.
*
* @param stack
* FluidStack containing the type and amount of the fluid stored in the item.
* @param filledContainer
* ItemStack representing the container when it is full.
* @return True if container was successfully registered; false if it already is, or an invalid parameter was passed.
*/
public static boolean registerFluidContainer(FluidStack stack, ItemStack filledContainer)
{
return registerFluidContainer(new FluidContainerData(stack, filledContainer, null, true));
}
/**
* Register a new fluid containing item that does not have an empty container. The item is
* assumed to hold 1000 mB of fluid. Also registers the Fluid if possible.
*
* @param fluid
* Fluid type that is stored in the item.
* @param filledContainer
* ItemStack representing the container when it is full.
* @return True if container was successfully registered; false if it already is, or an invalid parameter was passed.
*/
public static boolean registerFluidContainer(Fluid fluid, ItemStack filledContainer)
{
if (!FluidRegistry.isFluidRegistered(fluid))
{
FluidRegistry.registerFluid(fluid);
}
return registerFluidContainer(new FluidStack(fluid, BUCKET_VOLUME), filledContainer);
}
/**
* Register a new fluid containing item.
*
* @param data
* See {@link FluidContainerData}.
* @return True if container was successfully registered; false if it already is, or an invalid parameter was passed.
*/
public static boolean registerFluidContainer(FluidContainerData data)
{
if (isFilledContainer(data.filledContainer) || data.filledContainer == null)
{
return false;
}
if (data.fluid == null || data.fluid.getFluid() == null)
{
FMLLog.bigWarning("Invalid registration attempt for a fluid container item %s has occurred. The registration has been denied to prevent crashes. The mod responsible for the registration needs to correct this.", data.filledContainer.getItem().getUnlocalizedName(data.filledContainer));
return false;
}
containerFluidMap.put(new ContainerKey(data.filledContainer), data);
if (data.emptyContainer != null && data.emptyContainer != NULL_EMPTYCONTAINER)
{
filledContainerMap.put(new ContainerKey(data.emptyContainer, data.fluid), data);
emptyContainers.add(new ContainerKey(data.emptyContainer));
}
MinecraftForge.EVENT_BUS.post(new FluidContainerRegisterEvent(data));
return true;
}
/**
* Determines the fluid type and amount inside a container.
*
* @param container
* The fluid container.
* @return FluidStack representing stored fluid.
*/
public static FluidStack getFluidForFilledItem(ItemStack container)
{
if (container == null)
{
return null;
}
FluidContainerData data = containerFluidMap.get(new ContainerKey(container));
return data == null ? null : data.fluid.copy();
}
/**
* Attempts to fill an empty container with a fluid.
*
* NOTE: Returns null on fail, NOT the empty container.
*
* @param fluid
* FluidStack containing the type and amount of fluid to fill.
* @param container
* ItemStack representing the empty container.
* @return Filled container if successful, otherwise null.
*/
public static ItemStack fillFluidContainer(FluidStack fluid, ItemStack container)
{
if (container == null || fluid == null)
{
return null;
}
FluidContainerData data = filledContainerMap.get(new ContainerKey(container, fluid));
if (data != null && fluid.amount >= data.fluid.amount)
{
return data.filledContainer.copy();
}
return null;
}
/**
* Attempts to empty a full container.
*
* @param container
* ItemStack representing the full container.
* @return Empty container if successful, otherwise null.
*/
public static ItemStack drainFluidContainer(ItemStack container)
{
if (container == null)
{
return null;
}
FluidContainerData data = containerFluidMap.get(new ContainerKey(container));
if (data != null)
{
return data.emptyContainer.copy();
}
return null;
}
/**
* Determines the capacity of a full container.
*
* @param container
* The full container.
* @return The containers capacity, or 0 if the ItemStack does not represent
* a registered container.
*/
public static int getContainerCapacity(ItemStack container)
{
return getContainerCapacity(null, container);
}
/**
* Determines the capacity of a container.
*
* @param fluid
* FluidStack containing the type of fluid the capacity should be
* determined for (ignored for full containers).
* @param container
* The container (full or empty).
* @return The containers capacity, or 0 if the ItemStack does not represent
* a registered container or the FluidStack is not registered with
* the empty container.
*/
public static int getContainerCapacity(FluidStack fluid, ItemStack container)
{
if (container == null)
{
return 0;
}
FluidContainerData data = containerFluidMap.get(new ContainerKey(container));
if (data != null)
{
return data.fluid.amount;
}
if (fluid != null)
{
data = filledContainerMap.get(new ContainerKey(container, fluid));
if (data != null)
{
return data.fluid.amount;
}
}
return 0;
}
/**
* Determines if a container holds a specific fluid.
*/
public static boolean containsFluid(ItemStack container, FluidStack fluid)
{
if (container == null || fluid == null)
{
return false;
}
FluidContainerData data = containerFluidMap.get(new ContainerKey(container));
return data == null ? false : data.fluid.containsFluid(fluid);
}
public static boolean isBucket(ItemStack container)
{
if (container == null)
{
return false;
}
if (container.isItemEqual(EMPTY_BUCKET))
{
return true;
}
FluidContainerData data = containerFluidMap.get(new ContainerKey(container));
return data != null && data.emptyContainer.isItemEqual(EMPTY_BUCKET);
}
public static boolean isContainer(ItemStack container)
{
return isEmptyContainer(container) || isFilledContainer(container);
}
public static boolean isEmptyContainer(ItemStack container)
{
return container != null && emptyContainers.contains(new ContainerKey(container));
}
public static boolean isFilledContainer(ItemStack container)
{
return container != null && getFluidForFilledItem(container) != null;
}
public static boolean hasNullEmptyContainer(ItemStack container)
{
if (container == null)
{
return false;
}
FluidContainerData data = containerFluidMap.get(new ContainerKey(container));
if (data != null)
{
return data.emptyContainer == NULL_EMPTYCONTAINER;
}
return false;
}
public static FluidContainerData[] getRegisteredFluidContainerData()
{
return containerFluidMap.values().toArray(new FluidContainerData[containerFluidMap.size()]);
}
/**
* Wrapper class for the registry entries. Ensures that none of the attempted registrations
* contain null references unless permitted.
*/
public static class FluidContainerData
{
public final FluidStack fluid;
public final ItemStack filledContainer;
public final ItemStack emptyContainer;
public FluidContainerData(FluidStack stack, ItemStack filledContainer, ItemStack emptyContainer)
{
this(stack, filledContainer, emptyContainer, false);
}
public FluidContainerData(FluidStack stack, ItemStack filledContainer, ItemStack emptyContainer, boolean nullEmpty)
{
this.fluid = stack;
this.filledContainer = filledContainer;
this.emptyContainer = emptyContainer == null ? NULL_EMPTYCONTAINER : emptyContainer;
if (stack == null || filledContainer == null || emptyContainer == null && !nullEmpty)
{
throw new RuntimeException("Invalid FluidContainerData - a parameter was null.");
}
}
public FluidContainerData copy()
{
return new FluidContainerData(fluid, filledContainer, emptyContainer, true);
}
}
public static class FluidContainerRegisterEvent extends Event
{
private final FluidContainerData data;
public FluidContainerRegisterEvent(FluidContainerData data)
{
this.data = data.copy();
}
public FluidContainerData getData()
{
return data;
}
}
}

View file

@ -209,28 +209,6 @@ public abstract class FluidRegistry
return fluids.get(fluidName);
}
@Deprecated // Modders should never actually use int ID, use String
public static Fluid getFluid(int fluidID)
{
return fluidIDs.inverse().get(fluidID);
}
@Deprecated // Modders should never actually use int ID, use String
public static int getFluidID(Fluid fluid)
{
Integer ret = fluidIDs.get(fluid);
if (ret == null) throw new RuntimeException("Attempted to access ID for unregistered fluid, Stop using this method modder!");
return ret;
}
@Deprecated // Modders should never actually use int ID, use String
public static int getFluidID(String fluidName)
{
Integer ret = fluidIDs.get(getFluid(fluidName));
if (ret == null) throw new RuntimeException("Attempted to access ID for unregistered fluid, Stop using this method modder!");
return ret;
}
public static String getFluidName(Fluid fluid)
{
return fluids.inverse().get(fluid);

View file

@ -27,12 +27,9 @@ import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
@ -41,13 +38,9 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.wrappers.BlockLiquidWrapper;
import net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper;
import net.minecraftforge.fluids.capability.wrappers.FluidContainerItemWrapper;
import net.minecraftforge.fluids.capability.wrappers.FluidContainerRegistryWrapper;
import net.minecraftforge.fluids.capability.wrappers.FluidHandlerWrapper;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
public class FluidUtil
{
@ -56,7 +49,7 @@ public class FluidUtil
}
/**
* Used to handle the common case of a fluid item right-clicking on a fluid handler.
* Used to handle the common case of a player holding a fluid item and right-clicking on a fluid handler.
* First it tries to fill the container item from the fluid handler,
* if that action fails then it tries to drain the container item into the fluid handler.
*
@ -341,27 +334,10 @@ public class FluidUtil
@Nullable
public static IFluidHandler getFluidHandler(ItemStack itemStack)
{
if (itemStack == null)
{
return null;
}
// check for capability
if (itemStack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null))
if (itemStack != null && itemStack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null))
{
return itemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
}
// legacy container handling
Item item = itemStack.getItem();
if (item instanceof IFluidContainerItem)
{
return new FluidContainerItemWrapper((IFluidContainerItem) item, itemStack);
}
else if (FluidContainerRegistry.isContainer(itemStack))
{
return new FluidContainerRegistryWrapper(itemStack);
}
else
{
return null;
@ -504,302 +480,4 @@ public class FluidUtil
}
return null;
}
/**
* Returns true if interaction was successful.
* @deprecated use {@link #interactWithFluidHandler(ItemStack, IFluidHandler, EntityPlayer)}
*/
@Deprecated
public static boolean interactWithTank(ItemStack stack, EntityPlayer player, net.minecraftforge.fluids.IFluidHandler tank, EnumFacing side)
{
IFluidHandler fluidHandler = new FluidHandlerWrapper(tank, side);
return interactWithFluidHandler(stack, fluidHandler, player);
}
/**
* @deprecated use {@link #tryFillContainer(ItemStack, IFluidHandler, int, EntityPlayer, boolean)}
*/
@Deprecated
public static ItemStack tryFillBucket(ItemStack bucket, net.minecraftforge.fluids.IFluidHandler tank, EnumFacing side)
{
return tryFillBucket(bucket, tank, side, null);
}
/**
* Fill an empty bucket from the given tank. Uses the FluidContainerRegistry.
*
* @param bucket The empty bucket. Will not be modified.
* @param tank The tank to fill the bucket from
* @param side Side to access the tank from
* @return The filled bucket or null if the liquid couldn't be taken from the tank.
* @deprecated use {@link #tryFillContainer(ItemStack, IFluidHandler, int, EntityPlayer, boolean)}
*/
@Deprecated
public static ItemStack tryFillBucket(ItemStack bucket, net.minecraftforge.fluids.IFluidHandler tank, EnumFacing side, EntityPlayer player)
{
IFluidHandler newFluidHandler = new FluidHandlerWrapper(tank, side);
return tryFillContainer(bucket, newFluidHandler, Fluid.BUCKET_VOLUME, player, true);
}
/**
* @deprecated use {@link #tryEmptyContainer(ItemStack, IFluidHandler, int, EntityPlayer, boolean)}
*/
@Deprecated
public static ItemStack tryEmptyBucket(ItemStack bucket, net.minecraftforge.fluids.IFluidHandler tank, EnumFacing side)
{
return tryEmptyBucket(bucket, tank, side, null);
}
/**
* Takes a filled bucket and tries to empty it into the given tank. Uses the FluidContainerRegistry.
*
* @param bucket The filled bucket
* @param tank The tank to fill with the bucket
* @param side Side to access the tank from
* @param player Player for making the bucket drained sound.
* @return The empty bucket if successful, null if the tank couldn't be filled.
* @deprecated use {@link #tryFillContainer(ItemStack, IFluidHandler, int, EntityPlayer, boolean)}
*/
@Deprecated
public static ItemStack tryEmptyBucket(ItemStack bucket, net.minecraftforge.fluids.IFluidHandler tank, EnumFacing side, EntityPlayer player)
{
IFluidHandler destination = new FluidHandlerWrapper(tank, side);
return tryEmptyContainer(bucket, destination, Fluid.BUCKET_VOLUME, player, true);
}
/**
* Takes an IFluidContainerItem and tries to fill it from the given tank.
*
* @param container The IFluidContainerItem Itemstack to fill. WILL BE MODIFIED!
* @param tank The tank to fill from
* @param side Side to access the tank from
* @param player The player that tries to fill the bucket. Needed if the input itemstack has a stacksize > 1 to determine where the filled container goes.
* @return True if the IFluidContainerItem was filled successfully, false otherwise. The passed container will have been modified to accommodate for anything done in this method. New Itemstacks might have been added to the players inventory.
* @deprecated use {@link #tryFillContainerAndStow(ItemStack, IFluidHandler, IItemHandler, int, EntityPlayer)}
*/
@Deprecated
public static boolean tryFillFluidContainerItem(ItemStack container, net.minecraftforge.fluids.IFluidHandler tank, EnumFacing side, EntityPlayer player)
{
return tryFillFluidContainerItem(container, tank, side, new PlayerMainInvWrapper(player.inventory), -1, player);
}
/**
* @deprecated use {@link #tryEmptyContainerAndStow(ItemStack, IFluidHandler, IItemHandler, int, EntityPlayer)}
*/
@Deprecated
public static boolean tryEmptyFluidContainerItem(ItemStack container, net.minecraftforge.fluids.IFluidHandler tank, EnumFacing side, EntityPlayer player)
{
return tryEmptyFluidContainerItem(container, tank, side, new PlayerMainInvWrapper(player.inventory), -1, player);
}
/**
* Takes an IFluidContainerItem and tries to fill it from the given tank.
* If the input itemstack has a stacksize >1 new itemstacks will be created and inserted into the given inventory.
* If the inventory does not accept it, it will be given to the player or dropped at the players feet.
* If player is null in this case, the action will be aborted.
* To support buckets that are not in the FluidContainerRegistry but implement IFluidContainerItem be sure to convert
* the empty bucket to your empty bucket variant before passing it to this function.
*
* @param container The IFluidContainerItem Itemstack to fill. WILL BE MODIFIED!
* @param tank The tank to fill from
* @param side Side to access the tank from
* @param inventory An inventory where any additionally created item (filled container if multiple empty are present) are put
* @param max Maximum amount to take from the tank. Uses IFluidContainerItem capacity if <= 0
* @param player The player that gets the items the inventory can't take. Can be null, only used if the inventory cannot take the filled stack.
* @return True if the IFluidContainerItem was filled successfully, false otherwise. The passed container will have been modified to accommodate for anything done in this method. New Itemstacks might have been added to the players inventory.
* @deprecated use {@link #tryFillContainerAndStow(ItemStack, IFluidHandler, IItemHandler, int, EntityPlayer)}
*/
@Deprecated
public static boolean tryFillFluidContainerItem(ItemStack container, net.minecraftforge.fluids.IFluidHandler tank, EnumFacing side, IItemHandler inventory, int max, @Nullable EntityPlayer player)
{
if (!(container.getItem() instanceof IFluidContainerItem))
{
// not a fluid container
return false;
}
IFluidContainerItem fluidContainer = (IFluidContainerItem) container.getItem();
if (fluidContainer.getFluid(container) != null)
{
// not empty
return false;
}
// if no maximum is given, fill fully
if (max <= 0)
{
max = fluidContainer.getCapacity(container);
}
// check how much liquid we can drain from the tank
FluidStack liquid = tank.drain(side, max, false);
if (liquid != null && liquid.amount > 0)
{
// check which itemstack shall be altered by the fill call
if (container.func_190916_E() > 1)
{
// create a copy of the container and fill it
ItemStack toFill = container.copy();
toFill.func_190920_e(1);
int filled = fluidContainer.fill(toFill, liquid, false);
if (filled > 0)
{
// This manipulates the container Itemstack!
filled = fluidContainer.fill(toFill, liquid, true);
}
else
{
// IFluidContainer does not accept the fluid/amount
return false;
}
if(player == null || !player.worldObj.isRemote)
{
// check if we can give the itemstack to the inventory
ItemStack remainder = ItemHandlerHelper.insertItemStacked(inventory, toFill, true);
if (remainder != null && player == null)
{
// couldn't add to the inventory and don't have a player to drop the item at
return false;
}
remainder = ItemHandlerHelper.insertItemStacked(inventory, toFill, false);
// give it to the player or drop it at his feet
if (remainder != null && player != null)
{
ItemHandlerHelper.giveItemToPlayer(player, remainder);
}
}
// the result has been given to the player, drain the tank since everything is ok
tank.drain(side, filled, true);
// decrease its stacksize to accommodate the filled one (it was >1 from the check above)
container.func_190918_g(1);
}
// just 1 empty container to fill, no special treatment needed
else
{
int filled = fluidContainer.fill(container, liquid, false);
if (filled > 0)
{
// This manipulates the container Itemstack!
filled = fluidContainer.fill(container, liquid, true);
}
else
{
// IFluidContainer does not accept the fluid/amount
return false;
}
tank.drain(side, filled, true);
}
// play sound
if(player != null)
{
SoundEvent soundevent = liquid.getFluid().getFillSound(liquid);
player.playSound(soundevent, 1f, 1f);
}
return true;
}
return false;
}
/**
* Takes an IFluidContainerItem and tries to empty it into the given tank.
* If the input itemstack has a stacksize >1 new itemstacks will be created and inserted into the given inventory.
* If the inventory does not accept it, it will be given to the player or dropped at the players feet.
* If player is null in this case, the action will be aborted.
*
* @param container The IFluidContainerItem Itemstack to empty. WILL BE MODIFIED!
* @param tank The tank to fill
* @param side Side to access the tank from
* @param inventory An inventory where any additionally created item (filled container if multiple empty are present) are put
* @param max Maximum amount to take from the tank. Uses IFluidContainerItem capacity if <= 0
* @param player The player that gets the items the inventory can't take. Can be null, only used if the inventory cannot take the emptied stack.
* @return True if the container successfully emptied at least 1 mb into the tank, false otherwise. The passed container itemstack will be modified to accommodate for the liquid transaction.
* @deprecated use {@link #tryEmptyContainerAndStow(ItemStack, IFluidHandler, IItemHandler, int, EntityPlayer)}
*/
@Deprecated
public static boolean tryEmptyFluidContainerItem(ItemStack container, net.minecraftforge.fluids.IFluidHandler tank, EnumFacing side, IItemHandler inventory, int max, EntityPlayer player)
{
if (!(container.getItem() instanceof IFluidContainerItem))
{
// not a fluid container
return false;
}
IFluidContainerItem fluidContainer = (IFluidContainerItem) container.getItem();
if (fluidContainer.getFluid(container) != null)
{
// drain out of the fluidcontainer
if (max <= 0)
{
max = fluidContainer.getCapacity(container);
}
FluidStack drained = fluidContainer.drain(container, max, false);
if (drained != null && tank.canFill(side, drained.getFluid()))
{
// check how much we can fill into the tank
int filled = tank.fill(side, drained, false);
if (filled > 0)
{
// verify that the new amount can also be drained (buckets can only extract full amounts for example)
drained = fluidContainer.drain(container, filled, false);
// actually transfer the liquid if everything went well
if (drained != null && drained.amount == filled)
{
// more than 1 filled itemstack, ensure that we can insert the changed container
if (container.func_190916_E() > 1)
{
// create a copy of the container and drain it
ItemStack toEmpty = container.copy();
toEmpty.func_190920_e(1);
drained = fluidContainer.drain(toEmpty, filled, true); // modifies the container!
if(player == null || !player.worldObj.isRemote)
{
// try adding the drained container to the inventory
ItemStack remainder = ItemHandlerHelper.insertItemStacked(inventory, toEmpty, true);
if (remainder != null && player == null)
{
// couldn't add to the inventory and don't have a player to drop the item at
return false;
}
remainder = ItemHandlerHelper.insertItemStacked(inventory, toEmpty, false);
// give it to the player or drop it at his feet
if (remainder != null && player != null)
{
ItemHandlerHelper.giveItemToPlayer(player, remainder);
}
}
// the result has been given to the player, fill the tank since everything is ok
tank.fill(side, drained, true);
// decrease its stacksize to accommodate the filled one (it was >1 from the check above)
container.func_190918_g(1);
}
// itemstack of size 1, no special treatment needed
else
{
// This manipulates the container Itemstack!
drained = fluidContainer.drain(container, filled, true); // modifies the container!
tank.fill(side, drained, true);
}
// play sound
if(player != null)
{
SoundEvent soundevent = drained.getFluid().getEmptySound(drained);
player.playSound(soundevent, 1f, 1f);
}
return true;
}
}
}
}
return false;
}
}

View file

@ -1,80 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fluids;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.capability.wrappers.FluidContainerItemWrapper;
/**
* Implement this interface on Item classes that support external manipulation of their internal
* fluid storage.
*
* A reference implementation is provided {@link ItemFluidContainer}.
*
* NOTE: Use of NBT data on the containing ItemStack is encouraged.
*
* @deprecated See {@link net.minecraftforge.fluids.capability.ItemFluidContainer} for a CapabilityProvider implementing the Capability {@link net.minecraftforge.fluids.capability.IFluidHandler}
* @see FluidContainerItemWrapper
*/
@Deprecated
public interface IFluidContainerItem
{
/**
*
* @param container
* ItemStack which is the fluid container.
* @return FluidStack representing the fluid in the container, null if the container is empty.
*/
FluidStack getFluid(ItemStack container);
/**
*
* @param container
* ItemStack which is the fluid container.
* @return Capacity of this fluid container.
*/
int getCapacity(ItemStack container);
/**
*
* @param container
* ItemStack which is the fluid container.
* @param resource
* FluidStack attempting to fill the container.
* @param doFill
* If false, the fill will only be simulated.
* @return Amount of fluid that was (or would have been, if simulated) filled into the
* container.
*/
int fill(ItemStack container, FluidStack resource, boolean doFill);
/**
*
* @param container
* ItemStack which is the fluid container.
* @param maxDrain
* Maximum amount of fluid to be removed from the container.
* @param doDrain
* If false, the drain will only be simulated.
* @return Amount of fluid that was (or would have been, if simulated) drained from the
* container.
*/
FluidStack drain(ItemStack container, int maxDrain, boolean doDrain);
}

View file

@ -1,103 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fluids;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.capability.wrappers.FluidHandlerWrapper;
/**
* Implement this interface on TileEntities which should handle fluids, generally storing them in
* one or more internal {@link IFluidTank} objects.
*
* A reference implementation is provided {@link TileFluidHandler}.
*
* @deprecated Use the Capability version {@link net.minecraftforge.fluids.capability.IFluidHandler}.
* @see FluidHandlerWrapper
*/
@Deprecated
public interface IFluidHandler
{
/**
* Fills fluid into internal tanks, distribution is left entirely to the IFluidHandler.
*
* @param from
* Orientation the Fluid is pumped in from.
* @param resource
* FluidStack representing the Fluid and maximum amount of fluid to be filled.
* @param doFill
* If false, fill will only be simulated.
* @return Amount of resource that was (or would have been, if simulated) filled.
*/
int fill(EnumFacing from, FluidStack resource, boolean doFill);
/**
* Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.
*
* @param from
* Orientation the Fluid is drained to.
* @param resource
* FluidStack representing the Fluid and maximum amount of fluid to be drained.
* @param doDrain
* If false, drain will only be simulated.
* @return FluidStack representing the Fluid and amount that was (or would have been, if
* simulated) drained.
*/
FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain);
/**
* Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.
*
* This method is not Fluid-sensitive.
*
* @param from
* Orientation the fluid is drained to.
* @param maxDrain
* Maximum amount of fluid to drain.
* @param doDrain
* If false, drain will only be simulated.
* @return FluidStack representing the Fluid and amount that was (or would have been, if
* simulated) drained.
*/
FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain);
/**
* Returns true if the given fluid can be inserted into the given direction.
*
* More formally, this should return true if fluid is able to enter from the given direction.
*/
boolean canFill(EnumFacing from, Fluid fluid);
/**
* Returns true if the given fluid can be extracted from the given direction.
*
* More formally, this should return true if fluid is able to leave from the given direction.
*/
boolean canDrain(EnumFacing from, Fluid fluid);
/**
* Returns an array of objects which represent the internal tanks. These objects cannot be used
* to manipulate the internal tanks. See {@link FluidTankInfo}.
*
* @param from
* Orientation determining which tanks should be queried.
* @return Info for the relevant internal tanks.
*/
FluidTankInfo[] getTankInfo(EnumFacing from);
}

View file

@ -1,185 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fluids;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.capability.wrappers.FluidContainerItemWrapper;
/**
* Reference implementation of {@link IFluidContainerItem}. Use/extend this or implement your own.
* @deprecated See {@link net.minecraftforge.fluids.capability.ItemFluidContainer}
*/
@Deprecated
public class ItemFluidContainer extends Item implements IFluidContainerItem
{
protected int capacity;
public ItemFluidContainer(int itemID)
{
super();
}
public ItemFluidContainer(int itemID, int capacity)
{
super();
this.capacity = capacity;
}
public ItemFluidContainer setCapacity(int capacity)
{
this.capacity = capacity;
return this;
}
/* IFluidContainerItem */
@Override
public FluidStack getFluid(ItemStack container)
{
if (!container.hasTagCompound() || !container.getTagCompound().hasKey("Fluid"))
{
return null;
}
return FluidStack.loadFluidStackFromNBT(container.getTagCompound().getCompoundTag("Fluid"));
}
@Override
public int getCapacity(ItemStack container)
{
return capacity;
}
@Override
public int fill(ItemStack container, FluidStack resource, boolean doFill)
{
if (resource == null)
{
return 0;
}
if (!doFill)
{
if (!container.hasTagCompound() || !container.getTagCompound().hasKey("Fluid"))
{
return Math.min(capacity, resource.amount);
}
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.getTagCompound().getCompoundTag("Fluid"));
if (stack == null)
{
return Math.min(capacity, resource.amount);
}
if (!stack.isFluidEqual(resource))
{
return 0;
}
return Math.min(capacity - stack.amount, resource.amount);
}
if (!container.hasTagCompound())
{
container.setTagCompound(new NBTTagCompound());
}
if (!container.getTagCompound().hasKey("Fluid"))
{
NBTTagCompound fluidTag = resource.writeToNBT(new NBTTagCompound());
if (capacity < resource.amount)
{
fluidTag.setInteger("Amount", capacity);
container.getTagCompound().setTag("Fluid", fluidTag);
return capacity;
}
container.getTagCompound().setTag("Fluid", fluidTag);
return resource.amount;
}
NBTTagCompound fluidTag = container.getTagCompound().getCompoundTag("Fluid");
FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidTag);
if (!stack.isFluidEqual(resource))
{
return 0;
}
int filled = capacity - stack.amount;
if (resource.amount < filled)
{
stack.amount += resource.amount;
filled = resource.amount;
}
else
{
stack.amount = capacity;
}
container.getTagCompound().setTag("Fluid", stack.writeToNBT(fluidTag));
return filled;
}
@Override
public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain)
{
if (!container.hasTagCompound() || !container.getTagCompound().hasKey("Fluid"))
{
return null;
}
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.getTagCompound().getCompoundTag("Fluid"));
if (stack == null)
{
return null;
}
int currentAmount = stack.amount;
stack.amount = Math.min(stack.amount, maxDrain);
if (doDrain)
{
if (currentAmount == stack.amount)
{
container.getTagCompound().removeTag("Fluid");
if (container.getTagCompound().hasNoTags())
{
container.setTagCompound(null);
}
return stack;
}
NBTTagCompound fluidTag = container.getTagCompound().getCompoundTag("Fluid");
fluidTag.setInteger("Amount", currentAmount - stack.amount);
container.getTagCompound().setTag("Fluid", fluidTag);
}
return stack;
}
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt)
{
return new FluidContainerItemWrapper(this, stack);
}
}

View file

@ -1,112 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fluids;
import javax.annotation.Nullable;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.wrappers.FluidHandlerWrapper;
/**
* Reference Tile Entity implementation of {@link IFluidHandler}. Use/extend this or write your own.
* @deprecated see {@link net.minecraftforge.fluids.capability.TileFluidHandler}
*/
@Deprecated
public class TileFluidHandler extends TileEntity implements IFluidHandler
{
protected FluidTank tank = new FluidTank(Fluid.BUCKET_VOLUME);
@Override
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT(tag);
tank.readFromNBT(tag);
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tag)
{
tag = super.writeToNBT(tag);
tank.writeToNBT(tag);
return tag;
}
/* IFluidHandler */
@Override
public int fill(EnumFacing from, FluidStack resource, boolean doFill)
{
return tank.fill(resource, doFill);
}
@Override
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain)
{
if (resource == null || !resource.isFluidEqual(tank.getFluid()))
{
return null;
}
return tank.drain(resource.amount, doDrain);
}
@Override
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain)
{
return tank.drain(maxDrain, doDrain);
}
@Override
public boolean canFill(EnumFacing from, Fluid fluid)
{
return true;
}
@Override
public boolean canDrain(EnumFacing from, Fluid fluid)
{
return true;
}
@Override
public FluidTankInfo[] getTankInfo(EnumFacing from)
{
return new FluidTankInfo[] { tank.getInfo() };
}
@Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing)
{
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
}
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing)
{
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
{
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(new FluidHandlerWrapper(this, facing));
}
return super.getCapability(capability, facing);
}
}

View file

@ -19,9 +19,7 @@
package net.minecraftforge.fluids;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDispenser;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
@ -29,13 +27,17 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.stats.StatList;
import net.minecraft.util.*;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.event.entity.player.FillBucketEvent;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.wrappers.FluidBucketWrapper;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
@ -44,12 +46,10 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.ItemHandlerHelper;
import java.util.List;
/**
* A universal bucket that can hold any liquid
*/
public class UniversalBucket extends Item implements IFluidContainerItem
public class UniversalBucket extends Item
{
private final int capacity; // how much the bucket holds
@ -107,7 +107,8 @@ public class UniversalBucket extends Item implements IFluidContainerItem
// add all fluids that the bucket can be filled with
FluidStack fs = new FluidStack(fluid, getCapacity());
ItemStack stack = new ItemStack(this);
if (fill(stack, fs, true) == fs.amount)
IFluidHandler fluidHandler = new FluidBucketWrapper(stack);
if (fluidHandler.fill(fs, true) == fs.amount)
{
subItems.add(stack);
}
@ -196,26 +197,6 @@ public class UniversalBucket extends Item implements IFluidContainerItem
return ActionResult.newResult(EnumActionResult.FAIL, itemstack);
}
// compatibility
@Deprecated
public boolean tryPlaceFluid(Block block, World worldIn, BlockPos pos)
{
if (block instanceof IFluidBlock)
{
IFluidBlock fluidBlock = (IFluidBlock) block;
return FluidUtil.tryPlaceFluid(null, worldIn, new FluidStack(fluidBlock.getFluid(), Fluid.BUCKET_VOLUME), pos);
}
else if (block.getDefaultState().getMaterial() == Material.WATER)
{
FluidUtil.tryPlaceFluid(null, worldIn, new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME), pos);
}
else if (block.getDefaultState().getMaterial() == Material.LAVA)
{
FluidUtil.tryPlaceFluid(null, worldIn, new FluidStack(FluidRegistry.LAVA, Fluid.BUCKET_VOLUME), pos);
}
return false;
}
@SubscribeEvent(priority = EventPriority.LOW) // low priority so other mods can handle their stuff first
public void onFillBucket(FillBucketEvent event)
{
@ -263,112 +244,33 @@ public class UniversalBucket extends Item implements IFluidContainerItem
public static ItemStack getFilledBucket(UniversalBucket item, Fluid fluid)
{
ItemStack stack = new ItemStack(item);
item.fill(stack, new FluidStack(fluid, item.getCapacity()), true);
return stack;
ItemStack bucket = new ItemStack(item);
if (FluidRegistry.getBucketFluids().contains(fluid))
{
// fill the container
NBTTagCompound tag = new NBTTagCompound();
FluidStack fluidStack = new FluidStack(fluid, item.getCapacity());
fluidStack.writeToNBT(tag);
bucket.setTagCompound(tag);
}
else if (fluid == FluidRegistry.WATER)
{
bucket.deserializeNBT(new ItemStack(Items.WATER_BUCKET).serializeNBT());
}
else if (fluid == FluidRegistry.LAVA)
{
bucket.deserializeNBT(new ItemStack(Items.LAVA_BUCKET).serializeNBT());
}
return bucket;
}
/* FluidContainer Management */
@Override
public FluidStack getFluid(ItemStack container)
{
return FluidStack.loadFluidStackFromNBT(container.getTagCompound());
}
@Override
public int getCapacity(ItemStack container)
{
return getCapacity();
}
@Override
public int fill(ItemStack container, FluidStack resource, boolean doFill)
{
// has to be exactly 1, must be handled from the caller
if (container.func_190916_E() != 1)
{
return 0;
}
// can only fill exact capacity
if (resource == null || resource.amount < getCapacity())
{
return 0;
}
// already contains fluid?
if (getFluid(container) != null)
{
return 0;
}
// registered in the registry?
if (FluidRegistry.getBucketFluids().contains(resource.getFluid()))
{
// fill the container
if (doFill)
{
NBTTagCompound tag = container.getTagCompound();
if (tag == null)
{
tag = new NBTTagCompound();
}
resource.writeToNBT(tag);
container.setTagCompound(tag);
}
return getCapacity();
}
else if (resource.getFluid() == FluidRegistry.WATER)
{
if (doFill)
{
container.deserializeNBT(new ItemStack(Items.WATER_BUCKET).serializeNBT());
}
return getCapacity();
}
else if (resource.getFluid() == FluidRegistry.LAVA)
{
if (doFill)
{
container.deserializeNBT(new ItemStack(Items.LAVA_BUCKET).serializeNBT());
}
return getCapacity();
}
return 0;
}
@Override
public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain)
{
// has to be exactly 1, must be handled from the caller
if (container.func_190916_E() != 1)
{
return null;
}
// can only drain everything at once
if (maxDrain < getCapacity(container))
{
return null;
}
FluidStack fluidStack = getFluid(container);
if (doDrain && fluidStack != null)
{
if(getEmpty() != null)
{
container.deserializeNBT(getEmpty().serializeNBT());
}
else {
container.func_190920_e(0);
}
}
return fluidStack;
}
public int getCapacity()
{
return capacity;

View file

@ -23,12 +23,10 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.IFluidContainerItem;
import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack;
/**
* A simple fluid container, to replace the functionality of {@link FluidContainerRegistry) and {@link IFluidContainerItem}.
* A simple fluid container, to replace the functionality of the old FluidContainerRegistry and IFluidContainerItem.
* This fluid container may be set so that is can only completely filled or empty. (binary)
* It may also be set so that it gets consumed when it is drained. (consumable)
*/

View file

@ -34,7 +34,7 @@ import net.minecraftforge.fluids.capability.IFluidTankProperties;
/**
* FluidHandlerItemStack is a template capability provider for ItemStacks.
* Data is stored directly in the vanilla NBT, in the same way as the old deprecated {@link ItemFluidContainer}.
* Data is stored directly in the vanilla NBT, in the same way as the old ItemFluidContainer.
*
* This class allows an itemStack to contain any partial level of fluid up to its capacity, unlike {@link FluidHandlerItemStackSimple}
*

View file

@ -29,7 +29,6 @@ import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.FluidTankProperties;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import net.minecraftforge.fluids.ItemFluidContainer;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;

View file

@ -1,109 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fluids.capability.wrappers;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.FluidTankProperties;
import net.minecraftforge.fluids.IFluidContainerItem;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
/**
* FluidContainerItemWrapper converts an old {@link IFluidContainerItem} to IFluidHandler.
* Note that successful operations WILL modify the container itemStack.
* @deprecated will be removed along with {@link IFluidContainerItem}
*/
@Deprecated
public class FluidContainerItemWrapper implements IFluidHandler, ICapabilityProvider
{
protected final IFluidContainerItem handler;
protected final ItemStack container;
public FluidContainerItemWrapper(IFluidContainerItem handler, ItemStack container)
{
this.handler = handler;
this.container = container;
}
@Override
public FluidTankProperties[] getTankProperties()
{
return new FluidTankProperties[] { new FluidTankProperties(handler.getFluid(container), handler.getCapacity(container)) };
}
@Override
public int fill(FluidStack resource, boolean doFill)
{
if (container.func_190916_E() != 1)
{
return 0;
}
return handler.fill(container, resource, doFill);
}
@Override
public FluidStack drain(FluidStack resource, boolean doDrain)
{
if (container.func_190916_E() != 1 || resource == null)
{
return null;
}
FluidStack canDrain = drain(resource.amount, false);
if (canDrain != null)
{
if (canDrain.isFluidEqual(resource))
{
return drain(resource.amount, doDrain);
}
}
return null;
}
@Override
public FluidStack drain(int maxDrain, boolean doDrain)
{
if (container.func_190916_E() != 1)
{
return null;
}
return handler.drain(container, maxDrain, doDrain);
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing)
{
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
{
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(this);
}
return null;
}
}

View file

@ -1,152 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fluids.capability.wrappers;
import javax.annotation.Nullable;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.FluidTankProperties;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
/**
* Wraps a liquid container that uses the {@link FluidContainerRegistry}
* Note that successful operations WILL modify the container itemStack.
* @deprecated will be removed along with {@link FluidContainerRegistry}
*/
@Deprecated
public class FluidContainerRegistryWrapper implements IFluidHandler, ICapabilityProvider
{
protected final ItemStack container;
public FluidContainerRegistryWrapper(ItemStack container)
{
this.container = container;
}
@Override
public IFluidTankProperties[] getTankProperties()
{
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(container);
int capacity = FluidContainerRegistry.getContainerCapacity(fluid, container);
return new FluidTankProperties[] { new FluidTankProperties(fluid, capacity) };
}
@Override
public int fill(FluidStack resource, boolean doFill)
{
if (container.func_190916_E() != 1 || resource == null)
{
return 0;
}
FluidStack originalContained = FluidContainerRegistry.getFluidForFilledItem(container);
ItemStack result = FluidContainerRegistry.fillFluidContainer(resource, container);
if (result == null)
{
return 0;
}
if (doFill)
{
container.deserializeNBT(result.serializeNBT());
}
FluidStack newContained = FluidContainerRegistry.getFluidForFilledItem(result);
int originalAmount = originalContained == null ? 0 : originalContained.amount;
int newAmount = newContained == null ? 0 : newContained.amount;
return newAmount - originalAmount;
}
@Nullable
@Override
public FluidStack drain(FluidStack resource, boolean doDrain)
{
if (container.func_190916_E() != 1 || resource == null)
{
return null;
}
FluidStack contained = FluidContainerRegistry.getFluidForFilledItem(container);
if (contained != null && contained.isFluidEqual(resource))
{
return drain(resource.amount, doDrain);
}
return null;
}
@Nullable
@Override
public FluidStack drain(int maxDrain, boolean doDrain)
{
if (container.func_190916_E() != 1)
{
return null;
}
FluidStack contained = FluidContainerRegistry.getFluidForFilledItem(container);
if (contained != null)
{
if (contained.amount <= maxDrain)
{
ItemStack emptyContainer = FluidContainerRegistry.drainFluidContainer(container);
if (emptyContainer != null)
{
if (doDrain)
{
if (FluidContainerRegistry.hasNullEmptyContainer(container))
{
emptyContainer.func_190920_e(0);
}
container.deserializeNBT(emptyContainer.serializeNBT());
}
return contained;
}
}
}
return null;
}
@Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing)
{
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
}
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing)
{
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
{
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(this);
}
return null;
}
}

View file

@ -1,71 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fluids.capability.wrappers;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.FluidTankProperties;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import net.minecraftforge.fluids.capability.IFluidHandler;
/**
* FluidHandlerWrapper automatically converts the old {@link net.minecraftforge.fluids.IFluidHandler} to the new version.
* @deprecated will be removed along with {@link net.minecraftforge.fluids.IFluidHandler}
*/
@Deprecated
public class FluidHandlerWrapper implements IFluidHandler
{
protected final net.minecraftforge.fluids.IFluidHandler handler;
protected final EnumFacing side;
public FluidHandlerWrapper(net.minecraftforge.fluids.IFluidHandler handler, EnumFacing side)
{
this.handler = handler;
this.side = side;
}
@Override
public IFluidTankProperties[] getTankProperties()
{
return FluidTankProperties.convert(handler.getTankInfo(side));
}
@Override
public int fill(FluidStack resource, boolean doFill)
{
if (resource == null || !handler.canFill(side, resource.getFluid()))
return 0;
return handler.fill(side, resource, doFill);
}
@Override
public FluidStack drain(FluidStack resource, boolean doDrain)
{
if (resource == null || !handler.canDrain(side, resource.getFluid()))
return null;
return handler.drain(side, resource, doDrain);
}
@Override
public FluidStack drain(int maxDrain, boolean doDrain)
{
return handler.drain(side, maxDrain, doDrain);
}
}

View file

@ -1,5 +1,7 @@
package net.minecraftforge.debug;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
@ -16,7 +18,6 @@ import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
@ -24,16 +25,29 @@ import net.minecraft.util.EnumActionResult;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.ForgeModContainer;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.debug.ModelFluidDebug.TestFluid;
import net.minecraftforge.debug.ModelFluidDebug.TestGas;
import net.minecraftforge.event.entity.player.FillBucketEvent;
import net.minecraftforge.fluids.*;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fluids.UniversalBucket;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
@ -45,8 +59,6 @@ import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import java.util.List;
@Mod(modid = DynBucketTest.MODID, name = "DynBucketTest", version = "0.1", dependencies = "after:" + ModelFluidDebug.MODID)
public class DynBucketTest
{
@ -60,7 +72,7 @@ public class DynBucketTest
static
{
if (ENABLE)
if (ENABLE && ModelFluidDebug.ENABLE)
{
FluidRegistry.enableUniversalBucket();
}
@ -85,7 +97,7 @@ public class DynBucketTest
@Override
void setupModels()
{
if (!ENABLE)
if (!ENABLE || !ModelFluidDebug.ENABLE)
return;
ModelLoader.setBucketModelDefinition(dynBucket);
@ -109,7 +121,7 @@ public class DynBucketTest
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
if (!ENABLE)
if (!ENABLE || !ModelFluidDebug.ENABLE)
return;
GameRegistry.register(new TestItem(), testItemName);
@ -123,51 +135,13 @@ public class DynBucketTest
//GameRegistry.registerItem(dynBucket, "dynbucket");
GameRegistry.register(dynBottle);
GameRegistry.addShapelessRecipe(new ItemStack(Items.DIAMOND),
UniversalBucket.getFilledBucket(ForgeModContainer.getInstance().universalBucket, TestFluid.instance));
// register fluid containers
int i = 0;
//registerFluidContainer(FluidRegistry.WATER, i++);
//registerFluidContainer(FluidRegistry.LAVA, i++);
//registerFluidContainer(FluidRegistry.getFluid(TestFluid.name), i++);
//registerFluidContainer(FluidRegistry.getFluid(TestGas.name), i++);
i = 0;
//registerFluidContainer2(FluidRegistry.WATER, i++);
//registerFluidContainer2(FluidRegistry.LAVA, i++);
//registerFluidContainer2(FluidRegistry.getFluid(TestFluid.name), i++);
//registerFluidContainer2(FluidRegistry.getFluid(TestGas.name), i++);
// Set TestFluidBlocks blockstate to use milk instead of testfluid for the texture to be loaded
FluidContainerRegistry.registerFluidContainer(FluidRegistry.getFluid("milk"), new ItemStack(Items.MILK_BUCKET), FluidContainerRegistry.EMPTY_BUCKET);
ItemStack filledBucket = UniversalBucket.getFilledBucket(ForgeModContainer.getInstance().universalBucket, TestFluid.instance);
GameRegistry.addShapelessRecipe(new ItemStack(Items.DIAMOND), filledBucket);
proxy.setupModels();
//MinecraftForge.EVENT_BUS.register(this);
}
@SuppressWarnings("unused")
private void registerFluidContainer(Fluid fluid, int meta)
{
if (fluid == null)
return;
FluidStack fs = new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME);
ItemStack stack = new ItemStack(dynBucket, 1, meta);
FluidContainerRegistry.registerFluidContainer(fs, stack, new ItemStack(Items.BUCKET));
}
@SuppressWarnings("unused")
private void registerFluidContainer2(Fluid fluid, int meta)
{
if (fluid == null)
return;
FluidStack fs = new FluidStack(fluid, 250);
ItemStack stack = new ItemStack(dynBottle, 1, meta);
FluidContainerRegistry.registerFluidContainer(fs, stack, new ItemStack(Items.GLASS_BOTTLE));
}
@SubscribeEvent
public void onBucketFill(FillBucketEvent event)
{
@ -175,13 +149,18 @@ public class DynBucketTest
if (state.getBlock() instanceof IFluidBlock)
{
Fluid fluid = ((IFluidBlock) state.getBlock()).getFluid();
FluidStack fs = new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME);
FluidStack fs = new FluidStack(fluid, Fluid.BUCKET_VOLUME);
ItemStack filled = FluidContainerRegistry.fillFluidContainer(fs, event.getEmptyBucket());
if (filled != null)
ItemStack bucket = event.getEmptyBucket();
IFluidHandler fluidHandler = FluidUtil.getFluidHandler(bucket);
if (fluidHandler != null)
{
event.setFilledBucket(filled);
event.setResult(Result.ALLOW);
int fillAmount = fluidHandler.fill(fs, true);
if (fillAmount > 0)
{
event.setFilledBucket(bucket);
event.setResult(Result.ALLOW);
}
}
}
}
@ -242,7 +221,7 @@ public class DynBucketTest
for (int i = 0; i < 4; i++)
{
ItemStack bucket = new ItemStack(this, 1, i);
if (FluidContainerRegistry.isFilledContainer(bucket))
if (FluidUtil.getFluidContained(bucket) != null)
subItems.add(bucket);
}
}
@ -281,42 +260,37 @@ public class DynBucketTest
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
ItemStack heldItem = playerIn.getHeldItem(hand);
TileEntity te = worldIn.getTileEntity(pos);
if (!(te instanceof IFluidHandler))
{
return false;
}
IFluidHandler tank = (IFluidHandler) te;
side = side.getOpposite();
IFluidHandler tank = FluidUtil.getFluidHandler(worldIn, pos, side.getOpposite());
if (null == null)
{
sendText(playerIn, tank, side);
sendText(playerIn, tank);
return false;
}
// do the thing with the tank and the buckets
if (FluidUtil.interactWithTank(heldItem, playerIn, tank, side))
if (FluidUtil.interactWithFluidHandler(heldItem, tank, playerIn))
{
return true;
}
else
{
sendText(playerIn, tank, side);
sendText(playerIn, tank);
}
// prevent interaction of the item if it's a fluidcontainer. Prevents placing liquids when interacting with the tank
return FluidContainerRegistry.isFilledContainer(heldItem) || heldItem.getItem() instanceof IFluidContainerItem;
return FluidUtil.getFluidHandler(heldItem) != null;
}
private void sendText(EntityPlayer player, IFluidHandler tank, EnumFacing side)
private void sendText(EntityPlayer player, IFluidHandler tank)
{
if (player.worldObj.isRemote)
{
String text;
if (tank.getTankInfo(side).length > 0 && tank.getTankInfo(side)[0] != null && tank.getTankInfo(side)[0].fluid != null)
IFluidTankProperties[] tankProperties = tank.getTankProperties();
if (tankProperties.length > 0 && tankProperties[0] != null && tankProperties[0].getContents() != null)
{
text = tank.getTankInfo(side)[0].fluid.amount + "x " + tank.getTankInfo(side)[0].fluid.getLocalizedName();
text = tankProperties[0].getContents().amount + "x " + tankProperties[0].getContents().getLocalizedName();
} else
{
text = "empty";
@ -326,58 +300,10 @@ public class DynBucketTest
}
}
public static class TileSimpleTank extends TileEntity implements IFluidHandler
public static class TileSimpleTank extends TileEntity
{
FluidTank tank = new FluidTank(4000);
@Override
public int fill(EnumFacing from, FluidStack resource, boolean doFill)
{
int filled = tank.fill(resource, doFill);
if(doFill && filled > 0) {
IBlockState state = worldObj.getBlockState(pos);
worldObj.notifyBlockUpdate(pos, state, state, 8); // TODO check flag
}
return filled;
}
@Override
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain)
{
// not used in this test
return null;
}
@Override
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain)
{
FluidStack drained = tank.drain(maxDrain, doDrain);
if(doDrain && drained != null) {
IBlockState state = worldObj.getBlockState(pos);
worldObj.notifyBlockUpdate(pos, state, state, 8); // TODO check flag
}
return drained;
}
@Override
public boolean canFill(EnumFacing from, Fluid fluid)
{
return tank.getFluidAmount() == 0 ||
(tank.getFluid().getFluid() == fluid && tank.getFluidAmount() < tank.getCapacity());
}
@Override
public boolean canDrain(EnumFacing from, Fluid fluid)
{
return tank.getFluidAmount() > 0;
}
@Override
public FluidTankInfo[] getTankInfo(EnumFacing from)
{
return new FluidTankInfo[]{new FluidTankInfo(tank)};
}
@Override
public void readFromNBT(NBTTagCompound tags)
{
@ -405,5 +331,21 @@ public class DynBucketTest
super.onDataPacket(net, pkt);
readFromNBT(pkt.getNbtCompound());
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing)
{
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
{
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tank);
}
return super.getCapability(capability, facing);
}
}
}