EffectDurationFix.java
net.minecraft.util.datafix.fixes.EffectDurationFix
信息
- 全限定名:net.minecraft.util.datafix.fixes.EffectDurationFix
- 类型:public class
- 包:net.minecraft.util.datafix.fixes
- 源码路径:src/main/java/net/minecraft/util/datafix/fixes/EffectDurationFix.java
- 起始行号:L16
- 继承:DataFix
- 职责:
TODO
字段/常量
POTION_ITEMS- 类型:
Set<String> - 修饰符:
private static final - 源码定位:
L17 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public EffectDurationFix(Schema outputSchema) @ L21
- 构造器名:EffectDurationFix
- 源码定位:L21
- 修饰符:public
参数:
- outputSchema: Schema
说明:
TODO
方法
下面的方法块按源码顺序生成。
protected TypeRewriteRule makeRule() @ L25
- 方法名:makeRule
- 源码定位:L25
- 返回类型:TypeRewriteRule
- 修饰符:protected
参数:
- 无
说明:
TODO
private Dynamic<?> fixEffect(Dynamic<?> effect) @ L53
- 方法名:fixEffect
- 源码定位:L53
- 返回类型:Dynamic<?>
- 修饰符:private
参数:
- effect: Dynamic<?>
说明:
TODO
private Dynamic<?> fix(Dynamic<?> input) @ L63
- 方法名:fix
- 源码定位:L63
- 返回类型:Dynamic<?>
- 修饰符:private
参数:
- input: Dynamic<?>
说明:
TODO
private Dynamic<?> updateEntity(Dynamic<?> data) @ L67
- 方法名:updateEntity
- 源码定位:L67
- 返回类型:Dynamic<?>
- 修饰符:private
参数:
- data: Dynamic<?>
说明:
TODO
代码
public class EffectDurationFix extends DataFix {
private static final Set<String> POTION_ITEMS = Set.of(
"minecraft:potion", "minecraft:splash_potion", "minecraft:lingering_potion", "minecraft:tipped_arrow"
);
public EffectDurationFix(Schema outputSchema) {
super(outputSchema, false);
}
@Override
protected TypeRewriteRule makeRule() {
Schema inputSchema = this.getInputSchema();
Type<?> itemStackType = this.getInputSchema().getType(References.ITEM_STACK);
OpticFinder<Pair<String, String>> idFinder = DSL.fieldFinder("id", DSL.named(References.ITEM_NAME.typeName(), NamespacedSchema.namespacedString()));
OpticFinder<?> tagFinder = itemStackType.findField("tag");
return TypeRewriteRule.seq(
this.fixTypeEverywhereTyped(
"EffectDurationEntity", inputSchema.getType(References.ENTITY), input -> input.update(DSL.remainderFinder(), this::updateEntity)
),
this.fixTypeEverywhereTyped(
"EffectDurationPlayer", inputSchema.getType(References.PLAYER), input -> input.update(DSL.remainderFinder(), this::updateEntity)
),
this.fixTypeEverywhereTyped("EffectDurationItem", itemStackType, input -> {
if (input.getOptional(idFinder).filter(typeAndIdPair -> POTION_ITEMS.contains(typeAndIdPair.getSecond())).isPresent()) {
Optional<? extends Typed<?>> tag = input.getOptionalTyped(tagFinder);
if (tag.isPresent()) {
Dynamic<?> tagRest = tag.get().get(DSL.remainderFinder());
Typed<?> newTag = tag.get().set(DSL.remainderFinder(), tagRest.update("CustomPotionEffects", this::fix));
return input.set(tagFinder, newTag);
}
}
return input;
})
);
}
private Dynamic<?> fixEffect(Dynamic<?> effect) {
return effect.update("FactorCalculationData", factorData -> {
int timestamp = factorData.get("effect_changed_timestamp").asInt(-1);
factorData = factorData.remove("effect_changed_timestamp");
int duration = effect.get("Duration").asInt(-1);
int ticksActive = timestamp - duration;
return factorData.set("ticks_active", factorData.createInt(ticksActive));
});
}
private Dynamic<?> fix(Dynamic<?> input) {
return input.createList(input.asStream().map(this::fixEffect));
}
private Dynamic<?> updateEntity(Dynamic<?> data) {
data = data.update("Effects", this::fix);
data = data.update("ActiveEffects", this::fix);
return data.update("CustomPotionEffects", this::fix);
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
NamespacedSchema.namespacedString()
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置: