Skip to content

Commit 00e0582

Browse files
committed
- Reworked BurnTime for items and blocks, no longer using an event, instead based on custom item classes and registration of custom BlockItems.
- Removed old testing sections of LeafLitterBlock - Added Pine Leaf Fluff ParticleType - Pine Litter now spawns Pine Leaf Fluff Particles similar to Leaf Litter - Added Pine ParticleType - Pine Litter now spawns a single pine when walked on, with a 20% chance
1 parent 1abd080 commit 00e0582

File tree

17 files changed

+294
-77
lines changed

17 files changed

+294
-77
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package de.artemis.floraexpansion.client.event;
22

33
import de.artemis.floraexpansion.FloraExpansion;
4-
import de.artemis.floraexpansion.common.block.ModBlocks;
54
import de.artemis.floraexpansion.common.particle.LeafFluffParticles;
65
import de.artemis.floraexpansion.common.particle.ModParticles;
7-
import net.minecraft.client.color.block.BlockColors;
8-
import net.minecraft.client.renderer.BiomeColors;
9-
import net.minecraft.world.level.FoliageColor;
6+
import de.artemis.floraexpansion.common.particle.PineLeafFluffParticles;
7+
import de.artemis.floraexpansion.common.particle.PineParticles;
108
import net.neoforged.api.distmarker.Dist;
119
import net.neoforged.bus.api.SubscribeEvent;
1210
import net.neoforged.fml.common.EventBusSubscriber;
13-
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
1411
import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent;
1512

1613
@EventBusSubscriber(modid = FloraExpansion.MODID, value = Dist.CLIENT)
@@ -33,5 +30,7 @@ public static void registerBlockColors(RegisterColorHandlersEvent.Block event) {
3330
@SubscribeEvent
3431
public static void registerParticleFactories(RegisterParticleProvidersEvent event) {
3532
event.registerSpriteSet(ModParticles.LEAF_FLUFF_PARTICLES.get(), LeafFluffParticles.Provider::new);
33+
event.registerSpriteSet(ModParticles.PINE_LEAF_FLUFF_PARTICLES.get(), PineLeafFluffParticles.Provider::new);
34+
event.registerSpriteSet(ModParticles.PINE_PARTICLES.get(), PineParticles.Provider::new);
3635
}
3736
}

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,6 @@ public LeafLitterBlock(Properties properties) {
4444
level.destroyBlock(blockPos, false);
4545
level.playSound(null, blockPos, SoundEvents.MOSS_BREAK, SoundSource.BLOCKS, 1.0F, 1.0F);
4646

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-
6247
if (player instanceof ServerPlayer serverPlayer) {
6348
serverPlayer.awardStat(Stats.BLOCK_MINED.get(this));
6449
}
@@ -69,8 +54,6 @@ public LeafLitterBlock(Properties properties) {
6954

7055
@Override
7156
public void animateTick(@NotNull BlockState state, @NotNull Level level, @NotNull BlockPos pos, @NotNull RandomSource random) {
72-
super.animateTick(state, level, pos, random);
73-
7457
for (Player player : level.players()) {
7558
if (player.onGround() && player.blockPosition().equals(pos)) {
7659
double dx = player.getX() - player.xOld;

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package de.artemis.floraexpansion.common.block;
22

33
import de.artemis.floraexpansion.FloraExpansion;
4+
import de.artemis.floraexpansion.common.blockItem.ModBlockItem;
5+
import de.artemis.floraexpansion.common.item.ModItem;
46
import de.artemis.floraexpansion.common.item.ModItems;
57
import net.minecraft.world.item.BlockItem;
68
import net.minecraft.world.item.Item;
9+
import net.minecraft.world.item.Rarity;
710
import net.minecraft.world.level.block.Block;
811
import net.minecraft.world.level.block.SoundType;
912
import net.minecraft.world.level.block.state.BlockBehaviour;
@@ -16,22 +19,37 @@
1619
import java.util.function.Supplier;
1720

1821
public class ModBlocks {
22+
1923
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(FloraExpansion.MODID);
2024

2125
public static final DeferredBlock<Block> PINE_LITTER = registerBlock("pine_litter",
22-
() -> new PineLitterBlock(BlockBehaviour.Properties.of().mapColor(MapColor.PLANT).noCollission().sound(SoundType.PINK_PETALS).pushReaction(PushReaction.DESTROY)));
26+
() -> new PineLitterBlock(BlockBehaviour.Properties.of().mapColor(MapColor.PLANT).noCollission().sound(SoundType.PINK_PETALS).pushReaction(PushReaction.DESTROY)), 100
27+
);
2328

2429
public static final DeferredBlock<Block> LEAF_LITTER = registerBlock("leaf_litter",
25-
() -> new LeafLitterBlock(BlockBehaviour.Properties.of().mapColor(MapColor.PLANT).noCollission().sound(SoundType.PINK_PETALS).pushReaction(PushReaction.DESTROY)));
30+
() -> new LeafLitterBlock(BlockBehaviour.Properties.of().mapColor(MapColor.PLANT).noCollission().sound(SoundType.PINK_PETALS).pushReaction(PushReaction.DESTROY)), 100
31+
);
32+
33+
private static <T extends Block> DeferredBlock<T> registerBlock(String name, Supplier<T> block, int burnTime) {
34+
DeferredBlock<T> toReturn = BLOCKS.register(name, block);
35+
registerBlockItem(name, toReturn, burnTime);
36+
return toReturn;
37+
}
2638

2739
private static <T extends Block> DeferredBlock<T> registerBlock(String name, Supplier<T> block) {
2840
DeferredBlock<T> toReturn = BLOCKS.register(name, block);
29-
registerBlockItem(name, toReturn);
41+
registerBlockItem(name, toReturn, 0);
3042
return toReturn;
3143
}
3244

33-
private static <T extends Block> void registerBlockItem(String name, DeferredBlock<T> block) {
34-
ModItems.ITEMS.register(name, () -> new BlockItem(block.get(), new Item.Properties()));
45+
private static <T extends Block> void registerBlockItem(String name, DeferredBlock<T> block, int burnTime) {
46+
if (burnTime > 0) {
47+
ModItems.ITEMS.register(name,
48+
() -> new ModBlockItem(block.get(), new Item.Properties(), burnTime));
49+
} else {
50+
ModItems.ITEMS.register(name,
51+
() -> new BlockItem(block.get(), new Item.Properties()));
52+
}
3553
}
3654

3755
public static void register(IEventBus eventBus) {

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

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.mojang.serialization.MapCodec;
44
import de.artemis.floraexpansion.common.item.ModItems;
5+
import de.artemis.floraexpansion.common.particle.ModParticles;
56
import de.artemis.floraexpansion.common.util.ModBlockStateProperties;
67
import net.minecraft.Util;
78
import net.minecraft.core.BlockPos;
@@ -50,29 +51,29 @@ public class PineLitterBlock extends BushBlock implements BonemealableBlock {
5051

5152
public PineLitterBlock(Properties properties) {
5253
super(properties);
53-
this.registerDefaultState((BlockState)((BlockState)((BlockState)this.stateDefinition.any()).setValue(FACING, Direction.NORTH)).setValue(AMOUNT, 1));
54+
this.registerDefaultState((BlockState) ((BlockState) ((BlockState) this.stateDefinition.any()).setValue(FACING, Direction.NORTH)).setValue(AMOUNT, 1));
5455
}
5556

5657
public @NotNull BlockState rotate(BlockState blockState, Rotation rotation) {
57-
return (BlockState)blockState.setValue(FACING, rotation.rotate((Direction)blockState.getValue(FACING)));
58+
return (BlockState) blockState.setValue(FACING, rotation.rotate((Direction) blockState.getValue(FACING)));
5859
}
5960

6061
@SuppressWarnings("deprecation")
6162
public @NotNull BlockState mirror(BlockState blockState, Mirror mirror) {
62-
return blockState.rotate(mirror.getRotation((Direction)blockState.getValue(FACING)));
63+
return blockState.rotate(mirror.getRotation((Direction) blockState.getValue(FACING)));
6364
}
6465

6566
public boolean canBeReplaced(@NotNull BlockState blockState, BlockPlaceContext blockPlaceContext) {
66-
return !blockPlaceContext.isSecondaryUseActive() && blockPlaceContext.getItemInHand().is(this.asItem()) && (Integer)blockState.getValue(AMOUNT) < 4 ? true : super.canBeReplaced(blockState, blockPlaceContext);
67+
return !blockPlaceContext.isSecondaryUseActive() && blockPlaceContext.getItemInHand().is(this.asItem()) && (Integer) blockState.getValue(AMOUNT) < 4 ? true : super.canBeReplaced(blockState, blockPlaceContext);
6768
}
6869

6970
public @NotNull VoxelShape getShape(BlockState blockState, @NotNull BlockGetter blockGetter, @NotNull BlockPos blockPos, @NotNull CollisionContext context) {
70-
return (VoxelShape)SHAPE_BY_PROPERTIES.apply((Direction)blockState.getValue(FACING), (Integer)blockState.getValue(AMOUNT));
71+
return (VoxelShape) SHAPE_BY_PROPERTIES.apply((Direction) blockState.getValue(FACING), (Integer) blockState.getValue(AMOUNT));
7172
}
7273

7374
public BlockState getStateForPlacement(BlockPlaceContext context) {
7475
BlockState blockstate = context.getLevel().getBlockState(context.getClickedPos());
75-
return blockstate.is(this) ? (BlockState)blockstate.setValue(AMOUNT, Math.min(4, (Integer)blockstate.getValue(AMOUNT) + 1)) : (BlockState)this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
76+
return blockstate.is(this) ? (BlockState) blockstate.setValue(AMOUNT, Math.min(4, (Integer) blockstate.getValue(AMOUNT) + 1)) : (BlockState) this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
7677
}
7778

7879
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> blockBlockStateBuilder) {
@@ -88,9 +89,9 @@ public boolean isBonemealSuccess(@NotNull Level level, @NotNull RandomSource ran
8889
}
8990

9091
public void performBonemeal(@NotNull ServerLevel serverLevel, @NotNull RandomSource randomSource, @NotNull BlockPos blockPos, BlockState blockState) {
91-
int i = (Integer)blockState.getValue(AMOUNT);
92+
int i = (Integer) blockState.getValue(AMOUNT);
9293
if (i < 4) {
93-
serverLevel.setBlock(blockPos, (BlockState)blockState.setValue(AMOUNT, i + 1), 2);
94+
serverLevel.setBlock(blockPos, (BlockState) blockState.setValue(AMOUNT, i + 1), 2);
9495
} else {
9596
popResource(serverLevel, blockPos, new ItemStack(this));
9697
}
@@ -127,15 +128,67 @@ public void performBonemeal(@NotNull ServerLevel serverLevel, @NotNull RandomSou
127128
FACING = BlockStateProperties.HORIZONTAL_FACING;
128129
AMOUNT = ModBlockStateProperties.SEGMENT_AMOUNT;
129130
SHAPE_BY_PROPERTIES = Util.memoize((p_296142_, p_294775_) -> {
130-
VoxelShape[] avoxelshape = new VoxelShape[]{Block.box((double)8.0F, (double)0.0F, (double)8.0F, (double)16.0F, (double)3.0F, (double)16.0F), Block.box((double)8.0F, (double)0.0F, (double)0.0F, (double)16.0F, (double)3.0F, (double)8.0F), Block.box((double)0.0F, (double)0.0F, (double)0.0F, (double)8.0F, (double)3.0F, (double)8.0F), Block.box((double)0.0F, (double)0.0F, (double)8.0F, (double)8.0F, (double)3.0F, (double)16.0F)};
131+
VoxelShape[] avoxelshape = new VoxelShape[]{Block.box((double) 8.0F, (double) 0.0F, (double) 8.0F, (double) 16.0F, (double) 3.0F, (double) 16.0F), Block.box((double) 8.0F, (double) 0.0F, (double) 0.0F, (double) 16.0F, (double) 3.0F, (double) 8.0F), Block.box((double) 0.0F, (double) 0.0F, (double) 0.0F, (double) 8.0F, (double) 3.0F, (double) 8.0F), Block.box((double) 0.0F, (double) 0.0F, (double) 8.0F, (double) 8.0F, (double) 3.0F, (double) 16.0F)};
131132
VoxelShape voxelshape = Shapes.empty();
132133

133-
for(int i = 0; i < p_294775_; ++i) {
134+
for (int i = 0; i < p_294775_; ++i) {
134135
int j = Math.floorMod(i - p_296142_.get2DDataValue(), 4);
135136
voxelshape = Shapes.or(voxelshape, avoxelshape[j]);
136137
}
137138

138139
return voxelshape.singleEncompassing();
139140
});
140141
}
142+
143+
@Override
144+
public void animateTick(@NotNull BlockState state, @NotNull Level level, @NotNull BlockPos pos, @NotNull RandomSource random) {
145+
for (Player player : level.players()) {
146+
if (player.onGround() && player.blockPosition().equals(pos)) {
147+
double dx = player.getX() - player.xOld;
148+
double dz = player.getZ() - player.zOld;
149+
double speedSq = dx * dx + dz * dz;
150+
151+
if (speedSq > 0.0003 && random.nextFloat() < 0.65F) {
152+
int count = 2 + random.nextInt(4);
153+
154+
for (int i = 0; i < count; i++) {
155+
double x = pos.getX() + 0.1 + random.nextDouble() * 0.8;
156+
double z = pos.getZ() + 0.1 + random.nextDouble() * 0.8;
157+
double y = pos.getY() + 0.05 + random.nextDouble() * 0.1;
158+
159+
double angle = random.nextDouble() * Math.PI * 2;
160+
double speed = 0.025 + random.nextDouble() * 0.015;
161+
double vx = Math.cos(angle) * speed;
162+
double vz = Math.sin(angle) * speed;
163+
double vy = 0.005 + random.nextDouble() * 0.01;
164+
165+
level.addParticle(ModParticles.PINE_LEAF_FLUFF_PARTICLES.get(), x, y, z, vx, vy, vz);
166+
}
167+
168+
if (random.nextFloat() < 0.2F) {
169+
double x = pos.getX() + 0.3 + random.nextDouble() * 0.4; // centered within block
170+
double z = pos.getZ() + 0.3 + random.nextDouble() * 0.4;
171+
double y = pos.getY() + 0.05 + random.nextDouble() * 0.1;
172+
double angle = random.nextDouble() * Math.PI * 2;
173+
double speed = 0.012 + random.nextDouble() * 0.008; // gentle drift
174+
double vx = Math.cos(angle) * speed;
175+
double vz = Math.sin(angle) * speed;
176+
double vy = 0.025 + random.nextDouble() * 0.01; // short upward pop
177+
178+
level.addParticle(ModParticles.PINE_PARTICLES.get(), x, y, z, vx, vy, vz);
179+
180+
}
181+
182+
level.playLocalSound(
183+
pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
184+
SoundEvents.HANGING_ROOTS_STEP,
185+
SoundSource.BLOCKS,
186+
0.8F + random.nextFloat() * 0.2F,
187+
0.9F + random.nextFloat() * 0.3F,
188+
false
189+
);
190+
}
191+
}
192+
}
193+
}
141194
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package de.artemis.floraexpansion.common.blockItem;
2+
3+
import net.minecraft.world.item.BlockItem;
4+
import net.minecraft.world.item.ItemStack;
5+
import net.minecraft.world.item.crafting.RecipeType;
6+
import net.minecraft.world.level.block.Block;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import javax.annotation.Nullable;
10+
11+
public class ModBlockItem extends BlockItem {
12+
13+
private final int burnTime;
14+
15+
public ModBlockItem(Block block, Properties properties, int burnTime) {
16+
super(block, properties);
17+
this.burnTime = burnTime;
18+
}
19+
20+
@Override
21+
public int getBurnTime(@NotNull ItemStack itemStack, @Nullable RecipeType<?> recipeType) {
22+
return this.burnTime;
23+
}
24+
}

src/main/java/de/artemis/floraexpansion/common/event/ModEvents.java

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package de.artemis.floraexpansion.common.item;
2+
3+
import net.minecraft.world.item.Item;
4+
import net.minecraft.world.item.ItemStack;
5+
import net.minecraft.world.item.crafting.RecipeType;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
import javax.annotation.Nullable;
9+
10+
public class ModItem extends Item {
11+
private final int burnTime;
12+
13+
public ModItem(Properties properties, int burnTime) {
14+
super(properties);
15+
this.burnTime = burnTime;
16+
}
17+
18+
@Override
19+
public int getBurnTime(@NotNull ItemStack itemStack, @Nullable RecipeType<?> recipeType) {
20+
return burnTime;
21+
}
22+
}

src/main/java/de/artemis/floraexpansion/common/item/ModItems.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public class ModItems {
1919
public static final DeferredItem<Item> TOASTED_PINE_NUTS = ITEMS.register("toasted_pine_nuts",
2020
() -> new Item(new Item.Properties().food(ModFoods.TOASTED_PINE_NUTS)));
2121

22-
public static final DeferredItem<Item> TWIG = ITEMS.register("twig",
23-
() -> new Item(new Item.Properties()));
22+
public static final DeferredItem<ModItem> TWIG = ITEMS.register("twig",
23+
() -> new ModItem(new Item.Properties(), 200));
2424

2525
public static final DeferredItem<Item> FOREST_SNACK = ITEMS.register("forest_snack",
2626
() -> new Item(new Item.Properties().food(ModFoods.FOREST_SNACK)));

src/main/java/de/artemis/floraexpansion/common/item/PineConeItem.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package de.artemis.floraexpansion.common.item;
22

3-
import de.artemis.floraexpansion.common.item.projectile.PineConeProjectile;
3+
import de.artemis.floraexpansion.common.projectile.PineConeProjectile;
44
import net.minecraft.core.Direction;
55
import net.minecraft.core.Position;
66
import net.minecraft.sounds.SoundEvents;
@@ -12,8 +12,10 @@
1212
import net.minecraft.world.entity.projectile.Projectile;
1313
import net.minecraft.world.item.ItemStack;
1414
import net.minecraft.world.item.SnowballItem;
15+
import net.minecraft.world.item.crafting.RecipeType;
1516
import net.minecraft.world.level.Level;
1617
import org.jetbrains.annotations.NotNull;
18+
import org.jetbrains.annotations.Nullable;
1719

1820
public class PineConeItem extends SnowballItem {
1921

@@ -43,4 +45,9 @@ public PineConeItem(Properties properties) {
4345
pineCone.setItem(itemStack);
4446
return pineCone;
4547
}
48+
49+
@Override
50+
public int getBurnTime(@NotNull ItemStack itemStack, @Nullable RecipeType<?> recipeType) {
51+
return 100;
52+
}
4653
}

src/main/java/de/artemis/floraexpansion/common/particle/ModParticles.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ public class ModParticles {
1717
public static final Supplier<SimpleParticleType> LEAF_FLUFF_PARTICLES =
1818
PARTICLE_TYPES.register("leaf_fluff_particles", () -> new SimpleParticleType(true));
1919

20+
public static final Supplier<SimpleParticleType> PINE_LEAF_FLUFF_PARTICLES =
21+
PARTICLE_TYPES.register("pine_leaf_fluff_particles", () -> new SimpleParticleType(true));
22+
23+
public static final Supplier<SimpleParticleType> PINE_PARTICLES =
24+
PARTICLE_TYPES.register("pine_particles", () -> new SimpleParticleType(true));
25+
2026
public static void register(IEventBus eventBus) {
2127
PARTICLE_TYPES.register(eventBus);
2228
}

0 commit comments

Comments
 (0)