package net.minecraft.util.datafix.fixes; import com.mojang.datafixers.DSL; import com.mojang.datafixers.DataFix; import com.mojang.datafixers.OpticFinder; import com.mojang.datafixers.TypeRewriteRule; import com.mojang.datafixers.Typed; import com.mojang.datafixers.schemas.Schema; import com.mojang.datafixers.types.Type; import com.mojang.datafixers.util.Either; import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Unit; import com.mojang.serialization.Dynamic; import com.mojang.serialization.DynamicOps; import java.util.List; import java.util.function.Function; import java.util.function.Predicate; public class EquipmentFormatFix extends DataFix { public EquipmentFormatFix(Schema p_394549_) { super(p_394549_, true); } @Override protected TypeRewriteRule makeRule() { Type type = this.getInputSchema().getTypeRaw(References.ITEM_STACK); Type type1 = this.getOutputSchema().getTypeRaw(References.ITEM_STACK); OpticFinder opticfinder = type.findField("id"); return this.fix(type, type1, opticfinder); } private TypeRewriteRule fix(Type p_391706_, Type p_395571_, OpticFinder p_397910_) { Type, Unit>, Pair, Unit>, Pair, Either>>>>> type = DSL.named( References.ENTITY_EQUIPMENT.typeName(), DSL.and( DSL.optional(DSL.field("ArmorItems", DSL.list(p_391706_))), DSL.optional(DSL.field("HandItems", DSL.list(p_391706_))), DSL.optional(DSL.field("body_armor_item", p_391706_)), DSL.optional(DSL.field("saddle", p_391706_)) ) ); Type, Pair, Pair, Pair, Pair, Pair, Pair, Pair, Dynamic>>>>>>>>, Unit>>> type1 = DSL.named( References.ENTITY_EQUIPMENT.typeName(), DSL.optional( DSL.field( "equipment", DSL.and( DSL.optional(DSL.field("mainhand", p_395571_)), DSL.optional(DSL.field("offhand", p_395571_)), DSL.optional(DSL.field("feet", p_395571_)), DSL.and( DSL.optional(DSL.field("legs", p_395571_)), DSL.optional(DSL.field("chest", p_395571_)), DSL.optional(DSL.field("head", p_395571_)), DSL.and(DSL.optional(DSL.field("body", p_395571_)), DSL.optional(DSL.field("saddle", p_395571_)), DSL.remainderType()) ) ) ) ) ); if (!type.equals(this.getInputSchema().getType(References.ENTITY_EQUIPMENT))) { throw new IllegalStateException("Input entity_equipment type does not match expected"); } else if (!type1.equals(this.getOutputSchema().getType(References.ENTITY_EQUIPMENT))) { throw new IllegalStateException("Output entity_equipment type does not match expected"); } else { return this.fixTypeEverywhere( "EquipmentFormatFix", type, type1, p_395730_ -> { Predicate predicate = p_397158_ -> { Typed typed = new Typed<>(p_391706_, p_395730_, p_397158_); return typed.getOptional(p_397910_).isEmpty(); }; return p_396735_ -> { String s = p_396735_.getFirst(); Pair, Unit>, Pair, Unit>, Pair, Either>>> pair = p_396735_.getSecond(); List list = pair.getFirst().map(Function.identity(), p_397016_ -> List.of()); List list1 = pair.getSecond().getFirst().map(Function.identity(), p_397095_ -> List.of()); Either either = pair.getSecond().getSecond().getFirst(); Either either1 = pair.getSecond().getSecond().getSecond(); Either either2 = getItemFromList(0, list, predicate); Either either3 = getItemFromList(1, list, predicate); Either either4 = getItemFromList(2, list, predicate); Either either5 = getItemFromList(3, list, predicate); Either either6 = getItemFromList(0, list1, predicate); Either either7 = getItemFromList(1, list1, predicate); return areAllEmpty(either, either1, either2, either3, either4, either5, either6, either7) ? Pair.of(s, Either.right(Unit.INSTANCE)) : Pair.of( s, Either.left( Pair.of( (Either)either6, Pair.of( (Either)either7, Pair.of( (Either)either2, Pair.of( (Either)either3, Pair.of( (Either)either4, Pair.of( (Either)either5, Pair.of( (Either)either, Pair.of((Either)either1, new Dynamic(p_395730_)) ) ) ) ) ) ) ) ) ); }; } ); } } @SafeVarargs private static boolean areAllEmpty(Either... p_392949_) { for (Either either : p_392949_) { if (either.right().isEmpty()) { return false; } } return true; } private static Either getItemFromList(int p_391390_, List p_393050_, Predicate p_396906_) { if (p_391390_ >= p_393050_.size()) { return Either.right(Unit.INSTANCE); } else { ItemStack itemstack = p_393050_.get(p_391390_); return p_396906_.test(itemstack) ? Either.right(Unit.INSTANCE) : Either.left(itemstack); } } }