From e3e265a03d6f352dcbd54e187bb0336070387917 Mon Sep 17 00:00:00 2001 From: jchung01 Date: Fri, 23 Aug 2024 20:13:23 -0700 Subject: [PATCH] Use Overwrite to avoid original computation --- .../mixin/UTChunkGeneratorMachinesMixin.java | 18 +++++++++++++----- .../mixin/UTWorldProviderMachinesMixin.java | 2 -- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/spawns/mixin/UTChunkGeneratorMachinesMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/spawns/mixin/UTChunkGeneratorMachinesMixin.java index 32a7e51f..616513fe 100644 --- a/src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/spawns/mixin/UTChunkGeneratorMachinesMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/spawns/mixin/UTChunkGeneratorMachinesMixin.java @@ -5,28 +5,36 @@ import net.minecraft.entity.EnumCreatureType; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; import net.minecraft.world.biome.Biome; -import com.llamalad7.mixinextras.injector.ModifyReturnValue; import org.dave.compactmachines3.misc.ConfigurationHandler; import org.dave.compactmachines3.world.ChunkGeneratorMachines; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; // Courtesy of jchung01 @Mixin(value = ChunkGeneratorMachines.class) public class UTChunkGeneratorMachinesMixin { + @Shadow(remap = false) + @Final + private World world; + /** * Another spot the CM config should control spawns; here for redundancy. + * @reason Control mob spawn based on type + * @author jchung01 */ - @ModifyReturnValue(method = "getPossibleCreatures", at = @At(value = "RETURN")) - private List utCheckAllowedCreatures(List original, EnumCreatureType creatureType, BlockPos pos) + @Overwrite + public List getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos) { if ((creatureType.getPeacefulCreature() && ConfigurationHandler.MachineSettings.allowPeacefulSpawns) || (!creatureType.getPeacefulCreature() && ConfigurationHandler.MachineSettings.allowHostileSpawns)) { - return original; + return this.world.getBiome(pos).getSpawnableList(creatureType); } else return Collections.emptyList(); } diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/spawns/mixin/UTWorldProviderMachinesMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/spawns/mixin/UTWorldProviderMachinesMixin.java index fb6ebc92..eb86a1a7 100644 --- a/src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/spawns/mixin/UTWorldProviderMachinesMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/spawns/mixin/UTWorldProviderMachinesMixin.java @@ -5,7 +5,6 @@ import org.dave.compactmachines3.misc.ConfigurationHandler; import org.dave.compactmachines3.world.WorldProviderMachines; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; // Courtesy of jchung01 @Mixin(value = WorldProviderMachines.class) @@ -15,7 +14,6 @@ public abstract class UTWorldProviderMachinesMixin extends WorldProvider * Let CM config set allowed spawns when the dim loads. * This helps server performance especially when both hostile and peaceful spawns are disabled. */ - @Unique @Override public void setAllowedSpawnTypes(boolean allowHostile, boolean allowPeaceful) {