BlackstoneReplaceProcessor .java

net.minecraft.world.level.levelgen.structure.templatesystem.BlackstoneReplaceProcessor (class): members: replacements, templateRelativePos, processBlock.

net.minecraft.world.level.levelgen.structure.templatesystemclass84 linescommon3.7 KB

Implements

API Surface (1)

MapCodec<BlackstoneReplaceProcessor> codec()

Fields & Constants (8)

MAP_CODEC
INSTANCE
replacements
level
targetPosition
referencePos
templateRelativePos
processedBlockInfo

Full Source

BlackstoneReplaceProcessor.java84 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.structure.templatesystem;
2
3
import com.google.common.collect.Maps;
4
import com.mojang.serialization.MapCodec;
5
import java.util.Map;
6
import net.minecraft.core.BlockPos;
7
import net.minecraft.util.Util;
8
import net.minecraft.world.level.LevelReader;
9
import net.minecraft.world.level.block.Block;
10
import net.minecraft.world.level.block.Blocks;
11
import net.minecraft.world.level.block.SlabBlock;
12
import net.minecraft.world.level.block.StairBlock;
13
import net.minecraft.world.level.block.state.BlockState;
14
import org.jspecify.annotations.Nullable;
15
16
public class BlackstoneReplaceProcessor implements StructureProcessor {
17
	public static final MapCodec<BlackstoneReplaceProcessor> MAP_CODEC = MapCodec.unit(() -> BlackstoneReplaceProcessor.INSTANCE);
18
	public static final BlackstoneReplaceProcessor INSTANCE = new BlackstoneReplaceProcessor();
19
	private final Map<Block, Block> replacements = Util.make(Maps.newHashMap(), map -> {
20
		map.put(Blocks.COBBLESTONE, Blocks.BLACKSTONE);
21
		map.put(Blocks.MOSSY_COBBLESTONE, Blocks.BLACKSTONE);
22
		map.put(Blocks.STONE, Blocks.POLISHED_BLACKSTONE);
23
		map.put(Blocks.STONE_BRICKS, Blocks.POLISHED_BLACKSTONE_BRICKS);
24
		map.put(Blocks.MOSSY_STONE_BRICKS, Blocks.POLISHED_BLACKSTONE_BRICKS);
25
		map.put(Blocks.COBBLESTONE_STAIRS, Blocks.BLACKSTONE_STAIRS);
26
		map.put(Blocks.MOSSY_COBBLESTONE_STAIRS, Blocks.BLACKSTONE_STAIRS);
27
		map.put(Blocks.STONE_STAIRS, Blocks.POLISHED_BLACKSTONE_STAIRS);
28
		map.put(Blocks.STONE_BRICK_STAIRS, Blocks.POLISHED_BLACKSTONE_BRICK_STAIRS);
29
		map.put(Blocks.MOSSY_STONE_BRICK_STAIRS, Blocks.POLISHED_BLACKSTONE_BRICK_STAIRS);
30
		map.put(Blocks.COBBLESTONE_SLAB, Blocks.BLACKSTONE_SLAB);
31
		map.put(Blocks.MOSSY_COBBLESTONE_SLAB, Blocks.BLACKSTONE_SLAB);
32
		map.put(Blocks.SMOOTH_STONE_SLAB, Blocks.POLISHED_BLACKSTONE_SLAB);
33
		map.put(Blocks.STONE_SLAB, Blocks.POLISHED_BLACKSTONE_SLAB);
34
		map.put(Blocks.STONE_BRICK_SLAB, Blocks.POLISHED_BLACKSTONE_BRICK_SLAB);
35
		map.put(Blocks.MOSSY_STONE_BRICK_SLAB, Blocks.POLISHED_BLACKSTONE_BRICK_SLAB);
36
		map.put(Blocks.STONE_BRICK_WALL, Blocks.POLISHED_BLACKSTONE_BRICK_WALL);
37
		map.put(Blocks.MOSSY_STONE_BRICK_WALL, Blocks.POLISHED_BLACKSTONE_BRICK_WALL);
38
		map.put(Blocks.COBBLESTONE_WALL, Blocks.BLACKSTONE_WALL);
39
		map.put(Blocks.MOSSY_COBBLESTONE_WALL, Blocks.BLACKSTONE_WALL);
40
		map.put(Blocks.CHISELED_STONE_BRICKS, Blocks.CHISELED_POLISHED_BLACKSTONE);
41
		map.put(Blocks.CRACKED_STONE_BRICKS, Blocks.CRACKED_POLISHED_BLACKSTONE_BRICKS);
42
		map.put(Blocks.IRON_BARS, Blocks.IRON_CHAIN);
43
	});
44
45
	private BlackstoneReplaceProcessor() {
46
	}
47
48
	@Override
49
	public StructureTemplate.@Nullable StructureBlockInfo processBlock(
50
		final LevelReader level,
51
		final BlockPos targetPosition,
52
		final BlockPos referencePos,
53
		final BlockPos templateRelativePos,
54
		final StructureTemplate.StructureBlockInfo processedBlockInfo,
55
		final StructurePlaceSettings settings
56
	) {
57
		Block newBlock = this.replacements.get(processedBlockInfo.state().getBlock());
58
		if (newBlock == null) {
59
			return processedBlockInfo;
60
		}
61
62
		BlockState oldState = processedBlockInfo.state();
63
		BlockState newState = newBlock.defaultBlockState();
64
		if (oldState.hasProperty(StairBlock.FACING)) {
65
			newState = newState.setValue(StairBlock.FACING, oldState.getValue(StairBlock.FACING));
66
		}
67
68
		if (oldState.hasProperty(StairBlock.HALF)) {
69
			newState = newState.setValue(StairBlock.HALF, oldState.getValue(StairBlock.HALF));
70
		}
71
72
		if (oldState.hasProperty(SlabBlock.TYPE)) {
73
			newState = newState.setValue(SlabBlock.TYPE, oldState.getValue(SlabBlock.TYPE));
74
		}
75
76
		return new StructureTemplate.StructureBlockInfo(processedBlockInfo.pos(), newState, processedBlockInfo.nbt());
77
	}
78
79
	@Override
80
	public MapCodec<BlackstoneReplaceProcessor> codec() {
81
		return MAP_CODEC;
82
	}
83
}
84

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