EntityPaintingItemFrameDirectionFix.java

net.minecraft.util.datafix.fixes.EntityPaintingItemFrameDirectionFix

信息

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

    TODO

字段/常量

  • DIRECTIONS
    • 类型: int[][]
    • 修饰符: private static final
    • 源码定位: L12
    • 说明:

      TODO

内部类/嵌套类型

构造器

public EntityPaintingItemFrameDirectionFix(Schema outputSchema, boolean changesType) @ L14

  • 构造器名:EntityPaintingItemFrameDirectionFix
  • 源码定位:L14
  • 修饰符:public

参数:

  • outputSchema: Schema
  • changesType: boolean

说明:

TODO

方法

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

private Dynamic<?> doFix(Dynamic<?> input, boolean isPainting, boolean isItemFrame) @ L18

  • 方法名:doFix
  • 源码定位:L18
  • 返回类型:Dynamic<?>
  • 修饰符:private

参数:

  • input: Dynamic<?>
  • isPainting: boolean
  • isItemFrame: boolean

说明:

TODO

public TypeRewriteRule makeRule() @ L42

  • 方法名:makeRule
  • 源码定位:L42
  • 返回类型:TypeRewriteRule
  • 修饰符:public

参数:

说明:

TODO

代码

public class EntityPaintingItemFrameDirectionFix extends DataFix {
    private static final int[][] DIRECTIONS = new int[][]{{0, 0, 1}, {-1, 0, 0}, {0, 0, -1}, {1, 0, 0}};
 
    public EntityPaintingItemFrameDirectionFix(Schema outputSchema, boolean changesType) {
        super(outputSchema, changesType);
    }
 
    private Dynamic<?> doFix(Dynamic<?> input, boolean isPainting, boolean isItemFrame) {
        if ((isPainting || isItemFrame) && input.get("Facing").asNumber().result().isEmpty()) {
            int direction;
            if (input.get("Direction").asNumber().result().isPresent()) {
                direction = input.get("Direction").asByte((byte)0) % DIRECTIONS.length;
                int[] steps = DIRECTIONS[direction];
                input = input.set("TileX", input.createInt(input.get("TileX").asInt(0) + steps[0]));
                input = input.set("TileY", input.createInt(input.get("TileY").asInt(0) + steps[1]));
                input = input.set("TileZ", input.createInt(input.get("TileZ").asInt(0) + steps[2]));
                input = input.remove("Direction");
                if (isItemFrame && input.get("ItemRotation").asNumber().result().isPresent()) {
                    input = input.set("ItemRotation", input.createByte((byte)(input.get("ItemRotation").asByte((byte)0) * 2)));
                }
            } else {
                direction = input.get("Dir").asByte((byte)0) % DIRECTIONS.length;
                input = input.remove("Dir");
            }
 
            input = input.set("Facing", input.createByte((byte)direction));
        }
 
        return input;
    }
 
    @Override
    public TypeRewriteRule makeRule() {
        Type<?> paintingType = this.getInputSchema().getChoiceType(References.ENTITY, "Painting");
        OpticFinder<?> paintingF = DSL.namedChoice("Painting", paintingType);
        Type<?> itemFrameType = this.getInputSchema().getChoiceType(References.ENTITY, "ItemFrame");
        OpticFinder<?> itemFrameF = DSL.namedChoice("ItemFrame", itemFrameType);
        Type<?> entityType = this.getInputSchema().getType(References.ENTITY);
        TypeRewriteRule paintingRule = this.fixTypeEverywhereTyped(
            "EntityPaintingFix",
            entityType,
            input -> input.updateTyped(paintingF, paintingType, entity -> entity.update(DSL.remainderFinder(), tag -> this.doFix(tag, true, false)))
        );
        TypeRewriteRule itemFrameRule = this.fixTypeEverywhereTyped(
            "EntityItemFrameFix",
            entityType,
            input -> input.updateTyped(itemFrameF, itemFrameType, entity -> entity.update(DSL.remainderFinder(), tag -> this.doFix(tag, false, true)))
        );
        return TypeRewriteRule.seq(paintingRule, itemFrameRule);
    }
}

引用的其他类