AttachedStemBlock .java

net.minecraft.world.level.block.AttachedStemBlock (class): members: fruit, supportBlocks, stem, mayPlaceOn, getCloneItemStack, SHAPES, FACING, seed, ticks.

net.minecraft.world.level.blockclass105 linescommonextends VegetationBlock3.8 KB

API Surface (7)

VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
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)
boolean mayPlaceOn(final BlockState state, final BlockGetter level, final BlockPos pos)
ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final BlockState state, final boolean includeData)
BlockState rotate(final BlockState state, final Rotation rotation)
BlockState mirror(final BlockState state, final Mirror mirror)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)

Fields & Constants (13)

FACING
SHAPES
fruit
stem
seed
supportBlocks
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

AttachedStemBlock.java105 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import com.mojang.datafixers.DataFixUtils;
4
import java.util.Map;
5
import java.util.Optional;
6
import net.minecraft.core.BlockPos;
7
import net.minecraft.core.Direction;
8
import net.minecraft.core.registries.Registries;
9
import net.minecraft.resources.ResourceKey;
10
import net.minecraft.tags.TagKey;
11
import net.minecraft.util.RandomSource;
12
import net.minecraft.world.item.Item;
13
import net.minecraft.world.item.ItemStack;
14
import net.minecraft.world.level.BlockGetter;
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.EnumProperty;
21
import net.minecraft.world.phys.shapes.CollisionContext;
22
import net.minecraft.world.phys.shapes.Shapes;
23
import net.minecraft.world.phys.shapes.VoxelShape;
24
25
/**
26
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
27
 */
28
public class AttachedStemBlock extends VegetationBlock {
29
	public static final EnumProperty<Direction> FACING = HorizontalDirectionalBlock.FACING;
30
	private static final Map<Direction, VoxelShape> SHAPES = Shapes.rotateHorizontal(Block.boxZ(4.0, 0.0, 10.0, 0.0, 10.0));
31
	private final ResourceKey<Block> fruit;
32
	private final ResourceKey<Block> stem;
33
	private final ResourceKey<Item> seed;
34
	private final TagKey<Block> supportBlocks;
35
36
	/**
37
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
38
	 */
39
	public AttachedStemBlock(
40
		final ResourceKey<Block> stem,
41
		final ResourceKey<Block> fruit,
42
		final ResourceKey<Item> seed,
43
		final TagKey<Block> supportBlocks,
44
		final BlockBehaviour.Properties properties
45
	) {
46
		super(properties);
47
		this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
48
		this.stem = stem;
49
		this.fruit = fruit;
50
		this.seed = seed;
51
		this.supportBlocks = supportBlocks;
52
	}
53
54
	@Override
55
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
56
		return SHAPES.get(state.getValue(FACING));
57
	}
58
59
	@Override
60
	protected BlockState updateShape(
61
		final BlockState state,
62
		final LevelReader level,
63
		final ScheduledTickAccess ticks,
64
		final BlockPos pos,
65
		final Direction directionToNeighbour,
66
		final BlockPos neighbourPos,
67
		final BlockState neighbourState,
68
		final RandomSource random
69
	) {
70
		if (!neighbourState.is(this.fruit) && directionToNeighbour == state.getValue(FACING)) {
71
			Optional<Block> stem = level.registryAccess().lookupOrThrow(Registries.BLOCK).getOptional(this.stem);
72
			if (stem.isPresent()) {
73
				return stem.get().defaultBlockState().trySetValue(StemBlock.AGE, 7);
74
			}
75
		}
76
77
		return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
78
	}
79
80
	@Override
81
	protected boolean mayPlaceOn(final BlockState state, final BlockGetter level, final BlockPos pos) {
82
		return state.is(this.supportBlocks);
83
	}
84
85
	@Override
86
	protected ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final BlockState state, final boolean includeData) {
87
		return new ItemStack(DataFixUtils.orElse(level.registryAccess().lookupOrThrow(Registries.ITEM).getOptional(this.seed), this));
88
	}
89
90
	@Override
91
	protected BlockState rotate(final BlockState state, final Rotation rotation) {
92
		return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
93
	}
94
95
	@Override
96
	protected BlockState mirror(final BlockState state, final Mirror mirror) {
97
		return state.rotate(mirror.getRotation(state.getValue(FACING)));
98
	}
99
100
	@Override
101
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
102
		builder.add(FACING);
103
	}
104
}
105

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