Skip to content

Commit 1abd080

Browse files
committed
- Made Pine Cone, Twig, Leaf Litter, Pine Litter burnable as fuel
- Added own particle and particle type - Added leaf fluff particle type - Leaf Litter now spawns leaf fluff when stepped on
1 parent 14a0e2d commit 1abd080

File tree

10 files changed

+211
-5
lines changed

10 files changed

+211
-5
lines changed

src/main/java/de/artemis/floraexpansion/FloraExpansion.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
import de.artemis.floraexpansion.common.block.ModBlocks;
44
import de.artemis.floraexpansion.common.item.ModItems;
55
import de.artemis.floraexpansion.common.loot.ModLootModifiers;
6+
import de.artemis.floraexpansion.common.particle.LeafFluffParticles;
7+
import de.artemis.floraexpansion.common.particle.ModParticles;
8+
import net.neoforged.api.distmarker.Dist;
9+
import net.neoforged.fml.common.EventBusSubscriber;
10+
import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent;
611
import org.slf4j.Logger;
712

813
import com.mojang.logging.LogUtils;
@@ -43,6 +48,7 @@ public FloraExpansion(IEventBus modEventBus, ModContainer modContainer) {
4348
ModBlocks.register(modEventBus);
4449
ModCreativeModeTabs.register(modEventBus);
4550
ModLootModifiers.register(modEventBus);
51+
ModParticles.register(modEventBus);
4652
}
4753

4854
private void commonSetup(FMLCommonSetupEvent event) {

src/main/java/de/artemis/floraexpansion/client/event/ClientEvents.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
package de.artemis.floraexpansion.client.event;
22

3+
import de.artemis.floraexpansion.FloraExpansion;
34
import de.artemis.floraexpansion.common.block.ModBlocks;
5+
import de.artemis.floraexpansion.common.particle.LeafFluffParticles;
6+
import de.artemis.floraexpansion.common.particle.ModParticles;
47
import net.minecraft.client.color.block.BlockColors;
58
import net.minecraft.client.renderer.BiomeColors;
69
import net.minecraft.world.level.FoliageColor;
710
import net.neoforged.api.distmarker.Dist;
811
import net.neoforged.bus.api.SubscribeEvent;
912
import net.neoforged.fml.common.EventBusSubscriber;
1013
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
14+
import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent;
1115

12-
@EventBusSubscriber(value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD)
16+
@EventBusSubscriber(modid = FloraExpansion.MODID, value = Dist.CLIENT)
1317
public class ClientEvents {
1418

15-
@SuppressWarnings("deprecation")
19+
/**@SuppressWarnings("deprecation")
1620
@SubscribeEvent
1721
public static void registerBlockColors(RegisterColorHandlersEvent.Block event) {
1822
BlockColors blockColors = event.getBlockColors();
@@ -24,5 +28,10 @@ public static void registerBlockColors(RegisterColorHandlersEvent.Block event) {
2428
: FoliageColor.getDefaultColor(),
2529
ModBlocks.LEAF_LITTER.get()
2630
);
31+
}**/
32+
33+
@SubscribeEvent
34+
public static void registerParticleFactories(RegisterParticleProvidersEvent event) {
35+
event.registerSpriteSet(ModParticles.LEAF_FLUFF_PARTICLES.get(), LeafFluffParticles.Provider::new);
2736
}
28-
}
37+
}

src/main/java/de/artemis/floraexpansion/common/block/LeafLitterBlock.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package de.artemis.floraexpansion.common.block;
22

33
import de.artemis.floraexpansion.common.item.ModItems;
4+
import de.artemis.floraexpansion.common.particle.ModParticles;
45
import net.minecraft.core.BlockPos;
6+
import net.minecraft.core.particles.ParticleTypes;
57
import net.minecraft.server.level.ServerPlayer;
68
import net.minecraft.sounds.SoundEvents;
79
import net.minecraft.sounds.SoundSource;
810
import net.minecraft.stats.Stats;
11+
import net.minecraft.util.RandomSource;
912
import net.minecraft.world.InteractionHand;
1013
import net.minecraft.world.ItemInteractionResult;
14+
import net.minecraft.world.entity.Entity;
1115
import net.minecraft.world.entity.item.ItemEntity;
1216
import net.minecraft.world.entity.player.Player;
1317
import net.minecraft.world.item.ItemStack;
@@ -16,7 +20,12 @@
1620
import net.minecraft.world.phys.BlockHitResult;
1721
import org.jetbrains.annotations.NotNull;
1822

23+
import java.util.HashMap;
24+
import java.util.Map;
25+
import java.util.UUID;
26+
1927
public class LeafLitterBlock extends PineLitterBlock {
28+
private static final Map<UUID, Long> LAST_LEAF_PUFF = new HashMap<>();
2029

2130
public LeafLitterBlock(Properties properties) {
2231
super(properties);
@@ -35,11 +44,66 @@ public LeafLitterBlock(Properties properties) {
3544
level.destroyBlock(blockPos, false);
3645
level.playSound(null, blockPos, SoundEvents.MOSS_BREAK, SoundSource.BLOCKS, 1.0F, 1.0F);
3746

47+
if (level.isClientSide) {
48+
System.out.println("2");
49+
50+
System.out.println("3");
51+
52+
level.addParticle(
53+
ParticleTypes.ANGRY_VILLAGER,
54+
player.getX(),
55+
blockPos.getY() - 0.95,
56+
player.getZ(),
57+
1,
58+
1, 1
59+
);
60+
}
61+
3862
if (player instanceof ServerPlayer serverPlayer) {
3963
serverPlayer.awardStat(Stats.BLOCK_MINED.get(this));
4064
}
4165
}
4266

4367
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
4468
}
69+
70+
@Override
71+
public void animateTick(@NotNull BlockState state, @NotNull Level level, @NotNull BlockPos pos, @NotNull RandomSource random) {
72+
super.animateTick(state, level, pos, random);
73+
74+
for (Player player : level.players()) {
75+
if (player.onGround() && player.blockPosition().equals(pos)) {
76+
double dx = player.getX() - player.xOld;
77+
double dz = player.getZ() - player.zOld;
78+
double speedSq = dx * dx + dz * dz;
79+
80+
if (speedSq > 0.0003 && random.nextFloat() < 0.65F) {
81+
int count = 2 + random.nextInt(4);
82+
83+
for (int i = 0; i < count; i++) {
84+
double x = pos.getX() + 0.1 + random.nextDouble() * 0.8;
85+
double z = pos.getZ() + 0.1 + random.nextDouble() * 0.8;
86+
double y = pos.getY() + 0.05 + random.nextDouble() * 0.1;
87+
88+
double angle = random.nextDouble() * Math.PI * 2;
89+
double speed = 0.025 + random.nextDouble() * 0.015;
90+
double vx = Math.cos(angle) * speed;
91+
double vz = Math.sin(angle) * speed;
92+
double vy = 0.005 + random.nextDouble() * 0.01;
93+
94+
level.addParticle(ModParticles.LEAF_FLUFF_PARTICLES.get(), x, y, z, vx, vy, vz);
95+
}
96+
97+
level.playLocalSound(
98+
pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
99+
SoundEvents.CHERRY_LEAVES_STEP,
100+
SoundSource.BLOCKS,
101+
0.8F + random.nextFloat() * 0.2F,
102+
0.9F + random.nextFloat() * 0.3F,
103+
false
104+
);
105+
}
106+
}
107+
}
108+
}
45109
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package de.artemis.floraexpansion.common.event;
2+
3+
4+
import de.artemis.floraexpansion.common.block.ModBlocks;
5+
import de.artemis.floraexpansion.common.item.ModItems;
6+
import net.minecraft.world.item.ItemStack;
7+
import net.neoforged.bus.api.SubscribeEvent;
8+
import net.neoforged.fml.common.EventBusSubscriber;
9+
import net.neoforged.neoforge.event.furnace.FurnaceFuelBurnTimeEvent;
10+
11+
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
12+
public class ModEvents {
13+
14+
@SubscribeEvent
15+
public static void onFuelBurnTime(FurnaceFuelBurnTimeEvent event) {
16+
ItemStack itemStack = event.getItemStack();
17+
18+
//Blocks
19+
if (itemStack.is(ModBlocks.LEAF_LITTER.get().asItem())) {
20+
event.setBurnTime(100);
21+
}
22+
23+
if (itemStack.is(ModBlocks.PINE_LITTER.get().asItem())) {
24+
event.setBurnTime(100);
25+
}
26+
27+
//Items
28+
if (itemStack.is(ModItems.PINE_CONE.get())) {
29+
event.setBurnTime(100);
30+
}
31+
32+
if (itemStack.is(ModItems.TWIG.get())) {
33+
event.setBurnTime(200);
34+
}
35+
}
36+
}

src/main/java/de/artemis/floraexpansion/common/item/projectile/PineConeProjectile.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import net.minecraft.world.entity.Entity;
1010
import net.minecraft.world.entity.EntityType;
1111
import net.minecraft.world.entity.LivingEntity;
12-
import net.minecraft.world.entity.monster.Blaze;
13-
import net.minecraft.world.entity.player.Player;
1412
import net.minecraft.world.entity.projectile.Snowball;
1513
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
1614
import net.minecraft.world.item.Item;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package de.artemis.floraexpansion.common.particle;
2+
3+
import net.minecraft.client.multiplayer.ClientLevel;
4+
import net.minecraft.client.particle.*;
5+
import net.minecraft.core.particles.SimpleParticleType;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
import javax.annotation.Nullable;
9+
10+
public class LeafFluffParticles extends TextureSheetParticle {
11+
12+
protected LeafFluffParticles(ClientLevel level, double x, double y, double z, SpriteSet spriteSet, double xSpeed, double ySpeed, double zSpeed) {
13+
super(level, x, y, z, xSpeed, ySpeed, zSpeed);
14+
15+
double angle = random.nextDouble() * Math.PI * 2;
16+
double strength = 0.03 + random.nextDouble() * 0.015;
17+
this.xd = Math.cos(angle) * strength;
18+
this.yd = 0.04 + random.nextDouble() * 0.02;
19+
this.zd = Math.sin(angle) * strength;
20+
21+
this.friction = 0.94F;
22+
this.gravity = 0.025F;
23+
this.quadSize = 0.35F + random.nextFloat() * 0.1F;
24+
this.lifetime = 200 + random.nextInt(40);
25+
26+
this.setSpriteFromAge(spriteSet);
27+
}
28+
29+
@Override
30+
public void tick() {
31+
super.tick();
32+
33+
if (this.age % 10 == 0) {
34+
this.xd += (random.nextDouble() - 0.5) * 0.005;
35+
this.zd += (random.nextDouble() - 0.5) * 0.005;
36+
}
37+
38+
this.xd *= 0.97;
39+
this.zd *= 0.97;
40+
41+
float ageRatio = (float) this.age / this.lifetime;
42+
if (ageRatio > 0.75F) {
43+
this.alpha = 1.0F - (ageRatio - 0.75F) / 0.25F;
44+
}
45+
}
46+
47+
@Override
48+
public @NotNull ParticleRenderType getRenderType() {
49+
return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
50+
}
51+
52+
public static class Provider implements ParticleProvider<SimpleParticleType> {
53+
private final SpriteSet spriteSet;
54+
55+
public Provider(SpriteSet spriteSet) {
56+
this.spriteSet = spriteSet;
57+
}
58+
59+
@Nullable
60+
@Override
61+
public Particle createParticle(@NotNull SimpleParticleType simpleParticleType, @NotNull ClientLevel clientLevel, double pX, double pY, double pZ, double pXSpeed, double pYSpeed, double pZSpeed) {
62+
return new LeafFluffParticles(clientLevel, pX, pY, pZ, this.spriteSet, pXSpeed, pYSpeed, pZSpeed);
63+
}
64+
}
65+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package de.artemis.floraexpansion.common.particle;
2+
3+
import de.artemis.floraexpansion.FloraExpansion;
4+
import net.minecraft.core.particles.ParticleType;
5+
import net.minecraft.core.particles.SimpleParticleType;
6+
import net.minecraft.core.registries.BuiltInRegistries;
7+
import net.neoforged.bus.api.IEventBus;
8+
import net.neoforged.neoforge.registries.DeferredRegister;
9+
10+
import java.util.function.Supplier;
11+
12+
public class ModParticles {
13+
14+
public static final DeferredRegister<ParticleType<?>> PARTICLE_TYPES =
15+
DeferredRegister.create(BuiltInRegistries.PARTICLE_TYPE, FloraExpansion.MODID);
16+
17+
public static final Supplier<SimpleParticleType> LEAF_FLUFF_PARTICLES =
18+
PARTICLE_TYPES.register("leaf_fluff_particles", () -> new SimpleParticleType(true));
19+
20+
public static void register(IEventBus eventBus) {
21+
PARTICLE_TYPES.register(eventBus);
22+
}
23+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"textures": [
3+
"floraexpansion:leaf_fluff"
4+
]
5+
}
347 Bytes
Loading
238 Bytes
Loading

0 commit comments

Comments
 (0)