11package com .dtteam .dtcobblemon .leaves ;
22
3- import com .bedrockk .molang .runtime .value .DoubleValue ;
4- import com .cobblemon .mod .common .entity .MoLangScriptingEntity ;
53import com .cobblemon .mod .common .entity .pokemon .PokemonEntity ;
64import com .dtteam .dynamictrees .block .leaves .DynamicLeavesBlock ;
75import com .dtteam .dynamictrees .block .leaves .LeavesProperties ;
3836import net .minecraft .world .level .pathfinder .PathComputationType ;
3937import net .minecraft .world .level .pathfinder .PathType ;
4038import net .minecraft .world .phys .BlockHitResult ;
41- import net .minecraft .world .phys .shapes .CollisionContext ;
42- import net .minecraft .world .phys .shapes .EntityCollisionContext ;
43- import net .minecraft .world .phys .shapes .Shapes ;
4439import net .minecraft .world .phys .shapes .VoxelShape ;
4540import org .jetbrains .annotations .NotNull ;
4641import org .jetbrains .annotations .Nullable ;
4742
4843public class DynamicSaccharineLeavesBlock extends DynamicLeavesBlock {
4944
50- public static final IntegerProperty AGE = BlockStateProperties .AGE_2 ;
51- public static final int MAX_AGE = 2 ;
52- public static final int MIN_AGE = 0 ;
45+ public static final IntegerProperty HONEY = BlockStateProperties .AGE_2 ;
46+ public static final int MAX_HONEY = 2 ;
47+ public static final int MIN_HONEY = 0 ;
5348
5449 public DynamicSaccharineLeavesBlock (LeavesProperties leavesProperties , Properties properties ) {
5550 super (leavesProperties , properties );
56- registerDefaultState (defaultBlockState ().setValue (AGE , MIN_AGE ));
51+ registerDefaultState (defaultBlockState ().setValue (HONEY , MIN_HONEY ));
5752 }
5853
5954 @ Override
6055 protected void createBlockStateDefinition (StateDefinition .Builder <Block , BlockState > builder ) {
61- builder .add (AGE );
56+ builder .add (HONEY );
6257 super .createBlockStateDefinition (builder );
6358 }
6459
@@ -81,9 +76,11 @@ public int updateHydro(LevelAccessor accessor, BlockPos pos, BlockState state, b
8176 }
8277 }
8378
84- private @ NotNull BlockState getLeavesBlockStateForPlacementWithHoney (LevelAccessor accessor , BlockPos pos , BlockState oldState ,BlockState newHydroState , boolean worldGen , int oldHydro ) {
85- int honey = oldState .getValue (AGE );
86- if (newHydroState .hasProperty (AGE )) newHydroState = newHydroState .setValue (AGE , honey );
79+ private @ NotNull BlockState getLeavesBlockStateForPlacementWithHoney (LevelAccessor accessor , BlockPos pos , BlockState oldState , BlockState newHydroState , boolean worldGen , int oldHydro ) {
80+ if (oldState .hasProperty (HONEY )){
81+ int honey = oldState .getValue (HONEY );
82+ if (newHydroState .hasProperty (HONEY )) newHydroState = newHydroState .setValue (HONEY , honey );
83+ }
8784 return this .getLeavesBlockStateForPlacement (accessor , pos , newHydroState , oldHydro , worldGen );
8885 }
8986
@@ -110,7 +107,7 @@ protected boolean isPathfindable(BlockState state, PathComputationType pathCompu
110107 @ Override
111108 public SoundType getSoundType (BlockState state , LevelReader level , BlockPos pos , @ Nullable Entity entity ) {
112109 SoundType defaultType = super .getSoundType (state , level , pos , entity );
113- if (state .hasProperty (AGE ) && state .getValue (AGE ) > MIN_AGE )
110+ if (state .hasProperty (HONEY ) && state .getValue (HONEY ) > MIN_HONEY )
114111 return new SoundType (defaultType .volume , defaultType .pitch , defaultType .getBreakSound (), SoundEvents .HONEY_BLOCK_STEP , defaultType .getPlaceSound (), SoundEvents .HONEY_BLOCK_HIT , SoundEvents .HONEY_BLOCK_FALL );
115112 return defaultType ;
116113 }
@@ -122,17 +119,17 @@ public boolean isRandomlyTicking(BlockState state) {
122119
123120 @ Override
124121 public void randomTick (BlockState state , ServerLevel world , BlockPos pos , RandomSource random ) {
125- int currentAge = state .getValue (AGE );
122+ int currentAge = state .getValue (HONEY );
126123
127- if (currentAge > MIN_AGE && random .nextInt (2 ) == 0 ) {
124+ if (currentAge > MIN_HONEY && random .nextInt (2 ) == 0 ) {
128125 for (int i = 1 ; i <= 10 ; i ++) {
129126 BlockPos belowPos = pos .below (i );
130127 BlockState belowState = world .getBlockState (belowPos );
131128
132129 if (!belowState .isAir ()) {
133130 if (belowState .getBlock () instanceof DynamicSaccharineLeavesBlock ) {
134- int belowAge = belowState .getValue (AGE );
135- if (belowAge < MAX_AGE ) {
131+ int belowAge = belowState .getValue (HONEY );
132+ if (belowAge < MAX_HONEY ) {
136133 world .setBlock (pos , changeAge (state , -1 ), Block .UPDATE_CLIENTS );
137134 world .setBlock (belowPos , changeAge (belowState , 1 ), Block .UPDATE_CLIENTS );
138135 }
@@ -148,11 +145,11 @@ public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random
148145 @ Override
149146 public boolean placeLiquid (LevelAccessor level , BlockPos pos , BlockState state , FluidState fluidState ) {
150147 if (!state .getValue (WATERLOGGED ) && fluidState .getType () == Fluids .WATER ) {
151- boolean hasHoney = state .getValue (AGE ) > 0 ;
148+ boolean hasHoney = state .getValue (HONEY ) > 0 ;
152149
153150 if (!level .isClientSide ()) {
154151 BlockState newState = state .setValue (WATERLOGGED , true );
155- if (hasHoney ) newState = newState .setValue (AGE , 0 );
152+ if (hasHoney ) newState = newState .setValue (HONEY , 0 );
156153
157154 level .setBlock (pos , newState , 3 );
158155 level .scheduleTick (pos , fluidState .getType (), fluidState .getType ().getTickDelay (level ));
@@ -171,11 +168,11 @@ public boolean placeLiquid(LevelAccessor level, BlockPos pos, BlockState state,
171168 public void animateTick (BlockState state , Level level , BlockPos pos , RandomSource random ) {
172169 int particleCount = random .nextInt (3 );
173170
174- if (state .getValue (AGE ) == 1 ) {
171+ if (state .getValue (HONEY ) == 1 ) {
175172 for (int i = 0 ; i < particleCount ; i ++) {
176173 spawnHoneyParticles (level , pos , state , 0.025F );
177174 }
178- } else if (state .getValue (AGE ) == 2 ) {
175+ } else if (state .getValue (HONEY ) == 2 ) {
179176 for (int i = 0 ; i < particleCount ; i ++) {
180177 spawnHoneyParticles (level , pos , state , 0.05F );
181178 }
@@ -238,15 +235,15 @@ public ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level
238235 player .addItem (new ItemStack (Items .HONEY_BOTTLE ));
239236
240237 level .playSound (null , pos , SoundEvents .BOTTLE_FILL , SoundSource .BLOCKS );
241- level .setBlock (pos , state .setValue (AGE , 0 ), 2 );
238+ level .setBlock (pos , state .setValue (HONEY , 0 ), 2 );
242239 level .gameEvent (null , GameEvent .BLOCK_CHANGE , pos );
243240
244241 return ItemInteractionResult .SUCCESS ;
245242 } else if (isHoneyBottle && !isAtMaxAge (state )) {
246243 item .consume (1 , player );
247244
248245 level .playSound (null , pos , SoundEvents .HONEY_BLOCK_PLACE , SoundSource .BLOCKS );
249- level .setBlock (pos , state .setValue (AGE , 2 ), 2 );
246+ level .setBlock (pos , state .setValue (HONEY , 2 ), 2 );
250247 level .gameEvent (null , GameEvent .BLOCK_CHANGE , pos );
251248
252249 return ItemInteractionResult .SUCCESS ;
@@ -257,16 +254,16 @@ public ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level
257254 }
258255
259256 private boolean isAtMaxAge (BlockState state ) {
260- return state .getValue (AGE ) == MAX_AGE ;
257+ return state .getValue (HONEY ) == MAX_HONEY ;
261258 }
262259
263260 private boolean isAtMinAge (BlockState state ) {
264- return state .getValue (AGE ) == MIN_AGE ;
261+ return state .getValue (HONEY ) == MIN_HONEY ;
265262 }
266263
267264 private BlockState changeAge (BlockState state , int value ) {
268- int newAge = Mth .clamp (state .getValue (AGE ) + value , MIN_AGE , MAX_AGE );
269- return state .setValue (AGE , newAge );
265+ int newAge = Mth .clamp (state .getValue (HONEY ) + value , MIN_HONEY , MAX_HONEY );
266+ return state .setValue (HONEY , newAge );
270267 }
271268
272269 private void spawnDestroyHoneyParticles (Level level , BlockPos pos , BlockState state ) {
@@ -292,7 +289,7 @@ private void spawnDestroyHoneyParticles(Level level, BlockPos pos, BlockState st
292289 @ Override
293290 public void spawnDestroyParticles (Level level , Player player , BlockPos pos , BlockState state ) {
294291 spawnDestroyHoneyParticles (level , pos , state );
295- super .spawnDestroyParticles (level , player , pos , state .setValue (AGE , state .getValue (AGE )));
292+ super .spawnDestroyParticles (level , player , pos , state .setValue (HONEY , state .getValue (HONEY )));
296293 }
297294}
298295
0 commit comments