From 9637c271590981679e02850e0f1f9d3c82f7345a Mon Sep 17 00:00:00 2001 From: FalsePattern Date: Mon, 9 Jun 2025 13:36:17 +0200 Subject: [PATCH] Just Another Spawner compat #201 --- README.MD | 1 + build.gradle.kts | 3 + .../biome/jas/LegacyCreatureTypeMixin.java | 65 +++++++++++++++++++ .../biome/jas/ModernCreatureTypeMixin.java | 65 +++++++++++++++++++ .../endlessids/mixin/plugin/Mixin.java | 4 ++ .../endlessids/mixin/plugin/TargetedMod.java | 1 + 6 files changed, 139 insertions(+) create mode 100644 src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/jas/LegacyCreatureTypeMixin.java create mode 100644 src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/jas/ModernCreatureTypeMixin.java diff --git a/README.MD b/README.MD index 2862457..26254fd 100644 --- a/README.MD +++ b/README.MD @@ -83,6 +83,7 @@ This mod also contains patches for the following mods: - Highlands - Immersive Cavegen - Industrial Revolution by Redstone Rebooted +- Just Another Spawner - Matter Overdrive - More Fun Quicksand Mod - Nature's Compass diff --git a/build.gradle.kts b/build.gradle.kts index bf147c0..ebb8628 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -175,6 +175,9 @@ dependencies { //Industrial Revolution by Redstone Rebooted 1.1.1 compileOnly(deobfCurse("industrialrevolutionbyredstonerebooted-241812:2538035")) + //Just Another Spawner 0.17.9 + compileOnly(deobfCurse("justanotherspawner-228952:2380961")) + //LOTR Mod 36.15 compileOnly(deobfCurse("lotrmod-423748:4091561")) diff --git a/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/jas/LegacyCreatureTypeMixin.java b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/jas/LegacyCreatureTypeMixin.java new file mode 100644 index 0000000..060bf10 --- /dev/null +++ b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/jas/LegacyCreatureTypeMixin.java @@ -0,0 +1,65 @@ +/* + * EndlessIDs + * + * Copyright (C) 2022-2025 FalsePattern, The MEGA Team + * All Rights Reserved + * + * The above copyright notice, this permission notice and the word "MEGA" + * shall be included in all copies or substantial portions of the Software. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, only version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.falsepattern.endlessids.mixin.mixins.common.biome.jas; + +import com.falsepattern.endlessids.constants.ExtendedConstants; +import com.falsepattern.endlessids.mixin.helpers.ChunkBiomeHook; +import com.google.common.collect.ImmutableMap; +import jas.spawner.legacy.spawner.creature.type.CreatureType; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import net.minecraft.world.chunk.Chunk; + +@Mixin(CreatureType.class) +public class LegacyCreatureTypeMixin { + @Shadow(remap = false) @Final public int defaultBiomeCap; + + @Shadow(remap = false) @Final public ImmutableMap biomeCaps; + + /** + * @author FalsePattern + * @reason Painful to do with normal injects because of control flow + */ + @Overwrite(remap = false) + public int getChunkCap(Chunk chunk) { + if (chunk != null && this.defaultBiomeCap > 0) { + int chunkCap = 0; + int counter = 0; + short[] biomeArray = ((ChunkBiomeHook)chunk).getBiomeShortArray(); + + for (short value : biomeArray) { + int biomeID = value & ExtendedConstants.biomeIDMask; + int columnCap = this.biomeCaps.getOrDefault(biomeID, defaultBiomeCap); + chunkCap += columnCap; + ++counter; + } + + return counter > 0 ? chunkCap / counter : -1; + } else { + return -1; + } + } +} diff --git a/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/jas/ModernCreatureTypeMixin.java b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/jas/ModernCreatureTypeMixin.java new file mode 100644 index 0000000..7a91268 --- /dev/null +++ b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/biome/jas/ModernCreatureTypeMixin.java @@ -0,0 +1,65 @@ +/* + * EndlessIDs + * + * Copyright (C) 2022-2025 FalsePattern, The MEGA Team + * All Rights Reserved + * + * The above copyright notice, this permission notice and the word "MEGA" + * shall be included in all copies or substantial portions of the Software. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, only version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.falsepattern.endlessids.mixin.mixins.common.biome.jas; + +import com.falsepattern.endlessids.constants.ExtendedConstants; +import com.falsepattern.endlessids.mixin.helpers.ChunkBiomeHook; +import com.google.common.collect.ImmutableMap; +import jas.spawner.modern.spawner.creature.type.CreatureType; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import net.minecraft.world.chunk.Chunk; + +@Mixin(CreatureType.class) +public class ModernCreatureTypeMixin { + @Shadow(remap = false) @Final public int defaultBiomeCap; + + @Shadow(remap = false) @Final public ImmutableMap biomeCaps; + + /** + * @author FalsePattern + * @reason Painful to do with normal injects because of control flow + */ + @Overwrite(remap = false) + public int getChunkCap(Chunk chunk) { + if (chunk != null && this.defaultBiomeCap > 0) { + int chunkCap = 0; + int counter = 0; + short[] biomeArray = ((ChunkBiomeHook)chunk).getBiomeShortArray(); + + for (short value : biomeArray) { + int biomeID = value & ExtendedConstants.biomeIDMask; + int columnCap = this.biomeCaps.getOrDefault(biomeID, defaultBiomeCap); + chunkCap += columnCap; + ++counter; + } + + return counter > 0 ? chunkCap / counter : -1; + } else { + return -1; + } + } +} diff --git a/src/main/java/com/falsepattern/endlessids/mixin/plugin/Mixin.java b/src/main/java/com/falsepattern/endlessids/mixin/plugin/Mixin.java index 9a289a9..ad62736 100644 --- a/src/main/java/com/falsepattern/endlessids/mixin/plugin/Mixin.java +++ b/src/main/java/com/falsepattern/endlessids/mixin/plugin/Mixin.java @@ -171,6 +171,10 @@ public enum Mixin implements IMixin { //region Industrial Revolution by Redstone Rebooted IR3IR2Mixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.IR3)), "biome.ir3.IR2Mixin"), //endregion Industrial Revolution by Redstone Rebooted + //region Just Another Spawner + LegacyCreatureTypeMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.JAS)), "biome.jas.LegacyCreatureTypeMixin"), + ModernCreatureTypeMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.JAS)), "biome.jas.ModernCreatureTypeMixin"), + //endregion //region LOTR LOTRBiomeVariantStorageMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.LOTR)), "biome.lotr.LOTRBiomeVariantStorageMixin"), LOTRChunkProviderMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.LOTR)), "biome.lotr.LOTRChunkProviderMixin"), diff --git a/src/main/java/com/falsepattern/endlessids/mixin/plugin/TargetedMod.java b/src/main/java/com/falsepattern/endlessids/mixin/plugin/TargetedMod.java index b2bc86e..408e265 100644 --- a/src/main/java/com/falsepattern/endlessids/mixin/plugin/TargetedMod.java +++ b/src/main/java/com/falsepattern/endlessids/mixin/plugin/TargetedMod.java @@ -63,6 +63,7 @@ public enum TargetedMod implements ITargetedMod { HIGHLANDS("Highlands", false, contains("highlands")), ICG("Immersive Cavegen", false, contains("immersivecavegen")), IR3("Industrial Revolution by Redstone Rebooted", false, contains("industrialrevolutionbyredstonerebooted-")), + JAS("Just Another Spawner", false, contains("justanotherspawner-")), LOTR("LOTR Mod", false, contains("lotrmod")), MATTEROVERDRIVE("Matter Overdrive", false, contains("matteroverdrive-")), MATTERMEGADRIVE("Matter Megadrive", false, contains("mattermegadrive-")),