FurnaceRecipeFix.java
net.minecraft.util.datafix.fixes.FurnaceRecipeFix
信息
- 全限定名:net.minecraft.util.datafix.fixes.FurnaceRecipeFix
- 类型:public class
- 包:net.minecraft.util.datafix.fixes
- 源码路径:src/main/java/net/minecraft/util/datafix/fixes/FurnaceRecipeFix.java
- 起始行号:L18
- 继承:DataFix
- 职责:
TODO
字段/常量
- 无
内部类/嵌套类型
- 无
构造器
public FurnaceRecipeFix(Schema schema, boolean changesType) @ L19
- 构造器名:FurnaceRecipeFix
- 源码定位:L19
- 修饰符:public
参数:
- schema: Schema
- changesType: boolean
说明:
TODO
方法
下面的方法块按源码顺序生成。
protected TypeRewriteRule makeRule() @ L23
- 方法名:makeRule
- 源码定位:L23
- 返回类型:TypeRewriteRule
- 修饰符:protected
参数:
- 无
说明:
TODO
private <R> TypeRewriteRule cap(Type<R> recipeType) @ L28
- 方法名:cap
- 源码定位:L28
- 返回类型:
TypeRewriteRule - 修饰符:private
参数:
- recipeType: Type
说明:
TODO
private <R> Typed<?> updateFurnaceContents(Type<R> recipeType, Type<Pair<Either<Pair<List<Pair<R,Integer>>,Dynamic<?>>,Unit>,Dynamic<?>>> replacedType, Typed<?> input) @ L54
- 方法名:updateFurnaceContents
- 源码定位:L54
- 返回类型:
Typed<?> - 修饰符:private
参数:
- recipeType: Type
- replacedType: Type<Pair<Either<Pair<List<Pair<R,Integer>>,Dynamic>,Unit>,Dynamic>>
- input: Typed<?>
说明:
TODO
代码
public class FurnaceRecipeFix extends DataFix {
public FurnaceRecipeFix(Schema schema, boolean changesType) {
super(schema, changesType);
}
@Override
protected TypeRewriteRule makeRule() {
return this.cap(this.getOutputSchema().getTypeRaw(References.RECIPE));
}
private <R> TypeRewriteRule cap(Type<R> recipeType) {
Type<Pair<Either<Pair<List<Pair<R, Integer>>, Dynamic<?>>, Unit>, Dynamic<?>>> replacedType = DSL.and(
DSL.optional(DSL.field("RecipesUsed", DSL.and(DSL.compoundList(recipeType, DSL.intType()), DSL.remainderType()))), DSL.remainderType()
);
OpticFinder<?> oldFurnaceFinder = DSL.namedChoice(
"minecraft:furnace", this.getInputSchema().getChoiceType(References.BLOCK_ENTITY, "minecraft:furnace")
);
OpticFinder<?> oldBlastFurnaceFinder = DSL.namedChoice(
"minecraft:blast_furnace", this.getInputSchema().getChoiceType(References.BLOCK_ENTITY, "minecraft:blast_furnace")
);
OpticFinder<?> oldSmokerFinder = DSL.namedChoice("minecraft:smoker", this.getInputSchema().getChoiceType(References.BLOCK_ENTITY, "minecraft:smoker"));
Type<?> newFurnaceType = this.getOutputSchema().getChoiceType(References.BLOCK_ENTITY, "minecraft:furnace");
Type<?> newBlastFurnaceFinder = this.getOutputSchema().getChoiceType(References.BLOCK_ENTITY, "minecraft:blast_furnace");
Type<?> newSmokerFinder = this.getOutputSchema().getChoiceType(References.BLOCK_ENTITY, "minecraft:smoker");
Type<?> oldEntityType = this.getInputSchema().getType(References.BLOCK_ENTITY);
Type<?> newEntityType = this.getOutputSchema().getType(References.BLOCK_ENTITY);
return this.fixTypeEverywhereTyped(
"FurnaceRecipesFix",
oldEntityType,
newEntityType,
input -> input.updateTyped(oldFurnaceFinder, newFurnaceType, furnace -> this.updateFurnaceContents(recipeType, replacedType, furnace))
.updateTyped(oldBlastFurnaceFinder, newBlastFurnaceFinder, blastFurnace -> this.updateFurnaceContents(recipeType, replacedType, blastFurnace))
.updateTyped(oldSmokerFinder, newSmokerFinder, smoker -> this.updateFurnaceContents(recipeType, replacedType, smoker))
);
}
private <R> Typed<?> updateFurnaceContents(
Type<R> recipeType, Type<Pair<Either<Pair<List<Pair<R, Integer>>, Dynamic<?>>, Unit>, Dynamic<?>>> replacedType, Typed<?> input
) {
Dynamic<?> tag = input.getOrCreate(DSL.remainderFinder());
int recipesUsedSize = tag.get("RecipesUsedSize").asInt(0);
tag = tag.remove("RecipesUsedSize");
List<Pair<R, Integer>> results = Lists.newArrayList();
for (int i = 0; i < recipesUsedSize; i++) {
String locationKey = "RecipeLocation" + i;
String amountKey = "RecipeAmount" + i;
Optional<? extends Dynamic<?>> maybeLocation = tag.get(locationKey).result();
int amount = tag.get(amountKey).asInt(0);
if (amount > 0) {
maybeLocation.ifPresent(location -> {
Optional<? extends Pair<R, ? extends Dynamic<?>>> parseResult = recipeType.read((Dynamic<?>)location).result();
parseResult.ifPresent(r -> results.add(Pair.of(r.getFirst(), amount)));
});
}
tag = tag.remove(locationKey).remove(amountKey);
}
return input.set(DSL.remainderFinder(), replacedType, Pair.of(Either.left(Pair.of(results, tag.emptyMap())), tag));
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置: