Skip to content

feat: 支持试玩模式#5942

Open
Xirren wants to merge 6 commits intoHMCL-dev:mainfrom
Xirren:demo
Open

feat: 支持试玩模式#5942
Xirren wants to merge 6 commits intoHMCL-dev:mainfrom
Xirren:demo

Conversation

@Xirren
Copy link
Copy Markdown
Contributor

@Xirren Xirren commented Apr 12, 2026

No description provided.

@Glavo
Copy link
Copy Markdown
Member

Glavo commented Apr 12, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a new "Demo Mode" account type, allowing users to try Minecraft without a purchased account. Changes include the addition of DemoAccount and DemoAccountFactory classes, UI updates to the account creation and Microsoft login screens, and updated localization files. Review feedback suggests improving the UI layout for demo hints, registering the new factory for better visibility, standardizing account identifiers, correcting a mismatch between code and comments regarding authentication types, and ensuring the equals and hashCode methods are robust and consistent.

public static final DemoAccountFactory FACTORY_DEMO = new DemoAccountFactory(AUTHLIB_INJECTOR_DOWNLOADER);
public static final AuthlibInjectorAccountFactory FACTORY_AUTHLIB_INJECTOR = new AuthlibInjectorAccountFactory(AUTHLIB_INJECTOR_DOWNLOADER, Accounts::getOrCreateAuthlibInjectorServer);
public static final MicrosoftAccountFactory FACTORY_MICROSOFT = new MicrosoftAccountFactory(new MicrosoftService(OAUTH_CALLBACK));
public static final List<AccountFactory<?>> FACTORIES = immutableListOf(FACTORY_OFFLINE, FACTORY_MICROSOFT, FACTORY_AUTHLIB_INJECTOR);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

FACTORY_DEMO 应该被添加到 FACTORIES 列表中。如果不添加,该账户类型将不会出现在“添加账户”对话框的选项卡中,用户只能通过微软登录界面的快捷按钮发现此功能,这降低了功能的发现感和一致性。

Suggested change
public static final List<AccountFactory<?>> FACTORIES = immutableListOf(FACTORY_OFFLINE, FACTORY_MICROSOFT, FACTORY_AUTHLIB_INJECTOR);
public static final List<AccountFactory<?>> FACTORIES = immutableListOf(FACTORY_OFFLINE, FACTORY_MICROSOFT, FACTORY_AUTHLIB_INJECTOR, FACTORY_DEMO);


public AuthInfo logIn() throws AuthenticationException {
// Using "legacy" user type here because "mojang" user type may cause "invalid session token" or "disconnected" when connecting to a game server.
return new DemoAuthInfo(username, uuid, UUIDTypeAdapter.fromUUID(UUID.randomUUID()), AuthInfo.USER_TYPE_MSA, "{}");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

代码实现与注释描述不符。注释提到使用 "legacy" 用户类型以避免连接服务器时的验证问题,但代码中实际使用的是 AuthInfo.USER_TYPE_MSA ("msa")。建议根据注释意图将其改为 AuthInfo.USER_TYPE_LEGACY

Suggested change
return new DemoAuthInfo(username, uuid, UUIDTypeAdapter.fromUUID(UUID.randomUUID()), AuthInfo.USER_TYPE_MSA, "{}");
return new DemoAuthInfo(username, uuid, UUIDTypeAdapter.fromUUID(UUID.randomUUID()), AuthInfo.USER_TYPE_LEGACY, "{}");


@Override
public int hashCode() {
return username.hashCode();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

hashCode 的实现应包含 isPortable() 属性,以保持与 equals 方法的一致性。此外,建议同时包含 uuid 以增强唯一性校验。

Suggested change
return username.hashCode();
return java.util.Objects.hash(isPortable(), username, uuid);

if (!(obj instanceof DemoAccount))
return false;
DemoAccount another = (DemoAccount) obj;
return isPortable() == another.isPortable() && username.equals(another.username);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

equals 方法中,建议同时校验 uuid 属性,以确保账户的唯一性判断更加严谨。

Suggested change
return isPortable() == another.isPortable() && username.equals(another.username);
return isPortable() == another.isPortable() && username.equals(another.username) && uuid.equals(another.uuid);

@burningtnt
Copy link
Copy Markdown
Member

这个功能有意义吗?

@Xirren
Copy link
Copy Markdown
Contributor Author

Xirren commented Apr 12, 2026

这个功能有意义吗?

有restrict offline,为什么没意义

@Xirren
Copy link
Copy Markdown
Contributor Author

Xirren commented Apr 12, 2026

image image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants