LegacyAbstractBlockPropertyFix .java

net.minecraft.util.datafix.fixes.LegacyAbstractBlockPropertyFix (class, 35 lines): members: fixProperties, shouldFix, makeRule, name. imports: DataFix.

net.minecraft.util.datafix.fixesclass35 linescommonextends DataFix1.3 KB

API Surface (1)

TypeRewriteRule makeRule()

Fields & Constants (1)

name

String literals (1)

"Properties"

Code Graph: Dependencies (1)

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

Full Source

LegacyAbstractBlockPropertyFix.java35 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.datafix.fixes;
2
3
import com.mojang.datafixers.DSL;
4
import com.mojang.datafixers.DataFix;
5
import com.mojang.datafixers.TypeRewriteRule;
6
import com.mojang.datafixers.schemas.Schema;
7
import com.mojang.serialization.Dynamic;
8
import java.util.Optional;
9
import net.minecraft.util.datafix.schemas.NamespacedSchema;
10
11
public abstract class LegacyAbstractBlockPropertyFix extends DataFix {
12
	private final String name;
13
14
	public LegacyAbstractBlockPropertyFix(final Schema outputSchema, final String name) {
15
		super(outputSchema, false);
16
		this.name = name;
17
	}
18
19
	@Override
20
	protected TypeRewriteRule makeRule() {
21
		return this.fixTypeEverywhereTyped(
22
			this.name, this.getInputSchema().getType(References.BLOCK_STATE), input -> input.update(DSL.remainderFinder(), this::fixBlockState)
23
		);
24
	}
25
26
	private Dynamic<?> fixBlockState(final Dynamic<?> tag) {
27
		Optional<String> blockId = tag.get("Name").asString().result().map(NamespacedSchema::ensureNamespaced);
28
		return blockId.isPresent() && this.shouldFix(blockId.get()) ? tag.update("Properties", properties -> this.fixProperties(blockId.get(), properties)) : tag;
29
	}
30
31
	protected abstract boolean shouldFix(String blockId);
32
33
	protected abstract <T> Dynamic<T> fixProperties(String blockId, Dynamic<T> properties);
34
}
35

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