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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I want to download Forge 1.20.6, but when I press download, it redirects me to Adfocus and does not provide any download. I have never encountered such a problem when I downloaded Forge 1.18.2 at least 12 months ago.
    • did you find any solutions? i have the same problem and also that mahito doesnt transform
    • Here's a simple example to solve this particular issue: public class ModArmorMaterials { public static final DeferredRegister<ArmorMaterial> ARMORS = DeferredRegister.create(Registries.ARMOR_MATERIAL, MyModName.MOD_ID); public static final RegistryObject<ArmorMaterial> COPPER = registerArmor("copper", Util.make(new EnumMap<>(ArmorItem.Type.class), enumMap -> { enumMap.put(ArmorItem.Type.BOOTS, 1); enumMap.put(ArmorItem.Type.LEGGINGS, 4); enumMap.put(ArmorItem.Type.CHESTPLATE, 5); enumMap.put(ArmorItem.Type.HELMET, 2); enumMap.put(ArmorItem.Type.BODY, 4); }), 12, SoundEvents.ARMOR_EQUIP_IRON, 0.0F, 0.0F, () -> Ingredient.of(Items.COPPER_INGOT)); private static RegistryObject<ArmorMaterial> registerArmor(String pGroup, EnumMap<ArmorItem.Type, Integer> pEnumMap, int pEnchantmentValue, Holder<SoundEvent> pEquipSound, float pToughness, float pKnockbackResistance, Supplier<Ingredient> pRepairIngredient) { List<ArmorMaterial.Layer> pLayerList = List.of(new ArmorMaterial.Layer(new ResourceLocation(pGroup))); return registerArmor(pGroup, pEnumMap, pEnchantmentValue, pEquipSound, pToughness, pKnockbackResistance, pRepairIngredient, pLayerList); } private static RegistryObject<ArmorMaterial> registerArmor( String pGroup, EnumMap<ArmorItem.Type, Integer> pEnumMap, int pEnchantmentValue, Holder<SoundEvent> pEquipSound, float pToughness, float pKnockbackResistance, Supplier<Ingredient> pRepairIngredient, List<ArmorMaterial.Layer> pLayerList) { return ARMORS.register(pGroup, () -> new ArmorMaterial(pEnumMap, pEnchantmentValue, pEquipSound, pRepairIngredient, pLayerList, pToughness, pKnockbackResistance)); } public static void register(IEventBus eventBus) { ARMORS.register(eventBus); } } Essentially, the TierSortingRegistry has been removed and so you now need to set up your own DeferredRegister. Please see the minecraftforge GitHub for more information; I found this solution through their issues (https://github.com/MinecraftForge/MinecraftForge/issues/9961)
    • How did I even leave that in there? I’ll try it in a bit, that very well could be it.
  • Topics

×
×
  • Create New...

Important Information

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