Skip to content
This repository was archived by the owner on Apr 12, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ to your build.gradle(.kts) to use it.

Code - [MIT Licence](LICENSE)
Textures (PreAlpha, Alpha) - Copyright © 2025 dfdvdsf. All Rights Reserved.
Textures & Inspirations - Copyright © 2025 Mojang AB. All Rights Reserved. Microsoft and Minecraft are trademarks of the Microsoft group of companies.
Textures (Current) & Inspirations - Copyright © 2025 Mojang AB. All Rights Reserved. Microsoft and Minecraft are trademarks of the Microsoft group of companies.

2 changes: 1 addition & 1 deletion src/main/java/decok/dfcdvadstf/createworldui/Tags.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class Tags {
public static final String MODID = "createworldui";
public static final String NAME = "CreateWorldUI";
public static final String VERSION = "3.0.0";
public static final String VERSION = "3.1.0";
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,55 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;

/**
* A cyclable button that supports both click and scroll-wheel cycling through values.
* Left-click or scroll down cycles forward (+1); scroll up cycles backward (-1).
* The controller is handled by {@link CycleHandler}
* The displayed text is provided dynamically via a {@link TextSupplier}.
* <p>
* 支持单击和滚轮切换値的循环按钮。
* 左键点击或向下滚动为正向(+1);向上滚动为反向(-1)。
* 处理方式由{@link CycleHandler}处理。
* 显示的文本通过 {@link TextSupplier} 动态提供。
*/
public class GuiCyclableButton extends GuiButton {

/**
* Callback interface invoked when the button cycles.
* {@code direction} is +1 for forward, -1 for backward.
* <p>
* 按钮切换时调用的回调接口。
* {@code direction} 为 +1 表示正向,-1 表示反向。
*/
public interface CycleHandler {
void onCycle(int direction);
}

/**
* Supplies the text to display on the button.
* <p>
* 提供按钮上显示文本的接口。
*/
public interface TextSupplier {
String getText();
}

private final CycleHandler handler;
private final TextSupplier textSupplier;

/**
* Creates a new cyclable button.
* <p>
* 创建一个新的循环按钮。
*
* @param id Button ID / 按钮 ID
* @param x X position / X 坐标
* @param y Y position / Y 坐标
* @param width Width / 宽度
* @param height Height / 高度
* @param textSupplier Supplier for the display text / 提供显示文本的供应器
* @param handler Callback when cycling / 切换时的回调
*/
public GuiCyclableButton(int id,
int x,
int y,
Expand All @@ -31,6 +67,13 @@ public GuiCyclableButton(int id,
updateText();
}

/**
* Handles mouse scroll input to cycle through values.
* Positive {@code delta} scrolls up (backward, -1); negative scrolls down (forward, +1).
* <p>
* 处理鼠标滚轮输入以切换値。
* {@code delta} 为正向上滚动(反向,-1);负向下滚动(正向,+1)。
*/
public void mouseScrolled(int delta) {
if (!enabled) return;
int direction = Integer.signum(delta);
Expand All @@ -41,6 +84,11 @@ public void mouseScrolled(int delta) {
updateText();
}

/**
* Cycles forward (+1) on left-click.
* <p>
* 左键点击时正向切换(+1)。
*/
@Override
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY){
if(super.mousePressed(mc, mouseX, mouseY)){
Expand All @@ -51,6 +99,11 @@ public boolean mousePressed(Minecraft mc, int mouseX, int mouseY){
return false;
}

/**
* Updates the button's display text by querying the {@link TextSupplier}.
* <p>
* 通过查询 {@link TextSupplier} 更新按钮显示文本。
*/
public void updateText() {
if (textSupplier != null) {
this.displayString = textSupplier.getText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected void addButton(GuiButton button) {
tabManager.addButton(button);
}

// Helper methods for accessing shared state
// 辅助方法获取状态
protected String getWorldName() { return tabManager.getWorldName(); }
protected String getGameMode() { return tabManager.getGameMode(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public TabManager(GuiCreateWorld parent, List<GuiButton> buttonList, int width,
switchToTab(currentTabId);
}

// 从Mixin直接设置初始状态的方法
// Set initial state directly from Mixin / 从 Mixin 直接设置初始状态的方法
public void setInitialState(String worldName, String gameMode, String seed,
int worldTypeIndex, boolean generateStructures,
boolean bonusChest, boolean allowCheats,
Expand All @@ -71,20 +71,22 @@ public void setInitialState(String worldName, String gameMode, String seed,
this.hardcore = hardcore;
this.difficulty = difficulty != null ? difficulty : EnumDifficulty.NORMAL;

// Update game settings
// 更新游戏设置
Minecraft.getMinecraft().gameSettings.difficulty = this.difficulty;
Minecraft.getMinecraft().gameSettings.saveOptions();
}

// New method: Get the actual name used for world creation
// 新增方法:获取用于创建世界的实际名称
public String getWorldNameForCreation() {
if ((worldName == null || worldName.trim().isEmpty()) && !CreateWorldUI.config.disableCreateButtonWhenWNIsBlank) {
return I18n.format("selectWorld.newWorld"); // 返回默认名称
return I18n.format("selectWorld.newWorld"); // Return default name / 返回默认名称
}
return worldName.trim();
}

// 从TabManager获取状态回传给Mixin
// Get state back from TabManager to Mixin / 从 TabManager 获取状态回传给 Mixin
public void getCurrentState(String[] worldName, String[] gameMode, String[] seed,
int[] worldTypeIndex, boolean[] generateStructures,
boolean[] bonusChest, boolean[] allowCheats,
Expand All @@ -100,7 +102,8 @@ public void getCurrentState(String[] worldName, String[] gameMode, String[] seed
difficulty[0] = this.difficulty;
}

// 添加按钮到Mixin的按钮列表
// Add a button to the Mixin's button list
// 添加按钮到 Mixin 的按钮列表
public void addButton(GuiButton button) {
if (!buttonList.contains(button)) {
buttonList.add(button);
Expand Down
Loading