WallTorchBlock .java

net.minecraft.world.level.block.WallTorchBlock (class, 120 lines): members: SHAPES, FACING, animateTick, canSurvive, mirror, rotate, neighbourState, ticks.

net.minecraft.world.level.blockclass120 linescommonextends TorchBlock4.4 KB

API Surface (9)

VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
VoxelShape getShape(final BlockState state)
boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos)
boolean canSurvive(final LevelReader level, final BlockPos pos, 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 animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random)
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 (9)

FACING
SHAPES
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

WallTorchBlock.java120 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import java.util.Map;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.core.particles.ParticleTypes;
7
import net.minecraft.core.particles.SimpleParticleType;
8
import net.minecraft.util.RandomSource;
9
import net.minecraft.world.item.context.BlockPlaceContext;
10
import net.minecraft.world.level.BlockGetter;
11
import net.minecraft.world.level.Level;
12
import net.minecraft.world.level.LevelReader;
13
import net.minecraft.world.level.ScheduledTickAccess;
14
import net.minecraft.world.level.block.state.BlockBehaviour;
15
import net.minecraft.world.level.block.state.BlockState;
16
import net.minecraft.world.level.block.state.StateDefinition;
17
import net.minecraft.world.level.block.state.properties.EnumProperty;
18
import net.minecraft.world.phys.shapes.CollisionContext;
19
import net.minecraft.world.phys.shapes.Shapes;
20
import net.minecraft.world.phys.shapes.VoxelShape;
21
import org.jspecify.annotations.Nullable;
22
23
/**
24
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
25
 */
26
public class WallTorchBlock extends TorchBlock {
27
	public static final EnumProperty<Direction> FACING = HorizontalDirectionalBlock.FACING;
28
	private static final Map<Direction, VoxelShape> SHAPES = Shapes.rotateHorizontal(Block.boxZ(5.0, 3.0, 13.0, 11.0, 16.0));
29
30
	/**
31
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
32
	 */
33
	public WallTorchBlock(final SimpleParticleType flameParticle, final BlockBehaviour.Properties properties) {
34
		super(flameParticle, properties);
35
		this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
36
	}
37
38
	@Override
39
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
40
		return getShape(state);
41
	}
42
43
	public static VoxelShape getShape(final BlockState state) {
44
		return SHAPES.get(state.getValue(FACING));
45
	}
46
47
	@Override
48
	protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
49
		return canSurvive(level, pos, state.getValue(FACING));
50
	}
51
52
	public static boolean canSurvive(final LevelReader level, final BlockPos pos, final Direction facing) {
53
		BlockPos relativePos = pos.relative(facing.getOpposite());
54
		BlockState relativeState = level.getBlockState(relativePos);
55
		return relativeState.isFaceSturdy(level, relativePos, facing);
56
	}
57
58
	@Override
59
	public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
60
		BlockState state = this.defaultBlockState();
61
		LevelReader level = context.getLevel();
62
		BlockPos pos = context.getClickedPos();
63
		Direction[] directions = context.getNearestLookingDirections();
64
65
		for (Direction direction : directions) {
66
			if (direction.getAxis().isHorizontal()) {
67
				Direction facing = direction.getOpposite();
68
				state = state.setValue(FACING, facing);
69
				if (state.canSurvive(level, pos)) {
70
					return state;
71
				}
72
			}
73
		}
74
75
		return null;
76
	}
77
78
	@Override
79
	protected BlockState updateShape(
80
		final BlockState state,
81
		final LevelReader level,
82
		final ScheduledTickAccess ticks,
83
		final BlockPos pos,
84
		final Direction directionToNeighbour,
85
		final BlockPos neighbourPos,
86
		final BlockState neighbourState,
87
		final RandomSource random
88
	) {
89
		return directionToNeighbour.getOpposite() == state.getValue(FACING) && !state.canSurvive(level, pos) ? Blocks.AIR.defaultBlockState() : state;
90
	}
91
92
	@Override
93
	public void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random) {
94
		Direction direction = state.getValue(FACING);
95
		double x = pos.getX() + 0.5;
96
		double y = pos.getY() + 0.7;
97
		double z = pos.getZ() + 0.5;
98
		double h = 0.22;
99
		double r = 0.27;
100
		Direction opposite = direction.getOpposite();
101
		level.addParticle(ParticleTypes.SMOKE, x + 0.27 * opposite.getStepX(), y + 0.22, z + 0.27 * opposite.getStepZ(), 0.0, 0.0, 0.0);
102
		level.addParticle(this.flameParticle, x + 0.27 * opposite.getStepX(), y + 0.22, z + 0.27 * opposite.getStepZ(), 0.0, 0.0, 0.0);
103
	}
104
105
	@Override
106
	protected BlockState rotate(final BlockState state, final Rotation rotation) {
107
		return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
108
	}
109
110
	@Override
111
	protected BlockState mirror(final BlockState state, final Mirror mirror) {
112
		return state.rotate(mirror.getRotation(state.getValue(FACING)));
113
	}
114
115
	@Override
116
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
117
		builder.add(FACING);
118
	}
119
}
120

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