| 1 | package net.minecraft.util.datafix.fixes;
|
| 2 |
|
| 3 | import com.mojang.datafixers.DSL;
|
| 4 | import com.mojang.datafixers.DataFix;
|
| 5 | import com.mojang.datafixers.OpticFinder;
|
| 6 | import com.mojang.datafixers.TypeRewriteRule;
|
| 7 | import com.mojang.datafixers.schemas.Schema;
|
| 8 | import com.mojang.datafixers.types.Type;
|
| 9 | import com.mojang.datafixers.util.Either;
|
| 10 | import com.mojang.datafixers.util.Pair;
|
| 11 | import com.mojang.datafixers.util.Unit;
|
| 12 | import com.mojang.serialization.Dynamic;
|
| 13 |
|
| 14 | public class ChestedHorsesInventoryZeroIndexingFix extends DataFix {
|
| 15 | public ChestedHorsesInventoryZeroIndexingFix(final Schema v3807) {
|
| 16 | super(v3807, false);
|
| 17 | }
|
| 18 |
|
| 19 | @Override
|
| 20 | protected TypeRewriteRule makeRule() {
|
| 21 | OpticFinder<Pair<String, Pair<Either<Pair<String, String>, Unit>, Pair<Either<?, Unit>, Dynamic<?>>>>> itemStackFinder = DSL.typeFinder(
|
| 22 | (Type<Pair<String, Pair<Either<Pair<String, String>, Unit>, Pair<Either<?, Unit>, Dynamic<?>>>>>)this.getInputSchema().getType(References.ITEM_STACK)
|
| 23 | );
|
| 24 | Type<?> entityType = this.getInputSchema().getType(References.ENTITY);
|
| 25 | return TypeRewriteRule.seq(
|
| 26 | this.horseLikeInventoryIndexingFixer(itemStackFinder, entityType, "minecraft:llama"),
|
| 27 | this.horseLikeInventoryIndexingFixer(itemStackFinder, entityType, "minecraft:trader_llama"),
|
| 28 | this.horseLikeInventoryIndexingFixer(itemStackFinder, entityType, "minecraft:mule"),
|
| 29 | this.horseLikeInventoryIndexingFixer(itemStackFinder, entityType, "minecraft:donkey")
|
| 30 | );
|
| 31 | }
|
| 32 |
|
| 33 | private TypeRewriteRule horseLikeInventoryIndexingFixer(
|
| 34 | final OpticFinder<Pair<String, Pair<Either<Pair<String, String>, Unit>, Pair<Either<?, Unit>, Dynamic<?>>>>> itemStackFinder,
|
| 35 | final Type<?> schema,
|
| 36 | final String horseId
|
| 37 | ) {
|
| 38 | Type<?> choiceType = this.getInputSchema().getChoiceType(References.ENTITY, horseId);
|
| 39 | OpticFinder<?> entityFinder = DSL.namedChoice(horseId, choiceType);
|
| 40 | OpticFinder<?> itemsFieldFinder = choiceType.findField("Items");
|
| 41 | return this.fixTypeEverywhereTyped(
|
| 42 | "Fix non-zero indexing in chest horse type " + horseId,
|
| 43 | schema,
|
| 44 | input -> input.updateTyped(
|
| 45 | entityFinder,
|
| 46 | horseLike -> horseLike.updateTyped(
|
| 47 | itemsFieldFinder,
|
| 48 | items -> items.update(
|
| 49 | itemStackFinder,
|
| 50 | namedStack -> namedStack.mapSecond(
|
| 51 | itemStack -> itemStack.mapSecond(pair -> pair.mapSecond(remainder -> remainder.update("Slot", slot -> slot.createByte((byte)(slot.asInt(2) - 2)))))
|
| 52 | )
|
| 53 | )
|
| 54 | )
|
| 55 | )
|
| 56 | );
|
| 57 | }
|
| 58 | }
|
| 59 |
|