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

Implement registry removal check #3258

Closed

Conversation

apple502j
Copy link
Contributor

WIP. Will need to test with a better equipment. Thanks to @LambdAurora for the proposal!

@apple502j apple502j added enhancement New feature or request registry-sync Pull requests and issues related to registry sync labels Aug 12, 2023
@apple502j apple502j marked this pull request as ready for review August 28, 2023 04:57
@modmuss50 modmuss50 requested review from modmuss50 and a team August 28, 2023 09:25
Copy link
Member

@modmuss50 modmuss50 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start, this is sorely needed. I think it needs to be a bit more defensive when it encounters errors. Currently it defaults to loading the world, when I think it should try to show the warning when something isnt expected.


public final class RegistryRemovalChecker {
private static final int VERSION = 1;
public static final Logger LOGGER = LoggerFactory.getLogger(RegistryRemovalChecker.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we try to keep loggers private?

public static final Logger LOGGER = LoggerFactory.getLogger(RegistryRemovalChecker.class);
private static final Gson GSON = new Gson();
public static final String FILE_NAME = "fabric_registry_removal_check.json";
private static final boolean DISABLED = Boolean.getBoolean("fabric.registry.debug.disableRemovalCheck");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this field to the top, a small comment might be helpful to make it more visable?

Comment on lines +40 to +41
Path jsonFile = session.getDirectory(WorldSavePath.ROOT).resolve(RegistryRemovalChecker.FILE_NAME);
RegistryRemovalChecker.write(jsonFile);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should backup the old file, maybe store 5 or so previous files. This will match the previous reg sync behaviour.

RegistryRemovalChecker checker = RegistryRemovalChecker.runCheck(jsonFile);

if (checker == null || checker.getMissingNamespaces().isEmpty()) {
RegistryRemovalChecker.write(jsonFile);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I need the code in front of me, but I dont see where this is saved after a user backups and loads the world.


@SuppressWarnings("unchecked, rawtypes")
public RegistryRemovalChecker(JsonObject root) {
JsonObject json = root.getAsJsonObject("entries");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This never checks the version, it should handle the case of the version being newer than supported. I imagine telling the user this.

JsonObject json = serializeRegistries();
Files.writeString(jsonFile, GSON.toJson(json), StandardCharsets.UTF_8);
} catch (IOException e) {
LOGGER.warn("Could not write {}", FILE_NAME, e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let it crash, something has gone badly wrong if this fails to write.

import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;

public final class RemovedRegistryEntryWarningScreen extends BackupPromptScreen {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to include a screenshot in the PR.

import net.fabricmc.fabric.api.event.registry.RegistryAttribute;
import net.fabricmc.fabric.api.event.registry.RegistryAttributeHolder;

public final class RegistryRemovalChecker {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some unit tests would be great for this.

for (Map.Entry<String, JsonElement> registry : json.entrySet()) {
Identifier registryId = Identifier.tryParse(registry.getKey());

if (registryId == null) continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is an entry it doesnt understand (maybe from a future version) this warrents showing the backup screen IMO.

return;
}

RegistryRemovalChecker.LOGGER.warn("Registry removal check failed! This often occurs when you update or remove a mod.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe out of scope for this PR, but it could check the ServerBrands entry in the level.dat and show a warning. This way it could warn if a user tries to load a Forge world for example.

@modmuss50 modmuss50 self-assigned this Oct 29, 2023
@apple502j apple502j closed this Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request registry-sync Pull requests and issues related to registry sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants