|
| 1 | +package zone.moddev.mc.basemetals.api.migration; |
| 2 | + |
| 3 | +import net.minecraft.nbt.CompoundTag; |
| 4 | +import net.minecraft.resources.ResourceLocation; |
| 5 | +import net.minecraft.world.level.block.state.BlockState; |
| 6 | +import zone.moddev.mc.basemetals.migration.Legacy112WorldMigrator; |
| 7 | + |
| 8 | +/** |
| 9 | + * Lets a companion mod preserve its data when Base Metals pre-flattens a |
| 10 | + * Minecraft 1.10 or 1.12 world. Register during common setup, before worlds load. |
| 11 | + */ |
| 12 | +public interface Legacy112MigrationExtension { |
| 13 | + enum Payload { CHUNK, PLAYER } |
| 14 | + |
| 15 | + /** |
| 16 | + * Updates a legacy chunk or player payload in place, before vanilla's data |
| 17 | + * fixer or the migrator's block entity snapshot. Leave stacks that vanilla |
| 18 | + * recognizes in the legacy item format so its fixer can componentize them. |
| 19 | + * Return true on mutation. |
| 20 | + */ |
| 21 | + default boolean prepareData(CompoundTag tag, int dataVersion, Payload payload) { return false; } |
| 22 | + |
| 23 | + /** Runs immediately before the intermediate chunk data fix, only for chunks being converted. */ |
| 24 | + default void beforeChunkFlattening(CompoundTag chunk) { } |
| 25 | + |
| 26 | + /** |
| 27 | + * Checks or restores extension data after vanilla flattens the embedded |
| 28 | + * single-player record to the 1.20.1 schema (data version 3465). The prepared |
| 29 | + * source is a read-only legacy snapshot; the mutable result still stores |
| 30 | + * items as {@code Count} and {@code tag}. Base Metals runs the remaining native data fixes, |
| 31 | + * including item component conversion, after all callbacks return. Vanilla |
| 32 | + * does not componentize arbitrary stacks inside opaque mod payloads. |
| 33 | + */ |
| 34 | + default void afterPlayerFlattening(CompoundTag preparedSource, CompoundTag result) { } |
| 35 | + |
| 36 | + /** |
| 37 | + * Returns the native state for an owned legacy block, or null for an ID |
| 38 | + * this extension does not own. Metadata is the original four-bit value. |
| 39 | + */ |
| 40 | + default BlockState decodeBlockState(ResourceLocation legacyId, int metadata) { return null; } |
| 41 | + |
| 42 | + /** The ID identifies the registering extension and must be unique. */ |
| 43 | + static void register(ResourceLocation id, Legacy112MigrationExtension extension) { |
| 44 | + Legacy112WorldMigrator.registerExtension(id, extension); |
| 45 | + } |
| 46 | +} |
0 commit comments