Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Spawn Eggs for Entities appear white [1.16.5]
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
Godis_apan

Spawn Eggs for Entities appear white [1.16.5]

By Godis_apan, February 11 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Godis_apan    15

Godis_apan

Godis_apan    15

  • Creeper Killer
  • Godis_apan
  • Members
  • 15
  • 109 posts
Posted February 11

Hello! For some reason when adding multiple spawn eggs for my entities, only the last one registered renders in the inventory with its proper colors. All eggs registered before the last on appear white and I can't figure out why.

 

Item register code: https://github.com/Phrille/Vanilla-Boom/blob/master/src/main/java/phrille/vanillaboom/init/ModItems.java

  • Quote

My mod for futher awesomeness:

 

http://www.minecraftforum.net/topic/1714396-the-decopack-collection-v010-wip-made-a-signature-new-snapshot-1-screenshots-are-up-small-snapshot-1-is-out-for-147/#entry21250399

Share this post


Link to post
Share on other sites

Godis_apan    15

Godis_apan

Godis_apan    15

  • Creeper Killer
  • Godis_apan
  • Members
  • 15
  • 109 posts
Posted February 11

Bump

  • Quote

My mod for futher awesomeness:

 

http://www.minecraftforum.net/topic/1714396-the-decopack-collection-v010-wip-made-a-signature-new-snapshot-1-screenshots-are-up-small-snapshot-1-is-out-for-147/#entry21250399

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted February 11

That's because the spawn egg entry being pushed into the map keep replacing the null key value. As such, only the last egg is ever considered. You need to reflect into the map to add your spawn eggs with the corresponding entity type during common setup.

  • Quote

Share this post


Link to post
Share on other sites

Godis_apan    15

Godis_apan

Godis_apan    15

  • Creeper Killer
  • Godis_apan
  • Members
  • 15
  • 109 posts
Posted February 11

Alright that makes sense. Is this thread safe to do or should I use event.enqueueWork?

  • Quote

My mod for futher awesomeness:

 

http://www.minecraftforum.net/topic/1714396-the-decopack-collection-v010-wip-made-a-signature-new-snapshot-1-screenshots-are-up-small-snapshot-1-is-out-for-147/#entry21250399

Share this post


Link to post
Share on other sites

diesieben07    7688

diesieben07

diesieben07    7688

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7688
  • 56257 posts
Posted February 11

Considering it is an IdentityHashMap: No, it is not thread safe.

  • Quote

Share this post


Link to post
Share on other sites

Godis_apan    15

Godis_apan

Godis_apan    15

  • Creeper Killer
  • Godis_apan
  • Members
  • 15
  • 109 posts
Posted February 12

Can't get this to work yet:

 

    public static void addSpawnEgg(IItemProvider item)
    {
        if (item instanceof EntitySpawnItem) 
        {
            EntitySpawnItem egg = (EntitySpawnItem) item;
            
            try
            {
                Field field = ObfuscationReflectionHelper.findField(SpawnEggItem.class, "field_195987_b");
                Map<EntityType<?>, SpawnEggItem> map = (Map<EntityType<?>, SpawnEggItem>) field.get(null);
                map.put(egg.getType(null), egg);
            }
            catch (IllegalAccessException | IllegalArgumentException e)
            {
                throw new RuntimeException("Could not add " + item.asItem().getRegistryName().toString() + " to spawn eggs map", e);
            }
        }
    }

 

This is called from FMLCommonSetup:

 

        event.enqueueWork(() ->
        {
            Utils.addSpawnEgg(ModItems.PERCH_SPAWN_EGG);
            Utils.addSpawnEgg(ModItems.EEL_SPAWN_EGG);
            Utils.addSpawnEgg(ModItems.PIKE_SPAWN_EGG);
            Utils.addSpawnEgg(ModItems.TUNA_SPAWN_EGG);
            Utils.addSpawnEgg(ModItems.SWAMP_DWELLER_SPAWN_EGG);
        });

 

  • Quote

My mod for futher awesomeness:

 

http://www.minecraftforum.net/topic/1714396-the-decopack-collection-v010-wip-made-a-signature-new-snapshot-1-screenshots-are-up-small-snapshot-1-is-out-for-147/#entry21250399

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted February 12
3 hours ago, Godis_apan said:

Field field = ObfuscationReflectionHelper.findField(SpawnEggItem.class, "field_195987_b"); Map<EntityType<?>, SpawnEggItem> map = (Map<EntityType<?>, SpawnEggItem>) field.get(null);

Just store the map as a map with one reflection, this is just unnecessary.

 

Use breakpoints to determine whether or not the entries are being put in the map. Also, the null entry within the map should be removed afterwards.

 

  • Quote

Share this post


Link to post
Share on other sites

Godis_apan    15

Godis_apan

Godis_apan    15

  • Creeper Killer
  • Godis_apan
  • Members
  • 15
  • 109 posts
Posted February 12 (edited)

Okay! Checked with breakpoints and as far as I could tell the map is modified but still no result. What am I doing wrong here?

    public static final Map<EntityType<?>, SpawnEggItem> EGG_MAP = Maps.newHashMap();

    public static void addSpawnEggs()
    {
        try
        {
            Map<EntityType<?>, SpawnEggItem> map = (Map<EntityType<?>, SpawnEggItem>) ObfuscationReflectionHelper.findField(SpawnEggItem.class, "field_195987_b").get(null);
            map.keySet().removeIf(Objects::isNull);
            map.putAll(EGG_MAP);
        }
        catch (IllegalAccessException | IllegalArgumentException e)
        {
            throw new RuntimeException("Failed to spawn eggs to map", e);
        }
    }

 

Edited February 12 by Godis_apan
  • Quote

My mod for futher awesomeness:

 

http://www.minecraftforum.net/topic/1714396-the-decopack-collection-v010-wip-made-a-signature-new-snapshot-1-screenshots-are-up-small-snapshot-1-is-out-for-147/#entry21250399

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted February 12 (edited)

You are not storing the map itself but now a copy. Store the private value of the map and put elements into that.

Edited February 12 by ChampionAsh5357
  • Quote

Share this post


Link to post
Share on other sites

Godis_apan    15

Godis_apan

Godis_apan    15

  • Creeper Killer
  • Godis_apan
  • Members
  • 15
  • 109 posts
Posted February 12

I'm sorry to be such a dum-dum here but I can't see how I would do this. Wouldn't this be better to do with ATs? Or is that bad? Thanks for the help it's very much appreciated.

  • Quote

My mod for futher awesomeness:

 

http://www.minecraftforum.net/topic/1714396-the-decopack-collection-v010-wip-made-a-signature-new-snapshot-1-screenshots-are-up-small-snapshot-1-is-out-for-147/#entry21250399

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted February 13
8 hours ago, Godis_apan said:

Wouldn't this be better to do with ATs?

Not really, you are only using the value once so it'd be a waste to AT into the field. As I've mentioned, use ObfuscationReflectionHelper::getPrivateValue and store the map. Then, do the required operations on the map itself. Since we're changing the elements the map refers to, we can just store the overarching object.

  • Quote

Share this post


Link to post
Share on other sites

Godis_apan    15

Godis_apan

Godis_apan    15

  • Creeper Killer
  • Godis_apan
  • Members
  • 15
  • 109 posts
Posted February 13

Okay Im using that method now but how do I store the map? Do I need to use setPrivateValue afterwards?

            Map<EntityType<?>, SpawnEggItem> map = (Map<EntityType<?>, SpawnEggItem>) ObfuscationReflectionHelper.getPrivateValue(SpawnEggItem.class, null, "field_195987_b");
            map.keySet().removeIf(Objects::isNull);
            map.putAll(EGG_MAP);

 

  • Quote

My mod for futher awesomeness:

 

http://www.minecraftforum.net/topic/1714396-the-decopack-collection-v010-wip-made-a-signature-new-snapshot-1-screenshots-are-up-small-snapshot-1-is-out-for-147/#entry21250399

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted February 14
12 hours ago, Godis_apan said:

Okay Im using that method now but how do I store the map? Do I need to use setPrivateValue afterwards?

It's a map... Modifying information within an object doesn't require you to replace it. Only if you're modifying the outer object itself.

  • Quote

Share this post


Link to post
Share on other sites

Godis_apan    15

Godis_apan

Godis_apan    15

  • Creeper Killer
  • Godis_apan
  • Members
  • 15
  • 109 posts
Posted February 14

Well it still isn't working, all the eggs except the last still appear white

  • Quote

My mod for futher awesomeness:

 

http://www.minecraftforum.net/topic/1714396-the-decopack-collection-v010-wip-made-a-signature-new-snapshot-1-screenshots-are-up-small-snapshot-1-is-out-for-147/#entry21250399

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted February 15

Have you tested with a new world instance?

  • Quote

Share this post


Link to post
Share on other sites

Godis_apan    15

Godis_apan

Godis_apan    15

  • Creeper Killer
  • Godis_apan
  • Members
  • 15
  • 109 posts
Posted February 16

I have, still no result.

  • Quote

My mod for futher awesomeness:

 

http://www.minecraftforum.net/topic/1714396-the-decopack-collection-v010-wip-made-a-signature-new-snapshot-1-screenshots-are-up-small-snapshot-1-is-out-for-147/#entry21250399

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted February 16

Then I would put a breakpoint where ItemColors calls the egg list to add them and see if your eggs are present within there.

  • Quote

Share this post


Link to post
Share on other sites

Godis_apan    15

Godis_apan

Godis_apan    15

  • Creeper Killer
  • Godis_apan
  • Members
  • 15
  • 109 posts
Posted February 18 (edited)

Okay so I debugged this and it seems that the ItemColors registers before I reflect into the map. When I added a breakpoint in the ItemColors only the last egg I added showed up in the for loop where SpawnEggItem#getEggs() gets called. But when I run the same for loop after my reflection has taken place my entities also shows up. So how do I reflect into the map before ItemColors are registered?  

 

https://github.com/Phrille/Vanilla-Boom/blob/master/src/main/java/phrille/vanillaboom/util/Utils.java

Edited February 18 by Godis_apan
  • Quote

My mod for futher awesomeness:

 

http://www.minecraftforum.net/topic/1714396-the-decopack-collection-v010-wip-made-a-signature-new-snapshot-1-screenshots-are-up-small-snapshot-1-is-out-for-147/#entry21250399

Share this post


Link to post
Share on other sites

Godis_apan    15

Godis_apan

Godis_apan    15

  • Creeper Killer
  • Godis_apan
  • Members
  • 15
  • 109 posts
Posted Saturday at 01:46 PM (edited)

Bump

Edited Monday at 09:56 AM by Godis_apan
  • Quote

My mod for futher awesomeness:

 

http://www.minecraftforum.net/topic/1714396-the-decopack-collection-v010-wip-made-a-signature-new-snapshot-1-screenshots-are-up-small-snapshot-1-is-out-for-147/#entry21250399

Share this post


Link to post
Share on other sites

Godis_apan    15

Godis_apan

Godis_apan    15

  • Creeper Killer
  • Godis_apan
  • Members
  • 15
  • 109 posts
Posted Monday at 09:56 AM

Bum again

  • Quote

My mod for futher awesomeness:

 

http://www.minecraftforum.net/topic/1714396-the-decopack-collection-v010-wip-made-a-signature-new-snapshot-1-screenshots-are-up-small-snapshot-1-is-out-for-147/#entry21250399

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Centmap
      Forge Mods Folder

      By Centmap · Posted 31 minutes ago

      so i created a "1.16.5" folder in the folder "mod" as usual but it doesn't use the mods. Can anyone help me ?
    • Skyriis
      [SOLVED][1.16.5] Adding a Button to KeyBindings

      By Skyriis · Posted 1 hour ago

      That worked.   Here is my solution @SubscribeEvent public static void onOpenGui(final GuiScreenEvent.InitGuiEvent.Post event) { if (!(event.getGui() instanceof ControlsScreen)) return; final ControlsScreen controlsScreen = (ControlsScreen) event.getGui(); final KeyBindingList replacement = new KeyBindingListReplacement(controlsScreen, event.getGui().getMinecraft()); final KeyBindingList old = ObfuscationReflectionHelper.getPrivateValue(ControlsScreen.class, controlsScreen, "field_146494_r"); controlsScreen.getEventListeners().remove(old); ObfuscationReflectionHelper.setPrivateValue(ControlsScreen.class, controlsScreen, replacement, "field_146494_r"); try { Method addChildMethod = ObfuscationReflectionHelper.findMethod(Screen.class, "func_230481_d_", IGuiEventListener.class); addChildMethod.setAccessible(true); addChildMethod.invoke(controlsScreen, replacement); addChildMethod.setAccessible(false); } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } }  
    • DrCowiber
      Failed To Start Minecraft Server

      By DrCowiber · Posted 1 hour ago

      im using this run.sh file, which contains: java -Xmx6G -Xms6G -jar minecraft_server.1.16.5.jar --nogui Edit: When I first posted about this I was using the serverRun.jar, which the first log file I posted is what the output was
    • Tez
      [1.15.2] Couln't not resolve dependency: net.minecraftforge:forge:1.15.2-31.2.0:userdev

      By Tez · Posted 1 hour ago

      I'm new to mod coding so i've watch tutorial in youtube in setup workspace step i got this error , i've try many solutions to fix but it still not working try update gradle to 6.8.3 but still not working try update java and still not working too here's my stacktrace: Stacktrace
    • diesieben07
      Failed To Start Minecraft Server

      By diesieben07 · Posted 2 hours ago

      Please show how exactly you are starting the server.
  • Topics

    • Centmap
      0
      Forge Mods Folder

      By Centmap
      Started 31 minutes ago

    • Skyriis
      8
      [SOLVED][1.16.5] Adding a Button to KeyBindings

      By Skyriis
      Started 23 hours ago

    • DrCowiber
      8
      Failed To Start Minecraft Server

      By DrCowiber
      Started 21 hours ago

    • Tez
      0
      [1.15.2] Couln't not resolve dependency: net.minecraftforge:forge:1.15.2-31.2.0:userdev

      By Tez
      Started 1 hour ago

    • Mysterious minecrafter
      1
      game keeps crashing while initializings

      By Mysterious minecrafter
      Started 3 hours ago

  • Who's Online (See full list)

    • GermanBucket
    • smitokyo
    • KingBlake122308
    • Skyriis
    • sleepier
    • Zeher_Monkey
    • Uncreative
    • NullDev
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Spawn Eggs for Entities appear white [1.16.5]
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community