@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); } } } } }
@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); } }; }
@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; }
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; }
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); } }
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); } }
@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"); }
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); }
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); }
@Override public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt) { return new FluidHandlerItemStack(stack, capacity); }