From 895a1acf3c3028b0ab9cc1ea897546727e23773a Mon Sep 17 00:00:00 2001 From: Fourmisain <8464472+Fourmisain@users.noreply.github.com> Date: Fri, 6 Dec 2024 22:46:48 +0100 Subject: [PATCH] port to 1.21.4: - add option to change the vanilla spawn rate of pale oak leaf particles - only use vanilla particles for cherry and pale oak by default --- gradle.properties | 16 ++--- .../fallingleaves/config/ConfigDefaults.java | 5 ++ .../config/FallingLeavesConfig.java | 9 +++ .../mixin/CherryLeavesBlockMixin.java | 32 --------- .../mixin/ParticleLeavesBlockMixin.java | 66 +++++++++++++++++++ .../fallingleaves/util/LeafUtil.java | 7 +- .../assets/fallingleaves/lang/de_de.json | 2 + .../assets/fallingleaves/lang/en_us.json | 2 + src/main/resources/fallingleaves.mixins.json | 2 +- 9 files changed, 99 insertions(+), 42 deletions(-) delete mode 100644 src/main/java/randommcsomethin/fallingleaves/mixin/CherryLeavesBlockMixin.java create mode 100644 src/main/java/randommcsomethin/fallingleaves/mixin/ParticleLeavesBlockMixin.java diff --git a/gradle.properties b/gradle.properties index fd1325d..4d490b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,9 @@ org.gradle.warning.mode=all # Fabric Properties # check these on https://fabricmc.net/versions.html -minecraft_version=1.21.2 -yarn_mappings=1.21.2+build.1 -loader_version=0.16.7 +minecraft_version=1.21.4 +yarn_mappings=1.21.4+build.1 +loader_version=0.16.9 # Mod Properties mod_version=1.16.4 @@ -16,17 +16,17 @@ archives_base_name=fallingleaves # Dependencies java_version=21 -fabric_api_version=0.106.1+1.21.2 -cloth_config_version=16.0.141 -modmenu_version=12.0.0-beta.1 +fabric_api_version=0.111.0+1.21.4 +cloth_config_version=17.0.142 +modmenu_version=13.0.0-beta.1 fabric_seasons_version=2.4.2-BETA+1.21 serene_seasons_version=S5y2NO2L # Publishing modrinth_id=WhbRG4iK curseforge_id=417510 -game_version_range=>=1.21.2 -game_version_list=1.21.2 +game_version_range=>=1.21.4 +game_version_list=1.21.4 modrinth_dependencies=P7dR8mSH, 9s6osm5g modrinth_optional_dependencies=mOgUt4GM curseforge_dependencies=fabric-api, cloth-config diff --git a/src/main/java/randommcsomethin/fallingleaves/config/ConfigDefaults.java b/src/main/java/randommcsomethin/fallingleaves/config/ConfigDefaults.java index d388a90..cf48f93 100644 --- a/src/main/java/randommcsomethin/fallingleaves/config/ConfigDefaults.java +++ b/src/main/java/randommcsomethin/fallingleaves/config/ConfigDefaults.java @@ -34,6 +34,11 @@ public static boolean isConifer(Identifier blockId) { public static double spawnRateFactor(Identifier blockId) { switch (blockId.toString()) { + // Vanilla leaf/petal particles + case "minecraft:cherry_leaves": + case "minecraft:pale_oak_leaves": + return 0.0; + // Shrubs and large leaved trees case "byg:palm_leaves": case "minecraft:jungle_leaves": diff --git a/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java b/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java index b0a58b4..4f6d856 100644 --- a/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java +++ b/src/main/java/randommcsomethin/fallingleaves/config/FallingLeavesConfig.java @@ -75,6 +75,15 @@ public double getCherrySpawnRateFactor() { return cherrySpawnRate / 20.0; } + @ConfigEntry.Category("fallingleaves.general") + @ConfigEntry.Gui.Tooltip + @ConfigEntry.BoundedDiscrete(max = 20) + public int paleOakSpawnRate = 10; + + public double getPaleOakSpawnRateFactor() { + return paleOakSpawnRate / 20.0; + } + @ConfigEntry.Category("fallingleaves.general") @ConfigEntry.Gui.Tooltip @ConfigEntry.BoundedDiscrete(max = 40) diff --git a/src/main/java/randommcsomethin/fallingleaves/mixin/CherryLeavesBlockMixin.java b/src/main/java/randommcsomethin/fallingleaves/mixin/CherryLeavesBlockMixin.java deleted file mode 100644 index 1ebb720..0000000 --- a/src/main/java/randommcsomethin/fallingleaves/mixin/CherryLeavesBlockMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package randommcsomethin.fallingleaves.mixin; - -import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import net.minecraft.block.CherryLeavesBlock; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; - -import static randommcsomethin.fallingleaves.init.Config.CONFIG; - -@Mixin(CherryLeavesBlock.class) -public abstract class CherryLeavesBlockMixin { - @ModifyExpressionValue( - method = "randomDisplayTick", - at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/random/Random;nextInt(I)I") - ) - public int disableIfRateIsZero(int original) { - if (CONFIG.cherrySpawnRate == 0) - return -1; - return original; - } - - @ModifyArg( - method = "randomDisplayTick", - at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/random/Random;nextInt(I)I") - ) - public int modifySpawnRate(int bound) { - int newBound = (int) (bound / CONFIG.getCherrySpawnRateFactor()); - // make sure to not return 0, in case bound has changed - return Math.max(1, newBound); - } -} diff --git a/src/main/java/randommcsomethin/fallingleaves/mixin/ParticleLeavesBlockMixin.java b/src/main/java/randommcsomethin/fallingleaves/mixin/ParticleLeavesBlockMixin.java new file mode 100644 index 0000000..216a1cd --- /dev/null +++ b/src/main/java/randommcsomethin/fallingleaves/mixin/ParticleLeavesBlockMixin.java @@ -0,0 +1,66 @@ +package randommcsomethin.fallingleaves.mixin; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.ParticleLeavesBlock; +import net.minecraft.particle.ParticleEffect; +import net.minecraft.registry.Registries; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import static randommcsomethin.fallingleaves.init.Config.CONFIG; +import static randommcsomethin.fallingleaves.util.LeafUtil.CHERRY_LEAVES_PARTICLE_ID; +import static randommcsomethin.fallingleaves.util.LeafUtil.PALE_OAK_LEAVES_PARTICLE_ID; + +@Mixin(ParticleLeavesBlock.class) +public abstract class ParticleLeavesBlockMixin { + @Unique + private Identifier particleId = null; + + @Inject(method = "", at = @At("RETURN")) + public void getParticleTypeId(int chance, ParticleEffect particle, AbstractBlock.Settings settings, CallbackInfo ci) { + particleId = Registries.PARTICLE_TYPE.getId(particle.getType()); + } + + @ModifyExpressionValue( + method = "randomDisplayTick", + at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/random/Random;nextInt(I)I") + ) + public int disableIfRateIsZero(int original) { + if (!CONFIG.enabled) + return original; + + if (CONFIG.cherrySpawnRate == 0 && particleId.equals(CHERRY_LEAVES_PARTICLE_ID)) + return -1; + + if (CONFIG.paleOakSpawnRate == 0 && particleId.equals(PALE_OAK_LEAVES_PARTICLE_ID)) + return -1; + + return original; + } + + @ModifyArg( + method = "randomDisplayTick", + at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/random/Random;nextInt(I)I") + ) + public int modifySpawnRate(int bound) { + if (!CONFIG.enabled) + return bound; + + int newBound = bound; + + if (particleId.equals(CHERRY_LEAVES_PARTICLE_ID)) { + newBound = (int) (bound / CONFIG.getCherrySpawnRateFactor()); + } else if (particleId.equals(PALE_OAK_LEAVES_PARTICLE_ID)) { + newBound = (int) (bound / CONFIG.getPaleOakSpawnRateFactor()); + } + + // make sure to not return 0, in case bound has changed + return Math.max(1, newBound); + } +} diff --git a/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java b/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java index 0c42b75..b1d1c59 100644 --- a/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java +++ b/src/main/java/randommcsomethin/fallingleaves/util/LeafUtil.java @@ -9,6 +9,8 @@ import net.minecraft.client.texture.Sprite; import net.minecraft.client.texture.SpriteContents; import net.minecraft.particle.BlockStateParticleEffect; +import net.minecraft.particle.ParticleType; +import net.minecraft.particle.ParticleTypes; import net.minecraft.registry.Registries; import net.minecraft.registry.tag.BlockTags; import net.minecraft.util.Identifier; @@ -40,6 +42,9 @@ public class LeafUtil { + public static final Identifier CHERRY_LEAVES_PARTICLE_ID = Identifier.ofVanilla("cherry_leaves"); + public static final Identifier PALE_OAK_LEAVES_PARTICLE_ID = Identifier.ofVanilla("pale_oak_leaves"); + private static final Random renderRandom = Random.createLocal(); public static double getModifiedSpawnChance(BlockState state, LeafSettingsEntry leafSettings) { @@ -187,7 +192,7 @@ public static double[] getBlockTextureColor(BlockState state, World world, Block BakedQuad quad = quads.get(useFirstQuad ? 0 : quads.size() - 1); sprite = quad.getSprite(); - shouldColor = quad.hasColor(); + shouldColor = quad.hasTint(); } else { // fall back to block breaking particle sprite = model.getParticleSprite(); diff --git a/src/main/resources/assets/fallingleaves/lang/de_de.json b/src/main/resources/assets/fallingleaves/lang/de_de.json index e42ee03..d0b4664 100644 --- a/src/main/resources/assets/fallingleaves/lang/de_de.json +++ b/src/main/resources/assets/fallingleaves/lang/de_de.json @@ -8,6 +8,8 @@ "text.autoconfig.fallingleaves.option.leafSpawnRate.@Tooltip": "Wieviele Blätter über Zeit spawnen", "text.autoconfig.fallingleaves.option.cherrySpawnRate": "Kirschblüten-Spawnrate", "text.autoconfig.fallingleaves.option.cherrySpawnRate.@Tooltip": "Ändert die vanilla Kirschblüten-Spawnrate in 10%-Faktoren, d.h.\n5 = 50% (halbe Rate)\n10 = 100% (originale Rate)\n20 = 200% (doppelte Rate)", + "text.autoconfig.fallingleaves.option.paleOakSpawnRate": "Blasseichen-Spawnrate", + "text.autoconfig.fallingleaves.option.paleOakSpawnRate.@Tooltip": "Ändert die vanilla Blasseichen-Spawnrate in 10%-Faktoren, d.h.\n5 = 50% (halbe Rate)\n10 = 100% (originale Rate)\n20 = 200% (doppelte Rate)", "text.autoconfig.fallingleaves.option.coniferLeafSpawnRate": "Nadelblatt-Spawnrate", "text.autoconfig.fallingleaves.option.coniferLeafSpawnRate.@Tooltip": "Wieviele Nadelblätter über Zeit spawnen", "text.autoconfig.fallingleaves.option.snowflakeSpawnRate": "Schneeflock-Spawnrate", diff --git a/src/main/resources/assets/fallingleaves/lang/en_us.json b/src/main/resources/assets/fallingleaves/lang/en_us.json index 186fc82..13a8fe7 100644 --- a/src/main/resources/assets/fallingleaves/lang/en_us.json +++ b/src/main/resources/assets/fallingleaves/lang/en_us.json @@ -8,6 +8,8 @@ "text.autoconfig.fallingleaves.option.leafSpawnRate.@Tooltip": "How many leaves spawn over time", "text.autoconfig.fallingleaves.option.cherrySpawnRate": "Cherry Petals Spawn Rate", "text.autoconfig.fallingleaves.option.cherrySpawnRate.@Tooltip": "Changes the vanilla cherry petals spawn rate in factors of 10%, i.e.\n5 = 50% (half rate)\n10 = 100% (original rate)\n20 = 200% (double rate)", + "text.autoconfig.fallingleaves.option.paleOakSpawnRate": "Pale Oak Leaves Spawn Rate", + "text.autoconfig.fallingleaves.option.paleOakSpawnRate.@Tooltip": "Changes the vanilla Pale Oak leaves spawn rate in factors of 10%, i.e.\n5 = 50% (half rate)\n10 = 100% (original rate)\n20 = 200% (double rate)", "text.autoconfig.fallingleaves.option.coniferLeafSpawnRate": "Conifer Leaf Spawn Rate", "text.autoconfig.fallingleaves.option.coniferLeafSpawnRate.@Tooltip": "How many conifer leaves spawn over time", "text.autoconfig.fallingleaves.option.snowflakeSpawnRate": "Snowflake Spawn Rate", diff --git a/src/main/resources/fallingleaves.mixins.json b/src/main/resources/fallingleaves.mixins.json index 3b67a49..5026079 100644 --- a/src/main/resources/fallingleaves.mixins.json +++ b/src/main/resources/fallingleaves.mixins.json @@ -6,7 +6,7 @@ "plugin": "randommcsomethin.fallingleaves.init.MixinConfig", "client": [ "BlockMixin", - "CherryLeavesBlockMixin", + "ParticleLeavesBlockMixin", "ClientPlayNetworkHandlerMixin", "GsonConfigSerializerMixin", "LeafTickMixin",