22
33import com .mojang .serialization .MapCodec ;
44import de .artemis .floraexpansion .common .item .ModItems ;
5+ import de .artemis .floraexpansion .common .particle .ModParticles ;
56import de .artemis .floraexpansion .common .util .ModBlockStateProperties ;
67import net .minecraft .Util ;
78import 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}
0 commit comments