Jump to content

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


xxWhatsherfacex

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.

×
×
  • Create New...

Important Information

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