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.

SOLVED (1.12.2) Checking which biome a player is in when they try to fill a bucket.

Featured Replies

Posted

I'm trying to make it so when a player stands in an ocean or beach biome and tries to fill a bucket with water, it instead gives a different item (SaltwaterBucket). 

I think I have to do this in an event handler class and the FullBucketEvent?

Or would I accomplish this in my Item class?

I'm a little stumped on what to do specifically though. Any pointers would be really appreciated! 

public class BucketFillHandler {

	 @SubscribeEvent
	 public void onBucketFill(FillBucketEvent event) {
	 	//Check for Ocean Biome and give player either saltwaterbucket or regular bucket.
	 }
}

 

Edited by xxWhatsherfacex

1 hour ago, xxWhatsherfacex said:

FillBucketEvent event

Does this event have a World and a BlockPos field you can access? If so just use World#getBiome(BlockPos). I believe that is the name of the method.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author

Alright! Thanks so much!

I managed to successfully check the biome and detect if the player is trying to collect water with their bucket.

 

public class BucketFillHandler {

	 @SubscribeEvent
	 public void onBucketFill(FillBucketEvent event) {	 
			EntityPlayer player = Minecraft.getMinecraft().player;
			BlockPos pos = new BlockPos(player.getPositionVector());
			if (event.getWorld().getBiome(pos) == Biomes.BEACH || event.getWorld().getBiome(pos) == Biomes.OCEAN || event.getWorld().getBiome(pos) == Biomes.DEEP_OCEAN || event.getWorld().getBiome(pos) == Biomes.COLD_BEACH || event.getWorld().getBiome(pos) == Biomes.FROZEN_OCEAN || event.getWorld().getBiome(pos) == Biomes.STONE_BEACH) {

				if(event.getEntityPlayer() != null && !event.getWorld().isRemote)
			    {
			        RayTraceResult target = event.getTarget();
			        if(target != null && target.typeOfHit == RayTraceResult.Type.BLOCK)
			        {
			            if(target.getBlockPos() != null)
			            {
			                IBlockState state = event.getWorld().getBlockState(target.getBlockPos());
		                    Material material = state.getMaterial();
			                if(material == Material.WATER && ((Integer)state.getValue(BlockLiquid.LEVEL)).intValue() == 0)
			                {
			                	
			                	//Give the player ModItems.SALTWATER_BUCKET
			                	
			                }
			            }
			        }
			    }
			}
	 }

 

I'm a little stumped on how to give the player the bucket now. I tried using event.setFilledBucket(new ItemStack(ModItems.SALTWATER_BUCKET, 1)); where the comment is but it isn't doing anything but giving the regular bucket of water.

27 minutes ago, xxWhatsherfacex said:

but it isn't doing anything but giving the regular bucket of water.

Set the result to Result.ALLOW using Event#setResult

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

On 9/18/2019 at 3:50 AM, xxWhatsherfacex said:

I managed to successfully check the biome and detect if the player is trying to collect water with their bucket.

do not use "Minecraft.getMinecraft ().player". it will crash the game in multiplayer. get the player from the event parameter.

you almost never want to use equality to check for biomes (except if you want single exact biome, and none of its variations). normally you would use biome types.

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.