Skip to content

Commit

Permalink
port to 1.21.4:
Browse files Browse the repository at this point in the history
 - add option to change the vanilla spawn rate of pale oak leaf particles
 - only use vanilla particles for cherry and pale oak by default
  • Loading branch information
Fourmisain committed Dec 6, 2024
1 parent e6da286 commit 895a1ac
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 42 deletions.
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 = "<init>", 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/fallingleaves/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/fallingleaves/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fallingleaves.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"plugin": "randommcsomethin.fallingleaves.init.MixinConfig",
"client": [
"BlockMixin",
"CherryLeavesBlockMixin",
"ParticleLeavesBlockMixin",
"ClientPlayNetworkHandlerMixin",
"GsonConfigSerializerMixin",
"LeafTickMixin",
Expand Down

0 comments on commit 895a1ac

Please sign in to comment.