Advertisement
jayhillx

peach leaves

Jul 30th, 2024
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. package com.mysticsbiomes.common.block;
  2.  
  3. import net.minecraft.core.BlockPos;
  4. import net.minecraft.core.Direction;
  5. import net.minecraft.world.level.LevelAccessor;
  6. import net.minecraft.world.level.block.Block;
  7. import net.minecraft.world.level.block.SoundType;
  8. import net.minecraft.world.level.block.state.BlockState;
  9. import net.minecraft.world.level.block.state.StateDefinition;
  10. import net.minecraft.world.level.block.state.properties.BooleanProperty;
  11.  
  12. public class PeachLeavesBlock extends MysticLeavesBlock {
  13.     public static final BooleanProperty  FLOWERS = BooleanProperty.create("flowers");
  14.     public static final BooleanProperty  FLOWERS_TOP = BooleanProperty.create("flowers_top");
  15.  
  16.     public PeachLeavesBlock(SoundType soundType) {
  17.         super(soundType);
  18.         this.registerDefaultState(this.stateDefinition.any().setValue(FLOWERS, false).setValue(FLOWERS_TOP, false));
  19.     }
  20.  
  21.     @Override
  22.     public BlockState updateShape(BlockState state, Direction direction, BlockState state2, LevelAccessor level, BlockPos pos, BlockPos pos2) {
  23.         BlockState belowState = level.getBlockState(pos.below());
  24.         BlockState fruitState = level.getBlockState(pos.below().below());
  25.  
  26.         boolean flag = belowState.getBlock() instanceof PeachLeavesBlock && fruitState.getBlock() instanceof PeachPlantBlock && fruitState.getValue(PeachPlantBlock.AGE) >= 2;
  27.         state = state.setValue(FLOWERS, !flag).setValue(FLOWERS_TOP, flag);
  28.         if (!flag) {
  29.             state = state.setValue(FLOWERS, false).setValue(FLOWERS_TOP, false);
  30.         }
  31.  
  32.         if (belowState.getBlock() instanceof PeachPlantBlock && belowState.getValue(PeachPlantBlock.AGE) >= 2) {
  33.             state = state.setValue(FLOWERS, false).setValue(FLOWERS_TOP, true);
  34.  
  35.             if (level.getBlockState(pos.above()).getBlock() instanceof PeachLeavesBlock && level.getBlockState(pos.above()).getValue(FLOWERS_TOP)) {
  36.                 state = state.setValue(FLOWERS, true).setValue(FLOWERS_TOP, false);
  37.             }
  38.         }
  39.         return super.updateShape(state, direction, state2, level, pos, pos2);
  40.     }
  41.  
  42.     @Override
  43.     protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
  44.         super.createBlockStateDefinition(builder.add(FLOWERS, FLOWERS_TOP));
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement