Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mysticsbiomes.common.block;
- import net.minecraft.core.BlockPos;
- import net.minecraft.core.Direction;
- import net.minecraft.world.level.LevelAccessor;
- import net.minecraft.world.level.block.Block;
- import net.minecraft.world.level.block.SoundType;
- import net.minecraft.world.level.block.state.BlockState;
- import net.minecraft.world.level.block.state.StateDefinition;
- import net.minecraft.world.level.block.state.properties.BooleanProperty;
- public class PeachLeavesBlock extends MysticLeavesBlock {
- public static final BooleanProperty FLOWERS = BooleanProperty.create("flowers");
- public static final BooleanProperty FLOWERS_TOP = BooleanProperty.create("flowers_top");
- public PeachLeavesBlock(SoundType soundType) {
- super(soundType);
- this.registerDefaultState(this.stateDefinition.any().setValue(FLOWERS, false).setValue(FLOWERS_TOP, false));
- }
- @Override
- public BlockState updateShape(BlockState state, Direction direction, BlockState state2, LevelAccessor level, BlockPos pos, BlockPos pos2) {
- BlockState belowState = level.getBlockState(pos.below());
- BlockState fruitState = level.getBlockState(pos.below().below());
- boolean flag = belowState.getBlock() instanceof PeachLeavesBlock && fruitState.getBlock() instanceof PeachPlantBlock && fruitState.getValue(PeachPlantBlock.AGE) >= 2;
- state = state.setValue(FLOWERS, !flag).setValue(FLOWERS_TOP, flag);
- if (!flag) {
- state = state.setValue(FLOWERS, false).setValue(FLOWERS_TOP, false);
- }
- if (belowState.getBlock() instanceof PeachPlantBlock && belowState.getValue(PeachPlantBlock.AGE) >= 2) {
- state = state.setValue(FLOWERS, false).setValue(FLOWERS_TOP, true);
- if (level.getBlockState(pos.above()).getBlock() instanceof PeachLeavesBlock && level.getBlockState(pos.above()).getValue(FLOWERS_TOP)) {
- state = state.setValue(FLOWERS, true).setValue(FLOWERS_TOP, false);
- }
- }
- return super.updateShape(state, direction, state2, level, pos, pos2);
- }
- @Override
- protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
- super.createBlockStateDefinition(builder.add(FLOWERS, FLOWERS_TOP));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement