Skip to content

Commit

Permalink
Update 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
NemoNotFound committed Nov 13, 2024
1 parent c459273 commit ff16e98
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 27 deletions.
9 changes: 7 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog v1.3
# Changelog v1.4

## Additions
- Added falling leaf particles for pale oak leaves
- Added tag "drops_falling_leaves"
- If you want to add leaf particles to your leaf blocks, add your block to the tag
- Works only for grey texture, since the color will be set (will be adapted in the future)

## Changes
- Falling leaves particles now stay on ground for a bit
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=24w44a+build.1
loader_version=0.16.9

# Mod Properties
mod_version=1.3
mod_version=1.4
maven_group=com.nemonotfound
archives_base_name=nemos-ambience

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nemonotfound.nemosambience;

import com.nemonotfound.nemosambience.client.particle.ModParticles;
import com.nemonotfound.nemosambience.tag.ModBlockTags;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -14,5 +15,6 @@ public class NemosAmbience implements ModInitializer {
public void onInitialize() {
log.info("Thanks for using Nemo's Ambience!");
ModParticles.registerParticles();
ModBlockTags.register();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.nemonotfound.nemosambience;

import com.nemonotfound.nemosambience.client.particle.LeavesParticle;
import com.nemonotfound.nemosambience.client.particle.FallingLeavesParticle;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.particle.v1.FabricSpriteProvider;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
Expand All @@ -19,6 +19,6 @@ private void registerParticle(SimpleParticleType particleType) {
ParticleFactoryRegistry.getInstance()
.register(particleType, (FabricSpriteProvider spriteProvider) ->
(parameters, world, x, y, z, velocityX, velocityY, velocityZ) ->
new LeavesParticle(world, x, y, z, spriteProvider));
new FallingLeavesParticle(world, x, y, z, spriteProvider));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
import net.minecraft.world.biome.FoliageColors;

@Environment(value = EnvType.CLIENT)
public class LeavesParticle
public class FallingLeavesParticle
extends SpriteBillboardParticle {

private float rotSpeed;
private final float particleRandom;
private final float spinAcceleration;

public LeavesParticle(ClientWorld world, double x, double y, double z, SpriteProvider spriteProvider) {
public FallingLeavesParticle(ClientWorld world, double x, double y, double z, SpriteProvider spriteProvider) {
super(world, x, y, z);
float f;
this.setSprite(spriteProvider.getSprite(this.random.nextInt(12), 12));
Expand All @@ -47,7 +47,6 @@ private void setParticleColor(ClientWorld world) {
float blue = (color & 0xFF) / 255.0f;

this.setColor(red, green, blue);

}

private int getFoliageColor(ClientWorld world, BlockPos pos, String leavesName) {
Expand Down Expand Up @@ -90,7 +89,7 @@ public void tick() {
this.prevAngle = this.angle;
this.angle += this.rotSpeed / 20.0f;
this.move(this.velocityX, this.velocityY, this.velocityZ);
if (this.onGround || this.maxAge < 299 && (this.velocityX == 0.0 || this.velocityZ == 0.0)) {
if (this.maxAge < 299 && (this.velocityX == 0.0 || this.velocityZ == 0.0)) {
this.markDead();
}
if (this.dead) {
Expand All @@ -99,6 +98,13 @@ public void tick() {
this.velocityX *= this.velocityMultiplier;
this.velocityY *= this.velocityMultiplier;
this.velocityZ *= this.velocityMultiplier;

if (this.onGround) {
this.velocityX = 0;
this.velocityY = 0;
this.velocityZ = 0;
this.rotSpeed = 0;
}
}
}

Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.nemonotfound.nemosambience.mixin;

import com.nemonotfound.nemosambience.tag.ModBlockTags;
import net.minecraft.block.BlockState;
import net.minecraft.block.LeavesBlock;
import net.minecraft.particle.ParticleUtil;
import net.minecraft.particle.SimpleParticleType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
Expand All @@ -16,32 +14,23 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static com.nemonotfound.nemosambience.client.particle.ModParticles.*;
import static com.nemonotfound.nemosambience.client.particle.ModParticles.FALLING_LEAVES_PARTICLE;


@Mixin(LeavesBlock.class)
public class LeavesBlockMixin {

@Inject(at = @At("HEAD"), method = "randomDisplayTick")
private void init(BlockState state, World world, BlockPos pos, Random random, CallbackInfo ci) {
String leavesName = Registries.BLOCK.getId(state.getBlock()).getPath();
boolean isLeavesBlock = state.getRegistryEntry().isIn(BlockTags.LEAVES);
boolean shouldBlockDropLeaves = state.getRegistryEntry().isIn(ModBlockTags.DROPS_FALLING_LEAVES);

if (isLeavesBlock) {
generateLeafParticles(world, pos, random, leavesName);
if (shouldBlockDropLeaves) {
generateParticles(world, pos, random);
}
}

@Unique
private void generateLeafParticles(World world, BlockPos pos, Random random, String leavesName) {
switch (leavesName) {
case "oak_leaves", "dark_oak_leaves", "birch_leaves", "spruce_leaves", "jungle_leaves", "mangrove_leaves",
"acacia_leaves" -> generateParticles(world, pos, random, FALLING_LEAVES_PARTICLE);
}
}

@Unique
private void generateParticles(World world, BlockPos pos, Random random, SimpleParticleType particleType) {
private void generateParticles(World world, BlockPos pos, Random random) {
if (random.nextInt(20) == 0) {
BlockPos blockPos = pos.down();
BlockState blockState = world.getBlockState(blockPos);
Expand All @@ -50,7 +39,7 @@ private void generateParticles(World world, BlockPos pos, Random random, SimpleP
return;
}

ParticleUtil.spawnParticle(world, pos, random, particleType);
ParticleUtil.spawnParticle(world, pos, random, FALLING_LEAVES_PARTICLE);
}
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/nemonotfound/nemosambience/tag/ModBlockTags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.nemonotfound.nemosambience.tag;

import net.minecraft.block.Block;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;

import static com.nemonotfound.nemosambience.NemosAmbience.MOD_ID;
import static com.nemonotfound.nemosambience.NemosAmbience.log;

public class ModBlockTags {

public static final TagKey<Block> DROPS_FALLING_LEAVES = TagKey.of(RegistryKeys.BLOCK, Identifier.of(MOD_ID, "drops_falling_leaves"));

public static void register() {
log.info("Registering block tags");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"values": [
"minecraft:jungle_leaves",
"minecraft:oak_leaves",
"minecraft:spruce_leaves",
"minecraft:dark_oak_leaves",
"minecraft:acacia_leaves",
"minecraft:birch_leaves",
"minecraft:azalea_leaves",
"minecraft:flowering_azalea_leaves",
"minecraft:mangrove_leaves"
]
}

0 comments on commit ff16e98

Please sign in to comment.