Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I have an fluid tank which has fluid handler item capability and fluid handler capability. I tried using getPickBlock so players in creative can get the filled tank in their inventory but for some reason its working only on an integrated server, when I try it on a dedicated server for some reason its only called client side, I tried using !world.isRemote but then the code doesn't run at all. This is the code I'm using:

    @Override
    public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
        ItemStack stack = new ItemStack(this);
        IFluidHandler fluidHandler = FluidUtil.getFluidHandler(world, pos, null);
        if (fluidHandler != null) {
            FluidActionResult fluidActionResult = FluidUtil.tryFillContainer(new ItemStack(this), fluidHandler, Integer.MAX_VALUE, null, false);

            if (fluidActionResult.isSuccess()) {
                stack = fluidActionResult.getResult();
            }
        }
        return stack;
    }

 

Edited by Terrails

I've never used getPickBlock before but you seem to fill the wrong container...

You are creating a variable called stack, but you fill a completly different instance...

Edited by Major Tuvok
spelling mistake

Changing your FluidUtil call, so that it uses your local stack variable instead of new ItemStack(this) might help, although I don't really understand, why this code works with an integrated server at all.

Although is it possible, that this getFluidHandler Methods accessed TileEntities? Because it might be that the TileEntity you're trying to access doesn't exist and it is therefore returning null... 

  • Author
1 hour ago, Major Tuvok said:

I've never used getPickBlock before but you seem to fill the wrong container...

You are creating a variable called stack, but you fill a completly different instance...

I'm creating a variable so I can return an empty item if IFluidHandler is null, but when IFluidHandler isn't null I try to fill a new instance and if its filled I set the variable to that new instance.

59 minutes ago, Major Tuvok said:

Although is it possible, that this getFluidHandler Methods accessed TileEntities? Because it might be that the TileEntity you're trying to access doesn't exist and it is therefore returning null... 

Yes it needs to access the TileEntity, it checks if block at pos has tileentity and if it has it, then checks if it has fluid handler capability and returns the IFluidHandler if it has the capability, if not it returns null. FluidUtil is a class in minecraftforge itself.

 

But like I said on server it only launches with WorldClient and if I check if world isn't remote it doesn't even run

Edited by Terrails

  • Author

I now tried something simple like this, but it still doesn't work

    @Override
    public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
        ItemStack stack = new ItemStack(this);
        IFluidHandler fluidHandler = getFluidHandler(world, pos); // Gets the tile at pos and FLUID_HANDLER_CAPABILITY from it
        IFluidHandlerItem fluidHandlerItem = FluidUtil.getFluidHandler(stack);

        if (fluidHandler != null && fluidHandlerItem != null) {
            fluidHandlerItem.fill(fluidHandler.drain(Integer.MAX_VALUE, false), true);
            return fluidHandlerItem.getContainer(); // Tried without this but it makes no difference
        }

        return stack;
    }

I just fill the item fluid handler with drained fluid stack from the tile, the doDrain in drain method is false because I don't want it to drain the tile entity.

 

also this is how I display the fluid amount in the ItemBlock class

    @Override
    public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
        IFluidHandler fluidHandler = FluidUtil.getFluidHandler(stack);
        if (fluidHandler == null)
            return;

        for (IFluidTankProperties properties : fluidHandler.getTankProperties()) {
            FluidStack fluidStack = properties.getContents();

            if (fluidStack == null)
                return;

            tooltip.add(fluidStack.amount + "/" + properties.getCapacity());
        }
    }

I know it didn't fill it because fluidStack is null

 

EDIT: Looks like I fixed it, in initCapabilities of my itemblock I used my own handler, now tried FluidHandlerItemStack and it works

Edited by Terrails

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.