Jump to content

How to check if player is in a biome of a specific type?


Recommended Posts

Posted

My goal is to check whether the player is currently in a certain type of biome; in this case, a forest. I was able to get everything working up until the if statement.

 

The error I get is 'Operator '==' cannot be applied to 'net.minecraft.world.biome.Biome', 'net.minecraft.util.RegistryKey<net.minecraft.world.biome.Biome>', and I can't say I know exactly what this means. Maybe their types are not compatible? And, if so, how should they be changed?

 

Also, just as an FYI, I'm fairly new to Minecraft Modding and Java as a whole.

 

@SubscribeEvent
public static void biomeDetect(LivingEvent.LivingUpdateEvent event) {
    LivingEntity player = event.getEntityLiving();
    BlockPos pos = new BlockPos(player.getPositionVec());
    World world = player.getEntityWorld();

    if (world.getBiome(pos) == Biomes.FOREST) {
        ///execute if player is in forest
    }
}
Posted

One of those things is a Biome, the other is a RegistryKey object that you need to get a Biome from.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

So that sort of answers my first question, which was whether their types were compatible or not, and from what I gather the answer to that is no. My second question has to do with how I should change the two conditions to operate correctly.

 

Assuming that 'world.getBiome(pos)' is the RegistryKey object that I can get the biome from, how exactly would I go about doing that? I tried storing it in a variable of type 'Biome', but this made no difference.

 

Biome biome = world.getBiome(pos);

if (biome == Biomes.FOREST) {
    ///execute if player is in forest
}

 

Posted
2 hours ago, sver20 said:

So that sort of answers my first question, which was whether their types were compatible or not

That's literally what the error says:

16 hours ago, sver20 said:

The error I get is 'Operator '==' cannot be applied to 'net.minecraft.world.biome.Biome', 'net.minecraft.util.RegistryKey<net.minecraft.world.biome.Biome>',

Its telling you that on one side you have an object of Type "Biome" and on the other you have an object of Type "RegistryKey<Biome>" and that neither one overloads the == operator to make the comparison possible.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
3 minutes ago, diesieben07 said:

Since Java does not have operator overloading, this statement is true for any two types in Java ;)

Touche.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.