Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for adding Entity-renaming DataFixes #213

Draft
wants to merge 6 commits into
base: 1.19
Choose a base branch
from
Draft
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import net.minecraft.datafixer.fix.BiomeRenameFix;
import net.minecraft.datafixer.fix.BlockNameFix;
import net.minecraft.datafixer.fix.EntityRenameFix;
import net.minecraft.datafixer.fix.ItemNameFix;
import net.minecraft.datafixer.schema.IdentifierNormalizingSchema;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -112,4 +113,32 @@ public static void addBiomeRenameFix(@NotNull DataFixerBuilder builder, @NotNull
}
builder.addFixer(new BiomeRenameFix(schema, false, name, mapBuilder.build()));
}

/**
* Adds an entity rename fix to the builder, in case an entity's identifier is changed.
*
* @param builder the builder
* @param name the fix's name
* @param oldId the entity's old identifier
* @param newId the entity's new identifier
* @param schema the schema this fix should be a part of
* @see EntityRenameFix
*/
public static void addEntityRenameFix(@NotNull DataFixerBuilder builder, @NotNull String name,
@NotNull Identifier oldId, @NotNull Identifier newId,
@NotNull Schema schema) {
requireNonNull(builder, "DataFixerBuilder cannot be null");
requireNonNull(name, "Fix name cannot be null");
requireNonNull(oldId, "Old identifier cannot be null");
requireNonNull(newId, "New identifier cannot be null");
requireNonNull(schema, "Schema cannot be null");

final String oldIdStr = oldId.toString(), newIdStr = newId.toString();
builder.addFixer(new EntityRenameFix(name, schema, false) {
@Override
protected String rename(String inputName) {
return Objects.equals(IdentifierNormalizingSchema.normalize(inputName), oldIdStr) ? newIdStr : inputName;
}
});
}
}