EntityProjectileOwnerFix.java

net.minecraft.util.datafix.fixes.EntityProjectileOwnerFix

信息

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

    TODO

字段/常量

内部类/嵌套类型

构造器

public EntityProjectileOwnerFix(Schema outputSchema) @ L15

  • 构造器名:EntityProjectileOwnerFix
  • 源码定位:L15
  • 修饰符:public

参数:

  • outputSchema: Schema

说明:

TODO

方法

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

protected TypeRewriteRule makeRule() @ L19

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

参数:

说明:

TODO

private Typed<?> updateProjectiles(Typed<?> input) @ L25

  • 方法名:updateProjectiles
  • 源码定位:L25
  • 返回类型:Typed<?>
  • 修饰符:private

参数:

  • input: Typed<?>

说明:

TODO

private Dynamic<?> updateOwnerArrow(Dynamic<?> tag) @ L37

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

参数:

  • tag: Dynamic<?>

说明:

TODO

private Dynamic<?> updateOwnerLlamaSpit(Dynamic<?> tag) @ L43

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

参数:

  • tag: Dynamic<?>

说明:

TODO

private Dynamic<?> updateOwnerThrowable(Dynamic<?> tag) @ L50

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

参数:

  • tag: Dynamic<?>

说明:

TODO

private Dynamic<?> setUUID(Dynamic<?> tag, long mostSignificantBits, long leastSignificantBits) @ L58

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

参数:

  • tag: Dynamic<?>
  • mostSignificantBits: long
  • leastSignificantBits: long

说明:

TODO

private static int[] createUUIDArray(long mostSignificantBits, long leastSignificantBits) @ L65

  • 方法名:createUUIDArray
  • 源码定位:L65
  • 返回类型:int[]
  • 修饰符:private static

参数:

  • mostSignificantBits: long
  • leastSignificantBits: long

说明:

TODO

private Typed<?> updateEntity(Typed<?> input, String name, Function<Dynamic<?>,Dynamic<?>> function) @ L69

  • 方法名:updateEntity
  • 源码定位:L69
  • 返回类型:Typed<?>
  • 修饰符:private

参数:

  • input: Typed<?>
  • name: String
  • function: Function<Dynamic,Dynamic>

说明:

TODO

代码

public class EntityProjectileOwnerFix extends DataFix {
    public EntityProjectileOwnerFix(Schema outputSchema) {
        super(outputSchema, false);
    }
 
    @Override
    protected TypeRewriteRule makeRule() {
        Schema inputSchema = this.getInputSchema();
        return this.fixTypeEverywhereTyped("EntityProjectileOwner", inputSchema.getType(References.ENTITY), this::updateProjectiles);
    }
 
    private Typed<?> updateProjectiles(Typed<?> input) {
        input = this.updateEntity(input, "minecraft:egg", this::updateOwnerThrowable);
        input = this.updateEntity(input, "minecraft:ender_pearl", this::updateOwnerThrowable);
        input = this.updateEntity(input, "minecraft:experience_bottle", this::updateOwnerThrowable);
        input = this.updateEntity(input, "minecraft:snowball", this::updateOwnerThrowable);
        input = this.updateEntity(input, "minecraft:potion", this::updateOwnerThrowable);
        input = this.updateEntity(input, "minecraft:llama_spit", this::updateOwnerLlamaSpit);
        input = this.updateEntity(input, "minecraft:arrow", this::updateOwnerArrow);
        input = this.updateEntity(input, "minecraft:spectral_arrow", this::updateOwnerArrow);
        return this.updateEntity(input, "minecraft:trident", this::updateOwnerArrow);
    }
 
    private Dynamic<?> updateOwnerArrow(Dynamic<?> tag) {
        long mostSignificantBits = tag.get("OwnerUUIDMost").asLong(0L);
        long leastSignificantBits = tag.get("OwnerUUIDLeast").asLong(0L);
        return this.setUUID(tag, mostSignificantBits, leastSignificantBits).remove("OwnerUUIDMost").remove("OwnerUUIDLeast");
    }
 
    private Dynamic<?> updateOwnerLlamaSpit(Dynamic<?> tag) {
        OptionalDynamic<?> owner = tag.get("Owner");
        long mostSignificantBits = owner.get("OwnerUUIDMost").asLong(0L);
        long leastSignificantBits = owner.get("OwnerUUIDLeast").asLong(0L);
        return this.setUUID(tag, mostSignificantBits, leastSignificantBits).remove("Owner");
    }
 
    private Dynamic<?> updateOwnerThrowable(Dynamic<?> tag) {
        String ownerKey = "owner";
        OptionalDynamic<?> owner = tag.get("owner");
        long mostSignificantBits = owner.get("M").asLong(0L);
        long leastSignificantBits = owner.get("L").asLong(0L);
        return this.setUUID(tag, mostSignificantBits, leastSignificantBits).remove("owner");
    }
 
    private Dynamic<?> setUUID(Dynamic<?> tag, long mostSignificantBits, long leastSignificantBits) {
        String name = "OwnerUUID";
        return mostSignificantBits != 0L && leastSignificantBits != 0L
            ? tag.set("OwnerUUID", tag.createIntList(Arrays.stream(createUUIDArray(mostSignificantBits, leastSignificantBits))))
            : tag;
    }
 
    private static int[] createUUIDArray(long mostSignificantBits, long leastSignificantBits) {
        return new int[]{(int)(mostSignificantBits >> 32), (int)mostSignificantBits, (int)(leastSignificantBits >> 32), (int)leastSignificantBits};
    }
 
    private Typed<?> updateEntity(Typed<?> input, String name, Function<Dynamic<?>, Dynamic<?>> function) {
        Type<?> oldType = this.getInputSchema().getChoiceType(References.ENTITY, name);
        Type<?> newType = this.getOutputSchema().getChoiceType(References.ENTITY, name);
        return input.updateTyped(DSL.namedChoice(name, oldType), newType, entity -> entity.update(DSL.remainderFinder(), function));
    }
}

引用的其他类