BlockEntityJukeboxFix .java

net.minecraft.util.datafix.fixes.BlockEntityJukeboxFix (class, 39 lines): extends NamedEntityFix. members: fix. strings: "Record", "RecordItem", "Count".

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

API Surface (1)

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

String literals (5)

"minecraft:jukebox"
"RecordItem"
"Record"
"Count"
"Could not create record item stack."

Code Graph: Dependencies (3)

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

Full Source

BlockEntityJukeboxFix.java39 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 BlockEntityJukeboxFix extends NamedEntityFix {
11
	public BlockEntityJukeboxFix(final Schema outputSchema, final boolean changesType) {
12
		super(outputSchema, changesType, "BlockEntityJukeboxFix", References.BLOCK_ENTITY, "minecraft:jukebox");
13
	}
14
15
	@Override
16
	protected Typed<?> fix(final Typed<?> entity) {
17
		Type<?> jukeboxType = this.getInputSchema().getChoiceType(References.BLOCK_ENTITY, "minecraft:jukebox");
18
		Type<?> itemStackType = jukeboxType.findFieldType("RecordItem");
19
		OpticFinder<?> recordItemF = DSL.fieldFinder("RecordItem", itemStackType);
20
		Dynamic<?> tag = entity.get(DSL.remainderFinder());
21
		int recordId = tag.get("Record").asInt(0);
22
		if (recordId > 0) {
23
			tag.remove("Record");
24
			String id = ItemStackTheFlatteningFix.updateItem(ItemIdFix.getItem(recordId), 0);
25
			if (id != null) {
26
				Dynamic<?> itemTag = tag.emptyMap();
27
				itemTag = itemTag.set("id", itemTag.createString(id));
28
				itemTag = itemTag.set("Count", itemTag.createByte((byte)1));
29
				return entity.set(
30
						recordItemF, itemStackType.readTyped(itemTag).result().orElseThrow(() -> new IllegalStateException("Could not create record item stack.")).getFirst()
31
					)
32
					.set(DSL.remainderFinder(), tag);
33
			}
34
		}
35
36
		return entity;
37
	}
38
}
39

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