tutorial:datafixer:basics
Differences
This shows you the differences between two versions of the page.
tutorial:datafixer:basics [2020/01/10 22:46] – created i509vcb | tutorial:datafixer:basics [2024/02/04 23:48] (current) – removed modmuss50 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== DataFixers: Builders, Schemas and Type Reference Boogaloo ===== | ||
- | |||
- | ==== What are Schemas ==== | ||
- | So you have a DataFixer, how do you tell it what to fix, what version the game the data is from and your target version to fix to? This is where Schemas come in. | ||
- | |||
- | Each Schema contains a version, the TypeReferences, | ||
- | |||
- | ==== TypeReference Electric Boogaloo ==== | ||
- | |||
- | TypeReferences can be a bit... confusing. Because of the way DFU has been made, Mojang makes it so you fix a type instead of dangerously modifying a CompoundTag and having to read the compound tag to figure out what type you are even fixing, which could contain about anything. | ||
- | |||
- | These types are defined within a Schema and represent Objects that are Serialized in the game such as Entities, BlockStates, | ||
- | |||
- | ==== DataFixerBuilder ==== | ||
- | |||
- | DataFixers start as a DataFixerBuilder, | ||
- | |||
- | ==== Building the Schema ==== | ||
- | |||
- | A Schema represents a data version of your mod's data. It contains all types within your mod at the version and defines the fixes that need to be applied in order to make the data compatible with the version. | ||
- | |||
- | <code java> | ||
- | DataFixerBuilder builder = new DataFixerBuilder(dataVersion); | ||
- | </ | ||
- | |||
- | When you create your DataFixerBuilder, | ||
- | |||
- | First you will define a Schema. This will be your base version schema which all schemas are a child of. Obviously you could register a blank schema or MC's Identifier Schema (Which only contains logic to turn namespaced strings to Identifiers) but an issue will arise, any fixes you register will fail because none type references exist to the schema. So your first Schema must define the TypeReferences you wish to fix. | ||
- | |||
- | So your mod's DataFixer will look like this towards the start of it's creation. | ||
- | |||
- | <code java> | ||
- | DataFixerBuilder builder = new DataFixerBuilder(dataVersion); | ||
- | Schema schemaV0 = builder.addSchema(0, | ||
- | </ | ||
- | |||
- | Once you have the schema created, you can register data fixes onto the Schema. You can register more schema versions easily. For example say you have version '' | ||
- | |||
- | <code java> | ||
- | Schema schema102 = builder.addSchema(102, | ||
- | </ | ||
- | |||
- | When you add a schema, it will automatically be registered into the DataFixerBuilder. | ||
- | |||
- | ==== Building the DataFixer ==== | ||
- | |||
- | For the DataFixerBuilder above would to fix any data you need to build the DataFixer. | ||
- | |||
- | To create your DataFixer you need to build it by providing an Executor for the data to be fixed on. Normally the executor Minecraft uses for this would be the Server Worker which is accessible through '' | ||
- | |||
- | < | ||
- | builder.build(Util.getServerWorkerExecutor()); | ||
- | </ | ||
- | |||
- | The DataFixer has been built, it won't actually fix anything unless you invoke it in the vanilla code to fix your blocks and stuff. But the DataFixer API has handles all the injections for where vanilla fixes it's own data. To utilize these injection points, you have to register your DataFixer through the API. | ||
- | |||
- | This is done through the '' | ||
- | |||
- | <code java> | ||
- | DataFixerHelper.INSTANCE.registerFixer(" | ||
- | </ |
tutorial/datafixer/basics.1578696397.txt.gz · Last modified: 2020/01/10 22:46 by i509vcb