Jump to content

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


Recommended Posts

Posted (edited)

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

Posted

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.

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

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

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • @TileEntity it seemed to work, but do you know of a way i could get the two mods to play nicely with each other? Im just trying to add supplementary to a modpack (and most of the mods dont play nicely with neoforge) so i cant exactly remake the whole pack.
    • I did that and it says Error: Unable to access jarfile server.jar im assuming this is why you said make to sure they match? so I checked and following that same path then viewing the server folder, there is no .far file only a .dll file checking the modded server folder obviously has a server-1.20.1.jar file though completely different pathing so I don't think this is what you mean but let me know if im missing something. ALSO, was probably not what was needed but I reinstalled Java 17 in case it didnt fully download for some reason? still no such file.
    • Yes - Update 6 makes larger changes which is breaking these addons Most addons already have the update - some are still in the update process and will be released in the next days
    • So, as I understand it, at the moment it's not possible to update the modpack because too few addons are compatible with version 6 of Create?
    • Check the PC for the Java 17 installation The Oracle Java default path is C:\Program Files\Java\jdk-17\bin\javaw.exe   Open the bat file and replace the world java with the path and put it into quotation marks "C:\Program Files\Java\jdk-17\bin\javaw.exe" -Xmx4G -jar server.jar pause Make sure the java path is correct - the server jar file name also have to match
  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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