forked from DrexHD/lithium-fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: Add patch to optimize mob spawning
Retrieving the entity spawn list for a given entity category is a rather hot activity in mob spawning. This replaces the EntityCategory->List map with a specialized type for enum keys, which reduces a hash lookup to an array index.
- Loading branch information
1 parent
5aac5de
commit a122476
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/me/jellysquid/mods/lithium/mixin/world/mob_spawning/MixinBiome.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package me.jellysquid.mods.lithium.mixin.world.mob_spawning; | ||
|
||
import com.google.common.collect.Maps; | ||
import net.minecraft.entity.EntityCategory; | ||
import net.minecraft.world.biome.Biome; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Mixin(Biome.class) | ||
public class MixinBiome { | ||
@Mutable | ||
@Shadow | ||
@Final | ||
private Map<EntityCategory, List<Biome.SpawnEntry>> spawns; | ||
|
||
/** | ||
* Re-initialize the spawn category lists with a much faster backing collection type for enum keys. This provides | ||
* a modest speed-up for mob spawning as {@link Biome#getEntitySpawnList(EntityCategory)} is a rather hot method. | ||
*/ | ||
@Inject(method = "<init>", at = @At("RETURN")) | ||
private void reinit(Biome.Settings settings, CallbackInfo ci) { | ||
Map<EntityCategory, List<Biome.SpawnEntry>> spawns = Maps.newEnumMap(EntityCategory.class); | ||
spawns.putAll(this.spawns); | ||
|
||
this.spawns = spawns; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters