Spawn Egg BYID Redirect

Spawn Egg BYID Redirect

Mod

Needed for same Spawn Egg type compatibility

Client and server Library Mobs

271 downloads
1 follower
Created4 months ago
Updateda month ago

Follow Save
Host your Minecraft server on BisectHosting - get 25% off your first month with code MODRINTH.

For users:

Some mods may rely on things this mod does in the background to function properly. Just install it alongside any mod that requires it on both client and server.


Use Case: If a mod you have installed adds multiple spawn eggs for the same type of mob (i.e. for different variants), and one of the spawn eggs lost its color as a result, this mod may fix the color.

Follow the link below and use code "JACKBUSTERS" at checkout for 25% off server hosting.

Rent a server discount


For Developers:

This mod makes BY_ID#put() inside of the SpawnEggItem constructor call BY_ID#putIfAbsent() instead. While this change may seem minor, it makes a big difference when you want to have multiple spawn eggs with the same entity type (For instance, if you want spawn eggs which spawn variants).


A short tutorial on how to go about using this mod when adding something like a variant spawn egg:

1) Create a new class extending SpawnEggItem (Mojang Official Mappings, extend whatever this is converted to the mappings of your choice).

2) Create a public static Map of ResourceKey<(The type of variant you want> and SpawnEggItem. Like so:

public static final Map<ResourceKey<WolfVariant>, SpawnEggItem> BY_VARIANT = Maps.newIdentityHashMap();

3) In your constructor, call the HashMap you created with either the put() method or the putIfAbsent():

BY_VARIANT.putIfAbsent(wolfVariant, this);

4) Create a mixin mixing into the SpawnEggItem class. Inject the eggs method at return. Add your map to the returned Iterable like so (Again, this is Mojang official mappings):

@Inject(method = "eggs", at = @At("RETURN"), cancellable = true)
private static void eggs(CallbackInfoReturnable<Iterable<SpawnEggItem>> cir){
    ArrayList<SpawnEggItem> spawnEggItems = new ArrayList<>();
    cir.getReturnValue().iterator().forEachRemaining(spawnEggItems::add);
    spawnEggItems.addAll(BY_VARIANT.values());
    Iterable<SpawnEggItem> iterable = Iterables.consumingIterable(spawnEggItems);
    cir.setReturnValue(iterable);
}

This is just how I did it, there may very well be a more efficient way to do this. Use caution though, as you'll want to assure you maintain mod compatibility. This mixin will make sure each instance of your variant egg is provided to the eggs method for color processing. Without it, all eggs but your very last registered one would not generate with your defined colors.

5) If you run the mod now you'll notice that your general spawn egg, not specified to a variant, will have lost its color. That's what this mod fixes without any extra work on your part so long as you didn't do anything to the BY_ID map.


Most other work will probably be done by overriding the useOn method of SpawnEggItem. I won't be walking you through that one since it doesn't really pertain to this mod, but let me know if you run into any issues and I may try to help.


Project members

Jackbusters

Member


Technical information

License
ARR
Client side
required
Server side
required
Project ID