Skip to content

Commit 9fe2ae7

Browse files
committed
Initial commit
1 parent e385b83 commit 9fe2ae7

20 files changed

Lines changed: 2235 additions & 13 deletions
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package huix.infinity.common.client.screen;
2+
3+
import huix.infinity.common.world.inventory.TimedCraftingContainer;
4+
import net.minecraft.client.gui.GuiGraphics;
5+
import net.minecraft.client.gui.Font;
6+
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
7+
import net.minecraft.network.chat.Component;
8+
import net.minecraft.resources.ResourceLocation;
9+
import net.minecraft.world.entity.player.Inventory;
10+
import org.jetbrains.annotations.NotNull;
11+
12+
/**
13+
* MITE合成系统的GUI界面
14+
*/
15+
public class MITECraftingScreen extends AbstractContainerScreen<TimedCraftingContainer> {
16+
17+
private static final ResourceLocation CRAFTING_TABLE_LOCATION =
18+
new ResourceLocation("textures/gui/container/crafting_table.png");
19+
20+
private final DifficultyTooltip difficultyTooltip;
21+
private final CraftingProgressBar progressBar;
22+
private final TimeEstimateWidget timeWidget;
23+
24+
public MITECraftingScreen(TimedCraftingContainer menu, Inventory playerInventory, Component title) {
25+
super(menu, playerInventory, title);
26+
this.difficultyTooltip = new DifficultyTooltip(this);
27+
this.progressBar = new CraftingProgressBar(this);
28+
this.timeWidget = new TimeEstimateWidget(this);
29+
}
30+
31+
@Override
32+
protected void init() {
33+
super.init();
34+
this.titleLabelX = (this.imageWidth - this.font.width(this.title)) / 2;
35+
}
36+
37+
@Override
38+
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
39+
super.render(guiGraphics, mouseX, mouseY, partialTick);
40+
41+
// 渲染制作进度条
42+
this.progressBar.render(guiGraphics, mouseX, mouseY);
43+
44+
// 渲染时间估算组件
45+
this.timeWidget.render(guiGraphics, mouseX, mouseY);
46+
47+
// 渲染物品提示(最后渲染,确保在最上层)
48+
this.renderTooltip(guiGraphics, mouseX, mouseY);
49+
this.difficultyTooltip.render(guiGraphics, mouseX, mouseY);
50+
}
51+
52+
@Override
53+
protected void renderBg(@NotNull GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) {
54+
int x = (this.width - this.imageWidth) / 2;
55+
int y = (this.height - this.imageHeight) / 2;
56+
guiGraphics.blit(CRAFTING_TABLE_LOCATION, x, y, 0, 0, this.imageWidth, this.imageHeight);
57+
}
58+
59+
@Override
60+
protected void renderLabels(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) {
61+
super.renderLabels(guiGraphics, mouseX, mouseY);
62+
63+
// 显示制作难度信息
64+
if (this.menu.hasValidRecipe()) {
65+
String difficultyText = "难度: " + this.menu.getCurrentDifficulty();
66+
guiGraphics.drawString(this.font, difficultyText, 8, 73, 0x404040, false);
67+
68+
String tierText = "需要: " + this.menu.getRequiredTier();
69+
guiGraphics.drawString(this.font, tierText, 8, 83, 0x404040, false);
70+
}
71+
}
72+
73+
/**
74+
* 检查鼠标是否悬停在指定区域
75+
*/
76+
public boolean isHoveringSlot(int x, int y, int width, int height, int mouseX, int mouseY) {
77+
int screenX = this.leftPos + x;
78+
int screenY = this.topPos + y;
79+
return mouseX >= screenX && mouseX < screenX + width &&
80+
mouseY >= screenY && mouseY < screenY + height;
81+
}
82+
83+
/**
84+
* 获取字体对象
85+
*/
86+
public Font getFont() {
87+
return this.font;
88+
}
89+
90+
/**
91+
* 获取左上角位置
92+
*/
93+
public int getLeftPos() {
94+
return this.leftPos;
95+
}
96+
97+
/**
98+
* 获取左上角位置
99+
*/
100+
public int getTopPos() {
101+
return this.topPos;
102+
}
103+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package huix.infinity.common.client.screen;
2+
3+
import com.google.common.collect.Lists;
4+
import huix.infinity.common.world.item.tier.CraftingDifficultyCalculator;
5+
import net.minecraft.ChatFormatting;
6+
import net.minecraft.client.gui.GuiGraphics;
7+
import net.minecraft.network.chat.Component;
8+
import net.minecraft.world.item.ItemStack;
9+
10+
import java.util.List;
11+
12+
public class DifficultyTooltip {
13+
private final MITECraftingScreen parent;
14+
15+
public DifficultyTooltip(MITECraftingScreen parent) {
16+
this.parent = parent;
17+
}
18+
19+
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY) {
20+
// 检查鼠标是否悬停在制作网格上
21+
for (int slot = 1; slot <= 9; slot++) {
22+
if (isHoveringSlot(slot, mouseX, mouseY)) {
23+
renderSlotDifficultyTooltip(guiGraphics, slot, mouseX, mouseY);
24+
break;
25+
}
26+
}
27+
}
28+
29+
private boolean isHoveringSlot(int slot, int mouseX, int mouseY) {
30+
int slotX = getSlotX(slot);
31+
int slotY = getSlotY(slot);
32+
// 通过 parent 调用 isHovering 方法
33+
return parent.isHoveringSlot(slotX, slotY, 16, 16, mouseX, mouseY);
34+
}
35+
36+
private int getSlotX(int slot) {
37+
int col = (slot - 1) % 3;
38+
return 30 + col * 18;
39+
}
40+
41+
private int getSlotY(int slot) {
42+
int row = (slot - 1) / 3;
43+
return 17 + row * 18;
44+
}
45+
46+
private void renderSlotDifficultyTooltip(GuiGraphics guiGraphics, int slot, int mouseX, int mouseY) {
47+
ItemStack stack = parent.getMenu().getSlot(slot).getItem();
48+
if (stack.isEmpty()) return;
49+
50+
List<Component> tooltip = Lists.newArrayList();
51+
52+
// 显示物品的制作难度贡献
53+
int itemDifficulty = CraftingDifficultyCalculator.getItemDifficulty(stack);
54+
if (itemDifficulty > 0) {
55+
ChatFormatting color = getDifficultyColor(itemDifficulty);
56+
tooltip.add(Component.translatable("gui.infinityway.mite.item.difficulty", itemDifficulty)
57+
.withStyle(color));
58+
59+
// 显示材质等级
60+
String tier = CraftingDifficultyCalculator.getItemTier(stack);
61+
if (tier != null) {
62+
tooltip.add(Component.translatable("gui.infinityway.mite.item.tier", tier)
63+
.withStyle(ChatFormatting.GRAY));
64+
}
65+
66+
// 显示制作时间贡献
67+
double timeContribution = CraftingDifficultyCalculator.calculateCraftingTimeSeconds(itemDifficulty);
68+
tooltip.add(Component.translatable("gui.infinityway.mite.item.time_contribution",
69+
formatTime(timeContribution)).withStyle(ChatFormatting.DARK_GRAY));
70+
}
71+
72+
if (!tooltip.isEmpty()) {
73+
guiGraphics.renderComponentTooltip(parent.getFont(), tooltip, mouseX, mouseY);
74+
}
75+
}
76+
77+
private ChatFormatting getDifficultyColor(int difficulty) {
78+
if (difficulty <= 100) return ChatFormatting.GREEN;
79+
if (difficulty <= 400) return ChatFormatting.YELLOW;
80+
if (difficulty <= 1600) return ChatFormatting.GOLD;
81+
if (difficulty <= 6400) return ChatFormatting.RED;
82+
return ChatFormatting.DARK_RED;
83+
}
84+
85+
private String formatTime(double seconds) {
86+
if (seconds < 1) return String.format("%.1fs", seconds);
87+
if (seconds < 60) return String.format("%.0fs", seconds);
88+
if (seconds < 3600) return String.format("%.1fm", seconds / 60);
89+
return String.format("%.1fh", seconds / 3600);
90+
}
91+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package huix.infinity.common.client.screen;
2+
3+
import huix.infinity.common.world.inventory.TimedCraftingContainer;
4+
import net.minecraft.client.gui.GuiGraphics;
5+
import net.minecraft.client.gui.Font;
6+
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
7+
import net.minecraft.network.chat.Component;
8+
import net.minecraft.resources.ResourceLocation;
9+
import net.minecraft.world.entity.player.Inventory;
10+
import org.jetbrains.annotations.NotNull;
11+
12+
/**
13+
* MITE合成系统的GUI界面
14+
*/
15+
public class MITECraftingScreen extends AbstractContainerScreen<TimedCraftingContainer> {
16+
17+
private static final ResourceLocation CRAFTING_TABLE_LOCATION =
18+
new ResourceLocation("textures/gui/container/crafting_table.png");
19+
20+
private final DifficultyTooltip difficultyTooltip;
21+
private final CraftingProgressBar progressBar;
22+
private final TimeEstimateWidget timeWidget;
23+
24+
public MITECraftingScreen(TimedCraftingContainer menu, Inventory playerInventory, Component title) {
25+
super(menu, playerInventory, title);
26+
this.difficultyTooltip = new DifficultyTooltip(this);
27+
this.progressBar = new CraftingProgressBar(this);
28+
this.timeWidget = new TimeEstimateWidget(this);
29+
}
30+
31+
@Override
32+
protected void init() {
33+
super.init();
34+
this.titleLabelX = (this.imageWidth - this.font.width(this.title)) / 2;
35+
}
36+
37+
@Override
38+
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
39+
super.render(guiGraphics, mouseX, mouseY, partialTick);
40+
41+
// 渲染制作进度条
42+
this.progressBar.render(guiGraphics, mouseX, mouseY);
43+
44+
// 渲染时间估算组件
45+
this.timeWidget.render(guiGraphics, mouseX, mouseY);
46+
47+
// 渲染物品提示(最后渲染,确保在最上层)
48+
this.renderTooltip(guiGraphics, mouseX, mouseY);
49+
this.difficultyTooltip.render(guiGraphics, mouseX, mouseY);
50+
}
51+
52+
@Override
53+
protected void renderBg(@NotNull GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) {
54+
int x = (this.width - this.imageWidth) / 2;
55+
int y = (this.height - this.imageHeight) / 2;
56+
guiGraphics.blit(CRAFTING_TABLE_LOCATION, x, y, 0, 0, this.imageWidth, this.imageHeight);
57+
}
58+
59+
@Override
60+
protected void renderLabels(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) {
61+
super.renderLabels(guiGraphics, mouseX, mouseY);
62+
63+
// 显示制作难度信息
64+
if (this.menu.hasValidRecipe()) {
65+
String difficultyText = "难度: " + this.menu.getCurrentDifficulty();
66+
guiGraphics.drawString(this.font, difficultyText, 8, 73, 0x404040, false);
67+
68+
String tierText = "需要: " + this.menu.getRequiredTier();
69+
guiGraphics.drawString(this.font, tierText, 8, 83, 0x404040, false);
70+
}
71+
}
72+
73+
/**
74+
* 检查鼠标是否悬停在指定区域
75+
*/
76+
public boolean isHoveringSlot(int x, int y, int width, int height, int mouseX, int mouseY) {
77+
int screenX = this.leftPos + x;
78+
int screenY = this.topPos + y;
79+
return mouseX >= screenX && mouseX < screenX + width &&
80+
mouseY >= screenY && mouseY < screenY + height;
81+
}
82+
83+
/**
84+
* 获取字体对象
85+
*/
86+
public Font getFont() {
87+
return this.font;
88+
}
89+
90+
/**
91+
* 获取左上角位置
92+
*/
93+
public int getLeftPos() {
94+
return this.leftPos;
95+
}
96+
97+
/**
98+
* 获取左上角位置
99+
*/
100+
public int getTopPos() {
101+
return this.topPos;
102+
}
103+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package huix.infinity.common.client.screen;
2+
3+
import net.minecraft.ChatFormatting;
4+
import net.minecraft.client.gui.GuiGraphics;
5+
import net.minecraft.network.chat.Component;
6+
7+
/**
8+
* 时间估算显示组件
9+
*/
10+
public class TimeEstimateWidget {
11+
private final MITECraftingScreen parent;
12+
13+
public TimeEstimateWidget(MITECraftingScreen parent) {
14+
this.parent = parent;
15+
}
16+
17+
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY) {
18+
if (!parent.getMenu().hasValidRecipe()) return;
19+
20+
int x = parent.getLeftPos() + 8;
21+
int y = parent.getTopPos() + 93;
22+
23+
// 显示预估制作时间
24+
double estimatedTime = parent.getMenu().getEstimatedTimeSeconds();
25+
String timeText = formatTime(estimatedTime);
26+
27+
ChatFormatting color = getTimeColor(estimatedTime);
28+
Component timeComponent = Component.literal("预估时间: " + timeText).withStyle(color);
29+
30+
guiGraphics.drawString(parent.getFont(), timeComponent, x, y, 0xFFFFFF, false);
31+
}
32+
33+
private String formatTime(double seconds) {
34+
if (seconds < 1) return String.format("%.1fs", seconds);
35+
if (seconds < 60) return String.format("%.0fs", seconds);
36+
if (seconds < 3600) return String.format("%.1fm", seconds / 60);
37+
return String.format("%.1fh", seconds / 3600);
38+
}
39+
40+
private ChatFormatting getTimeColor(double seconds) {
41+
if (seconds <= 5) return ChatFormatting.GREEN;
42+
if (seconds <= 30) return ChatFormatting.YELLOW;
43+
if (seconds <= 120) return ChatFormatting.GOLD;
44+
if (seconds <= 600) return ChatFormatting.RED;
45+
return ChatFormatting.DARK_RED;
46+
}
47+
}

0 commit comments

Comments
 (0)