Jump to content

Help needed with FillBucketEvent


airpodjoch_

Recommended Posts

Hello everyone, I am trying to check wether a player is at an ocean/beach, and then gives the player a Salty Water Bucket instead of a normal Water Bucket. I got it kinda working, up until the point it's not giving me the Salty Water Bucket.

This is what I have now:

public class BucketFillHandler {

    @SubscribeEvent
    public static void onBucketFill(@NotNull FillBucketEvent event) {
        Player player = event.getPlayer();
        BlockPos pos = new BlockPos(player.getX(), player.getY(), player.getZ());

        if (event.getWorld().isClientSide()) {
            if (event.getWorld().getBiomeManager().getBiome(pos).getRegistryName().toString().equals("minecraft:beach")) {
                if (event.getPlayer() != null) {
                    HitResult target = event.getTarget();
                    if (target != null && target.getType() == HitResult.Type.BLOCK) {
                        BlockState state = event.getWorld().getBlockState(new BlockPos(target.getLocation()));
                        Material material = state.getMaterial();

                        if (material == Material.WATER && (Integer) state.getValue(LiquidBlock.LEVEL) == 0) {
                            event.setResult(Event.Result.ALLOW);
                            System.out.println("YES"); // This is just for testing purposes.
                            event.setFilledBucket(new ItemStack(ModItems.SALTY_WATER_BUCKET.get(), 1)); // This is what doesn't work
                        }
                    }
                }
            }
        }
    }
}

 

Edited by airpodjoch_
Link to comment
Share on other sites

Wow. It was that simple. I actually scrapped that off my list if possible fixes, when my game crashed last time I used the if statement with that condition. However, before I made this forum post I changed the script around a little, not checking if this would actually work. I got to say that, it's kinda weird isClientSide() basically means "are you a server".

Anyway, I got it fixed by making it:

if (!event.getWorld().isClientSide()) {}

 

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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