Skip to content

Commit

Permalink
Make particles in sakura groves and carnelian treeways spawn from lea…
Browse files Browse the repository at this point in the history
…ves (#169)
  • Loading branch information
Hugman76 authored Mar 5, 2024
2 parents a20ad18 + 0ef0d43 commit d60f8f9
Show file tree
Hide file tree
Showing 16 changed files with 186 additions and 39 deletions.
12 changes: 9 additions & 3 deletions src/main/java/fr/hugman/promenade/PromenadeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import fr.hugman.promenade.client.render.entity.DuckRenderer;
import fr.hugman.promenade.client.render.entity.LushCreeperRenderer;
import fr.hugman.promenade.client.render.entity.SunkenSkeletonRenderer;
import fr.hugman.promenade.particle.FallingLeafParticle;
import fr.hugman.promenade.particle.FloatingParticle;
import fr.hugman.promenade.registry.content.*;
import net.fabricmc.api.ClientModInitializer;
Expand All @@ -20,6 +21,8 @@
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.client.color.world.FoliageColors;
import net.minecraft.client.color.world.GrassColors;
import net.minecraft.client.particle.CherryLeavesParticle;
import net.minecraft.client.particle.SpriteProvider;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.item.BlockItem;

Expand All @@ -33,9 +36,12 @@ public void onInitializeClient() {
PromenadeClient.registerItemColors();
PromenadeClient.registerEntityRenderers();

ParticleFactoryRegistry.getInstance().register(SakuraContent.BLUSH_SAKURA_BLOSSOM, FloatingParticle.BlossomFactory::new);
ParticleFactoryRegistry.getInstance().register(SakuraContent.COTTON_SAKURA_BLOSSOM, FloatingParticle.BlossomFactory::new);
ParticleFactoryRegistry.getInstance().register(MapleContent.MAPLE_LEAF, FloatingParticle.MapleLeafFactory::new);
ParticleFactoryRegistry.getInstance().register(SakuraContent.BLUSH_SAKURA_BLOSSOM, FallingLeafParticle.BlossomFactory::new);
ParticleFactoryRegistry.getInstance().register(SakuraContent.COTTON_SAKURA_BLOSSOM, FallingLeafParticle.BlossomFactory::new);

ParticleFactoryRegistry.getInstance().register(MapleContent.MIKADO_MAPLE_LEAF, FallingLeafParticle.MapleLeafFactory::new);
ParticleFactoryRegistry.getInstance().register(MapleContent.FULVOUS_MAPLE_LEAF, FallingLeafParticle.MapleLeafFactory::new);
ParticleFactoryRegistry.getInstance().register(MapleContent.VERMILION_MAPLE_LEAF, FallingLeafParticle.MapleLeafFactory::new);

ClientRegistrar.add(SakuraContent.SAKURA_SIGNS);
ClientRegistrar.add(SakuraContent.SAKURA_BOAT_TYPE);
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/fr/hugman/promenade/PromenadeFactory.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package fr.hugman.promenade;

import fr.hugman.dawn.DawnFactory;
import fr.hugman.dawn.block.DawnBlockSettings;
import fr.hugman.dawn.item.DawnItemSettings;
import fr.hugman.promenade.block.CarpetedGrassBlock;
import fr.hugman.promenade.block.DecoratedLeavesBlock;
import fr.hugman.promenade.block.PileBlock;
import fr.hugman.promenade.block.SnowyLeavesBlock;
import fr.hugman.promenade.registry.content.GlaglaglaContent;
import net.minecraft.block.Block;
import net.minecraft.block.LeavesBlock;
import net.minecraft.block.MapColor;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.entity.EntityType;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.sound.BlockSoundGroup;

public final class PromenadeFactory {
Expand Down Expand Up @@ -65,4 +69,20 @@ public static SnowyLeavesBlock snowyLeaves(BlockSoundGroup soundGroup) {
.pistonBehavior(PistonBehavior.DESTROY)
.solidBlock((state, world, pos) -> false));
}

public static DecoratedLeavesBlock decoratedLeaves(MapColor mapColor, BlockSoundGroup soundGroup, int bound, ParticleEffect particle) {
return new DecoratedLeavesBlock(DawnFactory.leavesSettings(mapColor, soundGroup), bound, particle);
}

public static DecoratedLeavesBlock decoratedLeaves(MapColor mapColor, BlockSoundGroup soundGroup, ParticleEffect particle) {
return decoratedLeaves(mapColor, soundGroup, 10, particle);
}

public static DecoratedLeavesBlock decoratedLeaves(MapColor mapColor, int bound, ParticleEffect particle) {
return decoratedLeaves(mapColor, BlockSoundGroup.GRASS, bound, particle);
}

public static DecoratedLeavesBlock decoratedLeaves(MapColor mapColor, ParticleEffect particle) {
return decoratedLeaves(mapColor, BlockSoundGroup.GRASS, 10, particle);
}
}
36 changes: 36 additions & 0 deletions src/main/java/fr/hugman/promenade/block/DecoratedLeavesBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package fr.hugman.promenade.block;

import net.minecraft.block.BlockState;
import net.minecraft.block.CherryLeavesBlock;
import net.minecraft.block.LeavesBlock;
import net.minecraft.client.util.ParticleUtil;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;

public class DecoratedLeavesBlock extends LeavesBlock {
private final int bound;
private final ParticleEffect particle;

public DecoratedLeavesBlock(Settings settings, int bound, ParticleEffect particle) {
super(settings);
this.bound = bound;
this.particle = particle;
}

@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
super.randomDisplayTick(state, world, pos, random);
if (random.nextInt(this.bound) != 0) {
return;
}
BlockPos blockPos = pos.down();
BlockState blockState = world.getBlockState(blockPos);
if (CherryLeavesBlock.isFaceFullSquare(blockState.getCollisionShape(world, blockPos), Direction.UP)) {
return;
}
ParticleUtil.spawnParticle(world, pos, random, this.particle);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package fr.hugman.promenade.particle;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.particle.*;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.DefaultParticleType;

@Environment(value = EnvType.CLIENT)
public class FallingLeafParticle extends SpriteBillboardParticle {
private static final float velocityIncrement = 0.0025f;
private static final int MAX_AGE = 300;
private static final float SPEED = 2.0f;
private float field_43369;
private final float field_43370;
private final float field_43371;

public FallingLeafParticle(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));
this.field_43369 = (float)Math.toRadians(this.random.nextBoolean() ? -30.0 : 30.0);
this.field_43370 = this.random.nextFloat();
this.field_43371 = (float)Math.toRadians(this.random.nextBoolean() ? -5.0 : 5.0);
this.maxAge = MAX_AGE;
this.gravityStrength = 7.5E-4f;
this.scale = f = this.random.nextBoolean() ? 0.05f : 0.075f;
this.setBoundingBoxSpacing(f, f);
this.velocityMultiplier = 1.0f;
}

@Override
public ParticleTextureSheet getType() {
return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT;
}


@Override
public void tick() {
this.prevPosX = this.x;
this.prevPosY = this.y;
this.prevPosZ = this.z;
if (this.maxAge-- <= 0) {
this.markDead();
}
if (this.dead) {
return;
}
float f = MAX_AGE - this.maxAge;
float g = Math.min(f / MAX_AGE, 1.0f);
double d = Math.cos(Math.toRadians(this.field_43370 * 60.0f)) * SPEED * Math.pow(g, 1.25);
double e = Math.sin(Math.toRadians(this.field_43370 * 60.0f)) * SPEED * Math.pow(g, 1.25);
this.velocityX += d * (double) velocityIncrement;
this.velocityZ += e * (double) velocityIncrement;
this.velocityY -= this.gravityStrength;
this.field_43369 += this.field_43371 / 20.0f;
this.prevAngle = this.angle;
this.angle += this.field_43369 / 20.0f;
this.move(this.velocityX, this.velocityY, this.velocityZ);
if (this.onGround || this.maxAge < 299 && (this.velocityX == 0.0 || this.velocityZ == 0.0)) {
this.markDead();
}
if (this.dead) {
return;
}
this.velocityX *= this.velocityMultiplier;
this.velocityY *= this.velocityMultiplier;
this.velocityZ *= this.velocityMultiplier;
}

@Environment(value = EnvType.CLIENT)
public record BlossomFactory(SpriteProvider spriteProvider) implements ParticleFactory<DefaultParticleType> {
@Override
public Particle createParticle(DefaultParticleType defaultParticleType, ClientWorld clientWorld, double x, double y, double z, double velocityX, double velocityY, double velocityZ) {
FallingLeafParticle particle = new FallingLeafParticle(clientWorld, x, y, z, this.spriteProvider);
//particle.bobbingAmplitude = MathHelper.nextBetween(clientWorld.random, 0.9f, 1.2f);
//particle.maxAge = MathHelper.nextBetween(clientWorld.random, 500, 1000);
return particle;
}
}

@Environment(value = EnvType.CLIENT)
public record MapleLeafFactory(SpriteProvider spriteProvider) implements ParticleFactory<DefaultParticleType> {
@Override
public Particle createParticle(DefaultParticleType defaultParticleType, ClientWorld clientWorld, double x, double y, double z, double velocityX, double velocityY, double velocityZ) {
FallingLeafParticle particle = new FallingLeafParticle(clientWorld, x, y, z, this.spriteProvider);
//particle.bobbingAmplitude = MathHelper.nextBetween(world.random, 0.6f, 0.8f);
//particle.maxAge = MathHelper.nextBetween(world.random, 500, 1000);
//particle.scale *= world.random.nextFloat() * 0.1f + 1.4f;
return particle;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,27 @@ public class MapleContent {
public static final Block SAP_MAPLE_LEAVES = DawnFactory.leaves(SAP_LEAVES_COLOR);
public static final Block SAP_MAPLE_LEAF_PILE = PromenadeFactory.leafPile();

public static final DefaultParticleType VERMILION_MAPLE_LEAF = FabricParticleTypes.simple();
public static final Block VERMILION_MAPLE_SAPLING = DawnFactory.sapling(VERMILION_LEAVES_COLOR, OakLikeSaplingGenerator.of(Promenade.id("maple/vermilion")));
public static final Block POTTED_VERMILION_MAPLE_SAPLING = DawnFactory.potted(VERMILION_MAPLE_SAPLING);
public static final Block VERMILION_MAPLE_LEAVES = DawnFactory.leaves(VERMILION_LEAVES_COLOR);
public static final Block VERMILION_MAPLE_LEAVES = PromenadeFactory.decoratedLeaves(VERMILION_LEAVES_COLOR, VERMILION_MAPLE_LEAF);
public static final Block VERMILION_MAPLE_LEAF_PILE = PromenadeFactory.leafPile(VERMILION_LEAVES_COLOR);
public static final Block VERMILION_CARPETED_GRASS_BLOCK = PromenadeFactory.carpetedGrassBlock(VERMILION_LEAVES_COLOR);

public static final DefaultParticleType FULVOUS_MAPLE_LEAF = FabricParticleTypes.simple();
public static final Block FULVOUS_MAPLE_SAPLING = DawnFactory.sapling(FULVOUS_LEAVES_COLOR, OakLikeSaplingGenerator.of(Promenade.id("maple/fulvous")));
public static final Block POTTED_FULVOUS_MAPLE_SAPLING = DawnFactory.potted(FULVOUS_MAPLE_SAPLING);
public static final Block FULVOUS_MAPLE_LEAVES = DawnFactory.leaves(FULVOUS_LEAVES_COLOR);
public static final Block FULVOUS_MAPLE_LEAVES = PromenadeFactory.decoratedLeaves(FULVOUS_LEAVES_COLOR, FULVOUS_MAPLE_LEAF);
public static final Block FULVOUS_MAPLE_LEAF_PILE = PromenadeFactory.leafPile(FULVOUS_LEAVES_COLOR);
public static final Block FULVOUS_CARPETED_GRASS_BLOCK = PromenadeFactory.carpetedGrassBlock(FULVOUS_LEAVES_COLOR);

public static final DefaultParticleType MIKADO_MAPLE_LEAF = FabricParticleTypes.simple();
public static final Block MIKADO_MAPLE_SAPLING = DawnFactory.sapling(MIKADO_LEAVES_COLOR, OakLikeSaplingGenerator.of(Promenade.id("maple/mikado")));
public static final Block POTTED_MIKADO_MAPLE_SAPLING = DawnFactory.potted(MIKADO_MAPLE_SAPLING);
public static final Block MIKADO_MAPLE_LEAVES = DawnFactory.leaves(MIKADO_LEAVES_COLOR);
public static final Block MIKADO_MAPLE_LEAVES = PromenadeFactory.decoratedLeaves(MIKADO_LEAVES_COLOR, MIKADO_MAPLE_LEAF);
public static final Block MIKADO_MAPLE_LEAF_PILE = PromenadeFactory.leafPile(MIKADO_LEAVES_COLOR);
public static final Block MIKADO_CARPETED_GRASS_BLOCK = PromenadeFactory.carpetedGrassBlock(MIKADO_LEAVES_COLOR);

public static final DefaultParticleType MAPLE_LEAF = FabricParticleTypes.simple();

public static final RegistryKey<Biome> CARNELIAN_TREEWAY = DawnFactory.biome(Promenade.id("carnelian_treeway"));

public static void register(Registrar r) {
Expand Down Expand Up @@ -113,26 +114,27 @@ public static void register(Registrar r) {
r.add(("sap_maple_leaves"), SAP_MAPLE_LEAVES);
r.add(("sap_maple_leaf_pile"), SAP_MAPLE_LEAF_PILE);

r.add(("vermilion_maple_leaf"), VERMILION_MAPLE_LEAF);
r.add(("vermilion_maple_sapling"), VERMILION_MAPLE_SAPLING);
r.add(("potted_vermilion_maple_sapling"), POTTED_VERMILION_MAPLE_SAPLING);
r.add(("vermilion_maple_leaves"), VERMILION_MAPLE_LEAVES);
r.add(("vermilion_maple_leaf_pile"), VERMILION_MAPLE_LEAF_PILE);
r.add(("vermilion_carpeted_grass_block"), VERMILION_CARPETED_GRASS_BLOCK);

r.add(("fulvous_maple_leaf"), FULVOUS_MAPLE_LEAF);
r.add(("fulvous_maple_sapling"), FULVOUS_MAPLE_SAPLING);
r.add(("potted_fulvous_maple_sapling"), POTTED_FULVOUS_MAPLE_SAPLING);
r.add(("fulvous_maple_leaves"), FULVOUS_MAPLE_LEAVES);
r.add(("fulvous_maple_leaf_pile"), FULVOUS_MAPLE_LEAF_PILE);
r.add(("fulvous_carpeted_grass_block"), FULVOUS_CARPETED_GRASS_BLOCK);

r.add(("mikado_maple_leaf"), MIKADO_MAPLE_LEAF);
r.add(("mikado_maple_sapling"), MIKADO_MAPLE_SAPLING);
r.add(("potted_mikado_maple_sapling"), POTTED_MIKADO_MAPLE_SAPLING);
r.add(("mikado_maple_leaves"), MIKADO_MAPLE_LEAVES);
r.add(("mikado_maple_leaf_pile"), MIKADO_MAPLE_LEAF_PILE);
r.add(("mikado_carpeted_grass_block"), MIKADO_CARPETED_GRASS_BLOCK);

r.add(("maple_leaf"), MAPLE_LEAF);

appendItemGroups();
appendVillagerTrades();
appendWorldGen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ public class SakuraContent {
public static final SignBlocks SAKURA_SIGNS = DawnFactory.signs(Promenade.id("sakura"), SAKURA_PLANKS);
public static final TerraformBoatType SAKURA_BOAT_TYPE = DawnFactory.boat(Promenade.id("sakura"), Items.OAK_PLANKS); //TODO change when possible (PR #72 on TerraformersMC/Terraform)

public static final DefaultParticleType BLUSH_SAKURA_BLOSSOM = FabricParticleTypes.simple();
public static final Block BLUSH_SAKURA_SAPLING = DawnFactory.sapling(BLUSH_BLOSSOMS_COLOR, OakLikeSaplingGenerator.of(Promenade.id("sakura/blush")));
public static final Block POTTED_BLUSH_SAKURA_SAPLING = DawnFactory.potted(BLUSH_SAKURA_SAPLING);
public static final Block BLUSH_SAKURA_BLOSSOMS = DawnFactory.leaves(BLUSH_BLOSSOMS_COLOR, BlockSoundGroup.CHERRY_LEAVES);
public static final Block BLUSH_SAKURA_BLOSSOMS = PromenadeFactory.decoratedLeaves(BLUSH_BLOSSOMS_COLOR, BlockSoundGroup.CHERRY_LEAVES, BLUSH_SAKURA_BLOSSOM);
public static final Block BLUSH_SAKURA_BLOSSOM_PILE = PromenadeFactory.leafPile(BLUSH_BLOSSOMS_COLOR, BlockSoundGroup.CHERRY_LEAVES);
public static final DefaultParticleType BLUSH_SAKURA_BLOSSOM = FabricParticleTypes.simple();

public static final DefaultParticleType COTTON_SAKURA_BLOSSOM = FabricParticleTypes.simple();
public static final Block COTTON_SAKURA_SAPLING = DawnFactory.sapling(COTTON_BLOSSOMS_COLOR, OakLikeSaplingGenerator.of(Promenade.id("sakura/cotton")));
public static final Block POTTED_COTTON_SAKURA_SAPLING = DawnFactory.potted(COTTON_SAKURA_SAPLING);
public static final Block COTTON_SAKURA_BLOSSOMS = DawnFactory.leaves(COTTON_BLOSSOMS_COLOR, BlockSoundGroup.CHERRY_LEAVES);
public static final Block COTTON_SAKURA_BLOSSOMS = PromenadeFactory.decoratedLeaves(COTTON_BLOSSOMS_COLOR, BlockSoundGroup.CHERRY_LEAVES, COTTON_SAKURA_BLOSSOM);
public static final Block COTTON_SAKURA_BLOSSOM_PILE = PromenadeFactory.leafPile(COTTON_BLOSSOMS_COLOR, BlockSoundGroup.CHERRY_LEAVES);
public static final DefaultParticleType COTTON_SAKURA_BLOSSOM = FabricParticleTypes.simple();

public static final RegistryKey<Biome> BLUSH_SAKURA_GROVE = DawnFactory.biome(Promenade.id("blush_sakura_grove"));
public static final RegistryKey<Biome> COTTON_SAKURA_GROVE = DawnFactory.biome(Promenade.id("cotton_sakura_grove"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"textures": [
"promenade:maple_leaf/fulvous"
]
}
7 changes: 0 additions & 7 deletions src/main/resources/assets/promenade/particles/maple_leaf.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"textures": [
"promenade:maple_leaf/mikado"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"textures": [
"promenade:maple_leaf/vermilion"
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
"block_search_extent": 8,
"offset": 2
},
"particle": {
"options": {
"type": "promenade:blush_sakura_blossom"
},
"probability": 0.001
},
"music": {
"sound": "promenade:music.overworld.sakura_groves",
"min_delay": 12000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
"tick_delay": 6000,
"block_search_extent": 8,
"offset": 2
},
"particle": {
"options": {
"type": "promenade:maple_leaf"
},
"probability": 0.001
}
},
"spawners": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
"block_search_extent": 8,
"offset": 2
},
"particle": {
"options": {
"type": "promenade:cotton_sakura_blossom"
},
"probability": 0.001
},
"music": {
"sound": "promenade:music.overworld.sakura_groves",
"min_delay": 12000,
Expand Down

0 comments on commit d60f8f9

Please sign in to comment.