Posted May 9, 20178 yr I'm trying to check if an ItemStack has the FluidHandler capability. For that I tried using this: boolean hasCap = stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); The ItemStack passed was a ItemWaterBucket. I've also tried it using forge filled buckets, but both alway return false. Am I checking for the wrong capability?
May 9, 20178 yr Fluid handler items use CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY instead of CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY. I'm not sure exactly what you're doing with the fluid handler item, but you may want to check if the FluidUtil class already has a method that does what you want. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
May 9, 20178 yr Author Thanks, was wondering what FLUID_HANDLER_ITEM was for... Also didn't know about FluidUtil. Is there also a ItemHandlerUtil of some sort for ItemStackHandlers?
May 9, 20178 yr Just now, Tschipp said: Is there also a ItemHandlerUtil of some sort for ItemStackHandlers? Yes, ItemHandlerHelper. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
May 9, 20178 yr Author Thanks. One more thing: This doesn't seem to drain the bucket: FluidUtil.getFluidHandler(heldItem).drain(1000, true); the FluidHandler isn't null, i do that check beforehand. What am I missing?
May 9, 20178 yr 20 minutes ago, Tschipp said: Thanks. One more thing: This doesn't seem to drain the bucket: FluidUtil.getFluidHandler(heldItem).drain(1000, true); the FluidHandler isn't null, i do that check beforehand. What am I missing? If I recall correctly, the second parameter of the drain method is about whether it'll be simulated(to check the validity) or the change is actually applied. So it should be false in your csse. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
May 9, 20178 yr Author 4 minutes ago, Abastro said: If I recall correctly, the second parameter of the drain method is about whether it'll be simulated(to check the validity) or the change is actually applied. So it should be false in your csse. I've tried both true and false, still doesn't empty the bucket.
May 9, 20178 yr 8 minutes ago, Tschipp said: I've tried both true and false, still doesn't empty the bucket. Well, I recalled it incorrectly What did you get as return from the method? I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
May 9, 20178 yr Author getFluidHandler returns a IFluidHandlerItem, which isn't null. drain returns a FluidStack, the stack that supposedly was drained, also correct.
May 9, 20178 yr Author Block#onBlockActivated, but only if !world.isRemote else if(hasFluid(heldItem, BlockHandler.fluidSlop) && te.itemHandler.getStackInSlot(0).isEmpty()) { te.fluidHandler.fill(new FluidStack(BlockHandler.fluidSlop, 1000), true); worldIn.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_SLIME_PLACE, SoundCategory.PLAYERS, 0.6F, 0.8F); if(!playerIn.isCreative()) { FluidStack fluid = FluidUtil.getFluidHandler(heldItem).drain(1000, true); } return true; } Edited May 9, 20178 yr by Tschipp
May 9, 20178 yr Author @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack heldItem = playerIn.getHeldItem(hand); TileEntityTrough te = (TileEntityTrough) worldIn.getTileEntity(pos); if (worldIn.isRemote) { return true; } //SOLIDS else if(!heldItem.isEmpty() && heldItem.getItem() == Items.WHEAT) { if((!te.itemHandler.getStackInSlot(0).isEmpty() && te.itemHandler.getStackInSlot(0).getCount() < 3) || te.itemHandler.getStackInSlot(0).isEmpty() && te.fluidHandler.getFluid() == null) { te.itemHandler.insertItem(0, new ItemStack(Items.WHEAT), false); if(!playerIn.isCreative()) heldItem.shrink(1); return true; } } //LIQUIDS else if(hasFluid(heldItem, FluidRegistry.WATER) && te.itemHandler.getStackInSlot(0).isEmpty()) { te.fluidHandler.fill(new FluidStack(FluidRegistry.WATER, 1000), true); worldIn.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.PLAYERS, 0.6F, 0.8F); if(!playerIn.isCreative()) FluidUtil.getFluidHandler(heldItem).drain(1000, true); return true; } else if(hasFluid(heldItem, BlockHandler.fluidSlop) && te.itemHandler.getStackInSlot(0).isEmpty()) { te.fluidHandler.fill(new FluidStack(BlockHandler.fluidSlop, 1000), true); worldIn.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_SLIME_PLACE, SoundCategory.PLAYERS, 0.6F, 0.8F); if(!playerIn.isCreative()) { FluidStack fluid = FluidUtil.getFluidHandler(heldItem).drain(1000, true); } return true; } return false; }
May 9, 20178 yr Author 14 minutes ago, diesieben07 said: The IFluidHandlerItem might have to create a new ItemStack to allow for the modifications (e.g. when emptying a vanilla bucket, because they are different items). You can access the "up to date" stack with IFluidHandlerItem::getContainer. In this case you have to put it back in the player's hand. That did the trick, thanks!
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.