From eb11d681672e4dc14231bf0f7befec221f6b8f9b Mon Sep 17 00:00:00 2001 From: jchung01 Date: Tue, 13 Aug 2024 10:30:30 -0700 Subject: [PATCH 1/4] Let Compact Machines' config set allowed spawns --- .../universaltweaks/core/UTMixinLoader.java | 4 ++- .../{ => render}/mixin/UTCubeToolsMixin.java | 2 +- .../mixin/UTChunkGeneratorMachinesMixin.java | 33 +++++++++++++++++++ .../mixin/UTWorldProviderMachinesMixin.java | 24 ++++++++++++++ ...> mixins.mods.compactmachines.render.json} | 4 +-- .../mixins.mods.compactmachines.spawns.json | 7 ++++ 6 files changed, 70 insertions(+), 4 deletions(-) rename src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/{ => render}/mixin/UTCubeToolsMixin.java (98%) create mode 100644 src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/spawns/mixin/UTChunkGeneratorMachinesMixin.java create mode 100644 src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/spawns/mixin/UTWorldProviderMachinesMixin.java rename src/main/resources/{mixins.mods.compactmachines.json => mixins.mods.compactmachines.render.json} (77%) create mode 100644 src/main/resources/mixins.mods.compactmachines.spawns.json diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java index 39079fd4..3247a531 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java @@ -19,7 +19,7 @@ public class UTMixinLoader implements ILateMixinLoader { { put("mixins.mods.cbmultipart.client.json", () -> loaded("forgemultipartcbe") && UTConfigMods.CB_MULTIPART.utMemoryLeakFixToggle); - put("mixins.mods.compactmachines.json", () -> loaded("compactmachines3") && UTConfigMods.COMPACT_MACHINES.utCMRenderFixToggle); + put("mixins.mods.compactmachines.render.json", () -> loaded("compactmachines3") && UTConfigMods.COMPACT_MACHINES.utCMRenderFixToggle); put("mixins.mods.crafttweaker.json", () -> loaded("crafttweaker")); put("mixins.mods.hwyla.json", () -> loaded("waila")); put("mixins.mods.modularrouters.json", () -> loaded("modularrouters") && UTConfigMods.MODULAR_ROUTERS.utParticleThreadToggle); @@ -51,6 +51,8 @@ public class UTMixinLoader implements ILateMixinLoader put("mixins.mods.codechickenlib.json", () -> loaded("codechickenlib") && UTConfigMods.CCL.utPacketLeakFixToggle); put("mixins.mods.cofhcore.json", () -> loaded("cofhcore")); put("mixins.mods.collective.json", () -> loaded("collective")); + // TODO: Add config + put("mixins.mods.compactmachines.spawns.json", () -> loaded("compactmachines3")); put("mixins.mods.cqrepoured.json", () -> loaded("cqrepoured")); put("mixins.mods.effortlessbuilding.json", () -> loaded("effortlessbuilding")); put("mixins.mods.elementarystaffs.json", () -> loaded("element")); diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/mixin/UTCubeToolsMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/render/mixin/UTCubeToolsMixin.java similarity index 98% rename from src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/mixin/UTCubeToolsMixin.java rename to src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/render/mixin/UTCubeToolsMixin.java index 5b818097..0bcfe633 100644 --- a/src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/mixin/UTCubeToolsMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/render/mixin/UTCubeToolsMixin.java @@ -1,4 +1,4 @@ -package mod.acgaming.universaltweaks.mods.compactmachines.mixin; +package mod.acgaming.universaltweaks.mods.compactmachines.render.mixin; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; 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 new file mode 100644 index 00000000..32a7e51f --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/spawns/mixin/UTChunkGeneratorMachinesMixin.java @@ -0,0 +1,33 @@ +package mod.acgaming.universaltweaks.mods.compactmachines.spawns.mixin; + +import java.util.Collections; +import java.util.List; + +import net.minecraft.entity.EnumCreatureType; +import net.minecraft.util.math.BlockPos; +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.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +// Courtesy of jchung01 +@Mixin(value = ChunkGeneratorMachines.class) +public class UTChunkGeneratorMachinesMixin +{ + /** + * Another spot the CM config should control spawns; here for redundancy. + */ + @ModifyReturnValue(method = "getPossibleCreatures", at = @At(value = "RETURN")) + private List utCheckAllowedCreatures(List original, EnumCreatureType creatureType, BlockPos pos) + { + if ((creatureType.getPeacefulCreature() && ConfigurationHandler.MachineSettings.allowPeacefulSpawns) || + (!creatureType.getPeacefulCreature() && ConfigurationHandler.MachineSettings.allowHostileSpawns)) + { + return original; + } + 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 new file mode 100644 index 00000000..fb6ebc92 --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/mods/compactmachines/spawns/mixin/UTWorldProviderMachinesMixin.java @@ -0,0 +1,24 @@ +package mod.acgaming.universaltweaks.mods.compactmachines.spawns.mixin; + +import net.minecraft.world.WorldProvider; + +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) +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) + { + super.setAllowedSpawnTypes(ConfigurationHandler.MachineSettings.allowHostileSpawns, ConfigurationHandler.MachineSettings.allowPeacefulSpawns); + } +} diff --git a/src/main/resources/mixins.mods.compactmachines.json b/src/main/resources/mixins.mods.compactmachines.render.json similarity index 77% rename from src/main/resources/mixins.mods.compactmachines.json rename to src/main/resources/mixins.mods.compactmachines.render.json index b64c8c7b..69b2941f 100644 --- a/src/main/resources/mixins.mods.compactmachines.json +++ b/src/main/resources/mixins.mods.compactmachines.render.json @@ -1,7 +1,7 @@ { - "package": "mod.acgaming.universaltweaks.mods.compactmachines.mixin", + "package": "mod.acgaming.universaltweaks.mods.compactmachines.render.mixin", "refmap": "universaltweaks.refmap.json", "minVersion": "0.8", "compatibilityLevel": "JAVA_8", - "mixins": ["UTCubeToolsMixin"] + "client": ["UTCubeToolsMixin"] } \ No newline at end of file diff --git a/src/main/resources/mixins.mods.compactmachines.spawns.json b/src/main/resources/mixins.mods.compactmachines.spawns.json new file mode 100644 index 00000000..82c7d9e7 --- /dev/null +++ b/src/main/resources/mixins.mods.compactmachines.spawns.json @@ -0,0 +1,7 @@ +{ + "package": "mod.acgaming.universaltweaks.mods.compactmachines.spawns.mixin", + "refmap": "universaltweaks.refmap.json", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins": ["UTChunkGeneratorMachinesMixin", "UTWorldProviderMachinesMixin"] +} \ No newline at end of file From 0985e102fb919e19dd9f6c1b1a7e7ce8394b6626 Mon Sep 17 00:00:00 2001 From: jchung01 Date: Tue, 13 Aug 2024 14:45:04 -0700 Subject: [PATCH 2/4] Update configs, readme --- README.md | 1 + .../acgaming/universaltweaks/config/UTConfigMods.java | 10 ++++++++++ .../acgaming/universaltweaks/core/UTMixinLoader.java | 3 +-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 03da0342..c0e67e87 100644 --- a/README.md +++ b/README.md @@ -310,6 +310,7 @@ All changes are toggleable via config files. * **Memory Leak Fix:** Fixes memory leak when unloading worlds/switching dimensions * **Compact Machines** * **Invisible Wall Render Fix:** Fixes some compact machine walls being invisible if [Nothirium](https://www.curseforge.com/minecraft/mc-mods/nothirium) 0.2.x (and up) or [Vintagium](https://github.com/Asek3/sodium-1.12) is installed + * **Allowed Spawns Improvement:** Improves server performance by properly controlling spawn checks (effectiveness depends on CM's config) * **Effortless Building** * **Block Transmutation Fix:** Fixes Effortless Building ignoring Metadata when checking for items in inventory * **Elementary Staffs** diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java index 20a957f3..0cc75935 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java @@ -399,6 +399,16 @@ public static class CompactMachinesCoreCategory @Config.Name("Invisible Wall Render Fix") @Config.Comment("Fixes some compact machine walls being invisible if Nothirium 0.2.x (and up) or Vintagium is installed") public boolean utCMRenderFixToggle = true; + + @Config.RequiresMcRestart + @Config.Name("Allowed Spawns Improvement") + @Config.Comment + ({ + "Improves server performance by properly controlling spawn checks (effectiveness depends on CM's config)", + "Disable both 'allowHostileSpawns' and 'allowPeacefulSpawns' in the CM config for best performance", + "Does nothing if both config values are true" + }) + public boolean utAllowedSpawnsImprovementToggle = true; } public static class EffortlessBuildingCategory diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java index 3247a531..af75bb3a 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java @@ -51,8 +51,7 @@ public class UTMixinLoader implements ILateMixinLoader put("mixins.mods.codechickenlib.json", () -> loaded("codechickenlib") && UTConfigMods.CCL.utPacketLeakFixToggle); put("mixins.mods.cofhcore.json", () -> loaded("cofhcore")); put("mixins.mods.collective.json", () -> loaded("collective")); - // TODO: Add config - put("mixins.mods.compactmachines.spawns.json", () -> loaded("compactmachines3")); + put("mixins.mods.compactmachines.spawns.json", () -> loaded("compactmachines3") && UTConfigMods.COMPACT_MACHINES.utAllowedSpawnsImprovementToggle); put("mixins.mods.cqrepoured.json", () -> loaded("cqrepoured")); put("mixins.mods.effortlessbuilding.json", () -> loaded("effortlessbuilding")); put("mixins.mods.elementarystaffs.json", () -> loaded("element")); From d8ef4d53cea53bc1bfe29b10771c68d1dcd697c7 Mon Sep 17 00:00:00 2001 From: jchung01 Date: Tue, 13 Aug 2024 14:56:18 -0700 Subject: [PATCH 3/4] Add BedPatch to obsolete mods --- .../universaltweaks/util/compat/UTObsoleteModsHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/mod/acgaming/universaltweaks/util/compat/UTObsoleteModsHandler.java b/src/main/java/mod/acgaming/universaltweaks/util/compat/UTObsoleteModsHandler.java index 37f88113..0c9f3e3a 100644 --- a/src/main/java/mod/acgaming/universaltweaks/util/compat/UTObsoleteModsHandler.java +++ b/src/main/java/mod/acgaming/universaltweaks/util/compat/UTObsoleteModsHandler.java @@ -27,6 +27,7 @@ public class UTObsoleteModsHandler put("bannerpatch", () -> UTConfigBugfixes.BLOCKS.utBannerBoundingBoxToggle); put("bedbreakbegone", () -> UTConfigTweaks.BLOCKS.utBedObstructionToggle); put("bedfix", () -> UTConfigTweaks.ENTITIES.SLEEPING.utSleepingTime != -1); + put("bedpatch", () -> true); // Fix integrated in Forge 14.23.2.2643 (#4784) put("bedsaynosleep", () -> UTConfigTweaks.ENTITIES.SLEEPING.utDisableSleepingToggle); put("betterburning", () -> UTConfigTweaks.ENTITIES.BETTER_BURNING.utBBArrowsToggle || UTConfigTweaks.ENTITIES.BETTER_BURNING.utBBCookedToggle || UTConfigTweaks.ENTITIES.BETTER_BURNING.utBBExtinguishToggle || UTConfigTweaks.ENTITIES.BETTER_BURNING.utBBOverlayToggle || UTConfigTweaks.ENTITIES.BETTER_BURNING.utBBSpreadingToggle); put("betterpingdisplay", () -> UTConfigTweaks.MISC.utBetterPing); @@ -158,7 +159,7 @@ public static List obsoleteModsMessage() } // Mods checked by class - if (UTReflectionUtil.isClassLoaded("com.chocohead.biab.BornInABarn")) messages.add("Born in a Barn"); + if (UTReflectionUtil.isClassLoaded("com.chocohead.biab.BornInABarn")) messages.add("Born in a Barn"); // Fix integrated in Forge 14.23.2.2623 (#4689) if (UTReflectionUtil.isClassLoaded("io.github.jikuja.LocaleTweaker") && UTConfigBugfixes.MISC.utLocaleToggle) messages.add("LocaleFixer"); if (UTReflectionUtil.isClassLoaded("com.cleanroommc.blockdelayremover.BlockDelayRemoverCore") && UTConfigTweaks.BLOCKS.utBlockHitDelay != 5) messages.add("Block Delay Remover"); if (UTReflectionUtil.isClassLoaded("io.github.barteks2x.chunkgenlimiter.ChunkGenLimitMod") && UTConfigTweaks.WORLD.CHUNK_GEN_LIMIT.utChunkGenLimitToggle) messages.add("Chunk Generation Limiter"); From e3e265a03d6f352dcbd54e187bb0336070387917 Mon Sep 17 00:00:00 2001 From: jchung01 Date: Fri, 23 Aug 2024 20:13:23 -0700 Subject: [PATCH 4/4] 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) {