Skip to content

Commit

Permalink
Use Overwrite to avoid original computation
Browse files Browse the repository at this point in the history
  • Loading branch information
jchung01 committed Aug 24, 2024
1 parent d8ef4d5 commit e3e265a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Biome.SpawnListEntry> utCheckAllowedCreatures(List<Biome.SpawnListEntry> original, EnumCreatureType creatureType, BlockPos pos)
@Overwrite
public List<Biome.SpawnListEntry> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down

0 comments on commit e3e265a

Please sign in to comment.