BlockEntityBlockStateFix .java

net.minecraft.util.datafix.fixes.BlockEntityBlockStateFix (class): extends NamedEntityFix. members: fix. strings: "blockData", "blockId", "blockState".

net.minecraft.util.datafix.fixesclass34 linescommonextends NamedEntityFix1.5 KB

API Surface (1)

Typed<?> fix(final Typed<?> entity)

String literals (6)

"minecraft:piston"
"blockState"
"blockId"
"blockData"
"Could not create new piston block entity."
"Could not parse newly created block state tag."

Code Graph: Dependencies (2)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

BlockEntityBlockStateFix.java34 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.datafix.fixes;
2
3
import com.mojang.datafixers.DSL;
4
import com.mojang.datafixers.OpticFinder;
5
import com.mojang.datafixers.Typed;
6
import com.mojang.datafixers.schemas.Schema;
7
import com.mojang.datafixers.types.Type;
8
import com.mojang.serialization.Dynamic;
9
10
public class BlockEntityBlockStateFix extends NamedEntityFix {
11
	public BlockEntityBlockStateFix(final Schema outputSchema, final boolean changesType) {
12
		super(outputSchema, changesType, "BlockEntityBlockStateFix", References.BLOCK_ENTITY, "minecraft:piston");
13
	}
14
15
	@Override
16
	protected Typed<?> fix(final Typed<?> entity) {
17
		Type<?> newType = this.getOutputSchema().getChoiceType(References.BLOCK_ENTITY, "minecraft:piston");
18
		Type<?> blockStateType = newType.findFieldType("blockState");
19
		OpticFinder<?> blockStateF = DSL.fieldFinder("blockState", blockStateType);
20
		Dynamic<?> tag = entity.get(DSL.remainderFinder());
21
		int block = tag.get("blockId").asInt(0);
22
		tag = tag.remove("blockId");
23
		int data = tag.get("blockData").asInt(0) & 15;
24
		tag = tag.remove("blockData");
25
		Dynamic<?> blockStateTag = BlockStateData.getTag(block << 4 | data);
26
		Typed<?> output = newType.pointTyped(entity.getOps()).orElseThrow(() -> new IllegalStateException("Could not create new piston block entity."));
27
		return output.set(DSL.remainderFinder(), tag)
28
			.set(
29
				blockStateF,
30
				blockStateType.readTyped(blockStateTag).result().orElseThrow(() -> new IllegalStateException("Could not parse newly created block state tag.")).getFirst()
31
			);
32
	}
33
}
34

Decompiled Minecraft 26.3 source of BlockEntityBlockStateFix (net/minecraft/util/datafix/fixes/BlockEntityBlockStateFix.java) with Mojang official mappings, stored verbatim on the site.