BlockEntityJukeboxFix.java

net.minecraft.util.datafix.fixes.BlockEntityJukeboxFix

信息

  • 全限定名:net.minecraft.util.datafix.fixes.BlockEntityJukeboxFix
  • 类型:public class
  • 包:net.minecraft.util.datafix.fixes
  • 源码路径:src/main/java/net/minecraft/util/datafix/fixes/BlockEntityJukeboxFix.java
  • 起始行号:L10
  • 继承:NamedEntityFix
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

构造器

public BlockEntityJukeboxFix(Schema outputSchema, boolean changesType) @ L11

  • 构造器名:BlockEntityJukeboxFix
  • 源码定位:L11
  • 修饰符:public

参数:

  • outputSchema: Schema
  • changesType: boolean

说明:

TODO

方法

下面的方法块按源码顺序生成。

protected Typed<?> fix(Typed<?> entity) @ L15

  • 方法名:fix
  • 源码定位:L15
  • 返回类型:Typed<?>
  • 修饰符:protected

参数:

  • entity: Typed<?>

说明:

TODO

代码

public class BlockEntityJukeboxFix extends NamedEntityFix {
    public BlockEntityJukeboxFix(Schema outputSchema, boolean changesType) {
        super(outputSchema, changesType, "BlockEntityJukeboxFix", References.BLOCK_ENTITY, "minecraft:jukebox");
    }
 
    @Override
    protected Typed<?> fix(Typed<?> entity) {
        Type<?> jukeboxType = this.getInputSchema().getChoiceType(References.BLOCK_ENTITY, "minecraft:jukebox");
        Type<?> itemStackType = jukeboxType.findFieldType("RecordItem");
        OpticFinder<?> recordItemF = DSL.fieldFinder("RecordItem", itemStackType);
        Dynamic<?> tag = entity.get(DSL.remainderFinder());
        int recordId = tag.get("Record").asInt(0);
        if (recordId > 0) {
            tag.remove("Record");
            String id = ItemStackTheFlatteningFix.updateItem(ItemIdFix.getItem(recordId), 0);
            if (id != null) {
                Dynamic<?> itemTag = tag.emptyMap();
                itemTag = itemTag.set("id", itemTag.createString(id));
                itemTag = itemTag.set("Count", itemTag.createByte((byte)1));
                return entity.set(
                        recordItemF,
                        itemStackType.readTyped(itemTag)
                            .result()
                            .orElseThrow(() -> new IllegalStateException("Could not create record item stack."))
                            .getFirst()
                    )
                    .set(DSL.remainderFinder(), tag);
            }
        }
 
        return entity;
    }
}

引用的其他类