TorchBlock .java

net.minecraft.world.level.block.TorchBlock (class, 45 lines): members: PARTICLE_OPTIONS_FIELD, flameParticle, animateTick. strings: "particle_options".

net.minecraft.world.level.blockclass45 linescommonextends BaseTorchBlock1.7 KB

API Surface (1)

void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random)

Fields & Constants (2)

PARTICLE_OPTIONS_FIELD
flameParticle

String literals (2)

"Not a SimpleParticleType: "
"particle_options"

Full Source

TorchBlock.java45 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import com.mojang.serialization.DataResult;
4
import com.mojang.serialization.MapCodec;
5
import net.minecraft.core.BlockPos;
6
import net.minecraft.core.particles.ParticleType;
7
import net.minecraft.core.particles.ParticleTypes;
8
import net.minecraft.core.particles.SimpleParticleType;
9
import net.minecraft.core.registries.BuiltInRegistries;
10
import net.minecraft.util.RandomSource;
11
import net.minecraft.world.level.Level;
12
import net.minecraft.world.level.block.state.BlockBehaviour;
13
import net.minecraft.world.level.block.state.BlockState;
14
15
/**
16
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
17
 */
18
public class TorchBlock extends BaseTorchBlock {
19
	protected static final MapCodec<SimpleParticleType> PARTICLE_OPTIONS_FIELD = BuiltInRegistries.PARTICLE_TYPE
20
		.byNameCodec()
21
		.comapFlatMap(
22
			type -> type instanceof SimpleParticleType simple ? DataResult.success(simple) : DataResult.error(() -> "Not a SimpleParticleType: " + type),
23
			type -> (ParticleType<?>)type
24
		)
25
		.fieldOf("particle_options");
26
	protected final SimpleParticleType flameParticle;
27
28
	/**
29
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
30
	 */
31
	public TorchBlock(final SimpleParticleType flameParticle, final BlockBehaviour.Properties properties) {
32
		super(properties);
33
		this.flameParticle = flameParticle;
34
	}
35
36
	@Override
37
	public void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random) {
38
		double x = pos.getX() + 0.5;
39
		double y = pos.getY() + 0.7;
40
		double z = pos.getZ() + 0.5;
41
		level.addParticle(ParticleTypes.SMOKE, x, y, z, 0.0, 0.0, 0.0);
42
		level.addParticle(this.flameParticle, x, y, z, 0.0, 0.0, 0.0);
43
	}
44
}
45

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