Java 类net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack 实例源码

项目:customstuff4    文件:ItemFluidContainer.java   
@SideOnly(Side.CLIENT)
@Override
public void getSubItems(@Nullable CreativeTabs tab, @Nonnull NonNullList<ItemStack> subItems)
{
    if (isInCreativeTab(tab))
    {
        subItems.add(new ItemStack(this));

        for (Fluid fluid : FluidRegistry.getRegisteredFluids().values())
        {
            if (!fluid.getName().equals("milk"))
            {
                // add all fluids that the bucket can be filled  with
                FluidStack fs = new FluidStack(fluid, content.capacity);
                ItemStack stack = new ItemStack(this);
                IFluidHandlerItem fluidHandler = new FluidHandlerItemStack(stack, content.capacity);
                if (fluidHandler.fill(fs, true) == fs.amount)
                {
                    ItemStack filled = fluidHandler.getContainer();
                    subItems.add(filled);
                }
            }
        }
    }
}
项目:Soot    文件:ItemMug.java   
@Override
public ICapabilityProvider initCapabilities(@Nonnull ItemStack stack, @Nullable NBTTagCompound nbt) {
    return new FluidHandlerItemStack(stack,capacity)
    {
        @Override
        public int fill(FluidStack resource, boolean doFill) {
            if(resource == null || resource.amount < capacity)
                return 0;

            return super.fill(resource, doFill);
        }
    };
}
项目:Industrial-Foregoing    文件:MeatFeederItem.java   
@Nullable
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) {
    FluidHandlerItemStack handlerItemStack = new FluidHandlerItemStack(stack, 128000) {
        @Override
        public boolean canFillFluidType(FluidStack fluid) {
            return fluid.getFluid().equals(FluidsRegistry.MEAT);
        }

    };
    handlerItemStack.fill(new FluidStack(FluidsRegistry.MEAT, 0), true);
    return handlerItemStack;
}
项目:CrystalMod    文件:ItemBlockTank.java   
public static FluidTank loadTank(NBTTagCompound nbtRoot) {
    int tankType = nbtRoot.hasKey("tankType") ? nbtRoot.getInteger("tankType") : 0;
    tankType = MathHelper.clamp(tankType, 0, BlockTank.tankCaps.length);
    int cap = BlockTank.tankCaps[tankType]*Fluid.BUCKET_VOLUME;
    FluidTank ret = new FluidTank(cap);

    if(nbtRoot.hasKey(FluidHandlerItemStack.FLUID_NBT_KEY)) {
      FluidStack fl = FluidStack.loadFluidStackFromNBT((NBTTagCompound) nbtRoot.getTag(FluidHandlerItemStack.FLUID_NBT_KEY));
      ret.setFluid(fl);
    } else {
      ret.setFluid(null);
    }
    return ret;
}
项目:CrystalMod    文件:ItemBlockTank.java   
public static void saveTank(NBTTagCompound nbtRoot, FluidTank tank) {
    if(tank.getFluidAmount() > 0) {
        NBTTagCompound fluidRoot = new NBTTagCompound();
        tank.getFluid().writeToNBT(fluidRoot);
        nbtRoot.setTag(FluidHandlerItemStack.FLUID_NBT_KEY, fluidRoot);
    } else {
        nbtRoot.removeTag(FluidHandlerItemStack.FLUID_NBT_KEY);
    }
}
项目:Culinary-Cultivation    文件:InventoryHandlerHelper.java   
public static void fillContainer(ItemStack container, FluidStack fluidStack, ItemStack heldStack, EntityPlayer player, EnumHand hand) {
    if (!player.isCreative()) {
        NBTTagCompound fluidTag = new NBTTagCompound();

        fluidStack.writeToNBT(fluidTag);
        NBTHelper.getTag(container).setTag(FluidHandlerItemStack.FLUID_NBT_KEY, fluidTag);

        InventoryHandlerHelper.giveItem(player, hand, container);
        heldStack.shrink(1);
    }
}
项目:Industrial-Foregoing    文件:MeatFeederItem.java   
@Override
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
    super.addInformation(stack, worldIn, tooltip, flagIn);
    FluidHandlerItemStack handlerItemStack = (FluidHandlerItemStack) stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, EnumFacing.DOWN);
    tooltip.add(getFilledAmount(stack) + "/" + handlerItemStack.getTankProperties()[0].getCapacity() + "mb of Meat");
}
项目:Industrial-Foregoing    文件:MeatFeederItem.java   
public int getFilledAmount(ItemStack stack) {
    FluidHandlerItemStack handlerItemStack = (FluidHandlerItemStack) stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, EnumFacing.DOWN);
    return (handlerItemStack.getFluid() == null ? 0 : handlerItemStack.getFluid().amount);
}
项目:Industrial-Foregoing    文件:MeatFeederItem.java   
public void drain(ItemStack stack, int amount) {
    FluidHandlerItemStack handlerItemStack = (FluidHandlerItemStack) stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, EnumFacing.DOWN);
    handlerItemStack.drain(new FluidStack(FluidsRegistry.MEAT, amount), true);
}
项目:CustomWorldGen    文件:ItemFluidContainer.java   
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt)
{
    return new FluidHandlerItemStack(stack, capacity);
}