Jump to content

reflection to get biome name...


OsHeaven

Recommended Posts

hi,

I build a method to get the biome name on server side while world generation:

 

private static String getBiomeName(World world, int chunkX, int chunkZ)
    {
        String biomeName = "unknown";
        Biome biomeInstance = world.getBiome(new BlockPos(chunkX * 16, 0, chunkZ * 16));
        String field = "biomeName";
        try
        {
            Object value = ReflectionHelper.getPrivateValue(Biome.class, biomeInstance, field);
            biomeName = (String) value;
        }
        catch (Exception e)
        {
            Logger.log(Level.ERROR, "Problem loading value from field " + field, e);
        }
        return biomeName;
    }

when i am run mc server/client in my intellj ide everthings is working well, but after compiling in normal minecraft forge, same version like forge mdk, or newer versions, the launcher crashes and the console freezes. sometimes i get infos befor freeze, that says the biomeName field in (Biome.class) does not exist... i dont know how to fix, because in the ide is no issue while running...

 

i am using the biomeName to generate ores in specific biomes (like more gold in vanilla mesa or emeralds in extreme hills)

 

I would be grateful if someone helped me to find out what i am diong wrong using reflection to get the biome name on server side.

 

 

thanks!

 

Edited by OsHeaven
Link to comment
Share on other sites

ok, i get the SRG name from http://export.mcpbot.bspk.rs/ fields.csv (biomeName = field_185412_a)

 now i am using 

 

String[] fieldName = {"biomeName", "field_185412_a"};

Field f = ReflectionHelper.findField(Biome.class, fieldName);

biomeName = (String) f.get(biomeInstance);

 

in the ide everything is fine, in the actual game the launcher dont crashes anymore and log isnt freezing, but still java.lang.NoSuchFieldException: field_185412_a

 

Link to comment
Share on other sites

ReflectionHelper.findField(Biome.class, "biomeName", "field_185412_a" ); is sufficient

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.

Link to comment
Share on other sites

28 minutes ago, OsHeaven said:

does not change anything
 

I said "this line of code is identical" not "this will fix your problem."

That said, if you get a field not found exception, you have the wrong field name. Are you sure that that is the only entry for "biomeName"?

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.

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



×
×
  • Create New...

Important Information

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