BigDripleafStemBlock .java

net.minecraft.world.level.block.BigDripleafStemBlock (class): members: getCloneItemStack, SHAPES, isValidBonemealTarget, isBonemealSuccess, WATERLOGGED.

net.minecraft.world.level.blockclass128 linescommonextends HorizontalDirectionalBlock5.4 KB

Implements

API Surface (11)

VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)
FluidState getFluidState(final BlockState state)
boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos)
boolean place(final LevelAccessor level, final BlockPos pos, final FluidState fluidState, final Direction facing)
BlockState updateShape(final BlockState state, final LevelReader level, final ScheduledTickAccess ticks, final BlockPos pos, final Direction directionToNeighbour, final BlockPos neighbourPos, final BlockState neighbourState, final RandomSource random)
void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random)
boolean isValidBonemealTarget(final LevelReader level, final BlockPos pos, final BlockState state, final BonemealSource source)
boolean isBonemealSuccess(final Level level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source)
void performBonemeal(final ServerLevel level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source)
ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final BlockState state, final boolean includeData)

Fields & Constants (9)

WATERLOGGED
SHAPES
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

BigDripleafStemBlock.java128 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import java.util.Map;
4
import java.util.Optional;
5
import net.minecraft.core.BlockPos;
6
import net.minecraft.core.Direction;
7
import net.minecraft.server.level.ServerLevel;
8
import net.minecraft.tags.BlockTags;
9
import net.minecraft.util.BlockUtil;
10
import net.minecraft.util.RandomSource;
11
import net.minecraft.world.item.ItemStack;
12
import net.minecraft.world.level.BlockGetter;
13
import net.minecraft.world.level.Level;
14
import net.minecraft.world.level.LevelAccessor;
15
import net.minecraft.world.level.LevelReader;
16
import net.minecraft.world.level.ScheduledTickAccess;
17
import net.minecraft.world.level.block.state.BlockBehaviour;
18
import net.minecraft.world.level.block.state.BlockState;
19
import net.minecraft.world.level.block.state.StateDefinition;
20
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
21
import net.minecraft.world.level.block.state.properties.BooleanProperty;
22
import net.minecraft.world.level.material.FluidState;
23
import net.minecraft.world.level.material.Fluids;
24
import net.minecraft.world.phys.shapes.CollisionContext;
25
import net.minecraft.world.phys.shapes.Shapes;
26
import net.minecraft.world.phys.shapes.VoxelShape;
27
28
/**
29
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
30
 */
31
public class BigDripleafStemBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock, BonemealableBlock {
32
	private static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
33
	private static final Map<Direction, VoxelShape> SHAPES = Shapes.rotateHorizontal(Block.column(6.0, 0.0, 16.0).move(0.0, 0.0, 0.25).optimize());
34
35
	/**
36
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
37
	 */
38
	public BigDripleafStemBlock(final BlockBehaviour.Properties properties) {
39
		super(properties);
40
		this.registerDefaultState(this.stateDefinition.any().setValue(WATERLOGGED, false).setValue(FACING, Direction.NORTH));
41
	}
42
43
	@Override
44
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
45
		return SHAPES.get(state.getValue(FACING));
46
	}
47
48
	@Override
49
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
50
		builder.add(WATERLOGGED, FACING);
51
	}
52
53
	@Override
54
	protected FluidState getFluidState(final BlockState state) {
55
		return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
56
	}
57
58
	@Override
59
	protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
60
		BlockPos belowPos = pos.below();
61
		BlockState belowState = level.getBlockState(belowPos);
62
		BlockState aboveState = level.getBlockState(pos.above());
63
		return (belowState.is(this) || belowState.is(BlockTags.SUPPORTS_BIG_DRIPLEAF)) && (aboveState.is(this) || aboveState.is(Blocks.BIG_DRIPLEAF));
64
	}
65
66
	protected static boolean place(final LevelAccessor level, final BlockPos pos, final FluidState fluidState, final Direction facing) {
67
		BlockState newState = Blocks.BIG_DRIPLEAF_STEM.defaultBlockState().setValue(WATERLOGGED, fluidState.isSourceOfType(Fluids.WATER)).setValue(FACING, facing);
68
		return level.setBlockAndUpdate(pos, newState);
69
	}
70
71
	@Override
72
	protected BlockState updateShape(
73
		final BlockState state,
74
		final LevelReader level,
75
		final ScheduledTickAccess ticks,
76
		final BlockPos pos,
77
		final Direction directionToNeighbour,
78
		final BlockPos neighbourPos,
79
		final BlockState neighbourState,
80
		final RandomSource random
81
	) {
82
		if ((directionToNeighbour == Direction.DOWN || directionToNeighbour == Direction.UP) && !state.canSurvive(level, pos)) {
83
			ticks.scheduleTick(pos, this, 1);
84
		}
85
86
		if (state.getValue(WATERLOGGED)) {
87
			ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
88
		}
89
90
		return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
91
	}
92
93
	@Override
94
	protected void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
95
		if (!state.canSurvive(level, pos)) {
96
			level.destroyBlock(pos, true);
97
		}
98
	}
99
100
	@Override
101
	public boolean isValidBonemealTarget(final LevelReader level, final BlockPos pos, final BlockState state, final BonemealSource source) {
102
		Optional<BlockPos> headPos = BlockUtil.getTopConnectedBlock(level, pos, state.getBlock(), Direction.UP, Blocks.BIG_DRIPLEAF);
103
		return headPos.filter(blockPos -> BigDripleafBlock.canPlaceAt(level, blockPos.above())).isPresent();
104
	}
105
106
	@Override
107
	public boolean isBonemealSuccess(final Level level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
108
		return true;
109
	}
110
111
	@Override
112
	public void performBonemeal(final ServerLevel level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
113
		Optional<BlockPos> forwardPos = BlockUtil.getTopConnectedBlock(level, pos, state.getBlock(), Direction.UP, Blocks.BIG_DRIPLEAF);
114
		if (!forwardPos.isEmpty()) {
115
			BlockPos headPos = forwardPos.get();
116
			BlockPos placeHeadPos = headPos.above();
117
			Direction facing = state.getValue(FACING);
118
			place(level, headPos, level.getFluidState(headPos), facing);
119
			BigDripleafBlock.place(level, placeHeadPos, level.getFluidState(placeHeadPos), facing);
120
		}
121
	}
122
123
	@Override
124
	protected ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final BlockState state, final boolean includeData) {
125
		return new ItemStack(Blocks.BIG_DRIPLEAF);
126
	}
127
}
128

Decompiled Minecraft 26.3 source of BigDripleafStemBlock (net/minecraft/world/level/block/BigDripleafStemBlock.java) with Mojang official mappings, stored verbatim on the site.