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
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package decok.dfcdvadstf.createworldui.mixin;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiCreateWorld;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiSelectWorld;
import net.minecraft.world.storage.ISaveFormat;
import net.minecraft.world.storage.SaveFormatComparator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

/**
* <p>通过Mixin技术修改原版选择世界界面,当检测到没有存档时,直接跳转到创建世界界面</p>
*/
@Mixin(GuiSelectWorld.class)
public class MixinGuiSelectWorld extends GuiScreen {

@Shadow
protected GuiScreen field_146632_a;

@Unique
private static final Logger modernWorldCreatingUI$logger = LogManager.getLogger("MixinGuiSelectWorld");

/**
* 在初始化GUI时检测是否有存档,如果没有则直接跳转到创建世界界面
*/
@Inject(method = "initGui", at = @At("HEAD"), cancellable = true)
private void onInitGuiHead(CallbackInfo ci) {
modernWorldCreatingUI$logger.info("Initializing GuiSelectWorld");

// 检测是否有存档
if (modernWorldCreatingUI$hasNoSaves()) {
modernWorldCreatingUI$logger.info("No saves detected, redirecting to Create World screen");

// 直接跳转到创建世界界面并取消原版initGui的执行
this.mc.displayGuiScreen(new GuiCreateWorld(field_146632_a)); // 使用原版的父界面引用
ci.cancel();
}
}

/**
* 检测是否有存档
*/
@Unique
private boolean modernWorldCreatingUI$hasNoSaves() {
try {
// 使用与原版代码相同的方法获取存档列表
ISaveFormat saveFormat = this.mc.getSaveLoader();
List saveList = saveFormat.getSaveList();

if (saveList == null) {
modernWorldCreatingUI$logger.warn("Could not get save list");
return true; // 无法获取存档列表,视为没有存档
}

modernWorldCreatingUI$logger.info("Found {} save entries", saveList.size());

return saveList.isEmpty();
} catch (Exception e) {
modernWorldCreatingUI$logger.error("Error checking for saves: ", e);
return true; // 发生错误时,视为没有存档以确保用户能够创建新世界
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public abstract class MixinModernCreateWorld extends GuiScreen {
@Unique
private static final Logger modernWorldCreatingUI$logger = LogManager.getLogger("MixinGuiCreateWorld");

/**
* 检查是否按下了Shift键
*/
@Unique
/**
* 初始化
*/
Expand Down Expand Up @@ -449,20 +453,44 @@ private void onActionPerformed(GuiButton button, CallbackInfo ci) {
}
}
} catch (Throwable ignored) {}
}



/**
* 处理按键输入
*/
@Override
}

/**
* 处理按键输入
*/ @Override
protected void keyTyped(char typedChar, int keyCode) {
if (!modernWorldCreatingUI$isInitialized) {
super.keyTyped(typedChar, keyCode);
return;
}

// 处理Control + Tab 和 Control + Shift + Tab 切换Tab
if (isCtrlKeyDown() && keyCode == 15) { // Tab键的键码是15
if (modernWorldCreatingUI$tabManager != null) {
java.util.Map<Integer, ?> availableTabs = modernWorldCreatingUI$tabManager.getAllTabs();
java.util.List<Integer> sortedTabIds = new java.util.ArrayList<>(availableTabs.keySet());
java.util.Collections.sort(sortedTabIds);

if (!sortedTabIds.isEmpty()) {
int currentTabId = modernWorldCreatingUI$tabManager.getCurrentTabId();
int currentIndex = sortedTabIds.indexOf(currentTabId);

int nextIndex;
if (isShiftKeyDown()) {
// Control + Shift + Tab: 向左切换 (循环)
nextIndex = (currentIndex - 1 + sortedTabIds.size()) % sortedTabIds.size();
} else {
// Control + Tab: 向右切换 (循环)
nextIndex = (currentIndex + 1) % sortedTabIds.size();
}

int targetTabId = sortedTabIds.get(nextIndex);
modernWorldCreatingUI$tabManager.switchToTab(targetTabId);
}
}
return; // 拦截按键,不继续处理
}

// 处理Control/Command + 数字键切换Tab
if (isCtrlKeyDown()) { // 使用Minecraft内置的isCtrlKeyDown方法,该方法已处理Mac和Windows/Linux的差异
// 处理数字键 1-9 和 0 (0 通常在位置10)
Expand Down