Merge pull request #5 from C-H716/feature/provider_display
优化处理样板数量显示,支持样板供应器、样板管理终端显示
This commit is contained in:
commit
5242589bf3
|
|
@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||
loom.platform = forge
|
||||
|
||||
# Mod properties
|
||||
mod_version = 1.3.2-fix1
|
||||
mod_version = 1.3.3-beta
|
||||
maven_group = com.extendedae_plus
|
||||
archives_name = extendedae_plus
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,22 @@
|
|||
package com.extendedae_plus.mixin.ae2;
|
||||
|
||||
import appeng.client.Point;
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.TextOverride;
|
||||
import appeng.client.Point;
|
||||
import appeng.client.gui.style.PaletteColor;
|
||||
import appeng.client.gui.style.ScreenStyle;
|
||||
import appeng.client.gui.style.Text;
|
||||
import appeng.client.gui.style.TextAlignment;
|
||||
import appeng.menu.slot.AppEngSlot;
|
||||
import com.extendedae_plus.api.ExPatternPageAccessor;
|
||||
import com.extendedae_plus.util.GuiUtil;
|
||||
import com.glodblock.github.extendedae.client.gui.GuiExPatternProvider;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.renderer.Rect2i;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.contents.TranslatableContents;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
|
@ -65,6 +68,40 @@ public abstract class AEBaseScreenMixin {
|
|||
return net.minecraft.client.Minecraft.getInstance().font;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写renderSlot方法,为所有可见的样板槽位添加数量显示
|
||||
*/
|
||||
@Inject(method = "renderSlot", at = @At("TAIL"))
|
||||
private void eap$renderSlotAmounts(GuiGraphics guiGraphics, Slot s, CallbackInfo ci) {
|
||||
Object self = this;
|
||||
|
||||
// 只处理AppEngSlot类型的槽位
|
||||
if (!(s instanceof AppEngSlot appEngSlot)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查槽位是否可见且有效
|
||||
if (!appEngSlot.isActive() || !appEngSlot.isSlotEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取槽位中的物品
|
||||
var itemStack = appEngSlot.getItem();
|
||||
if (itemStack.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用GuiUtil的格式化方法获取数量文本
|
||||
String amountText = GuiUtil.getPatternOutputText(itemStack);
|
||||
if (amountText.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 在槽位右下角绘制数量文本
|
||||
Font font = eap$getFont(self);
|
||||
GuiUtil.drawAmountText(guiGraphics, font, amountText, appEngSlot.x, appEngSlot.y, 0.6f);
|
||||
}
|
||||
|
||||
// 在 AEBaseScreen.drawText 完成某个文本绘制后,若该文本为“样板”标签,则紧接着绘制页码。
|
||||
@Inject(method = "drawText", at = @At("TAIL"), remap = false)
|
||||
private void eap$appendPageAfterPatternsLabel(GuiGraphics guiGraphics,
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
package com.extendedae_plus.mixin.ae2;
|
||||
|
||||
import appeng.client.gui.me.patternaccess.PatternAccessTermScreen;
|
||||
import com.extendedae_plus.util.GuiUtil;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Mixin(PatternAccessTermScreen.class)
|
||||
public class PatternAccessTermScreenMixin {
|
||||
// 在绘制前景的最后阶段叠加显示样板输出数量
|
||||
@Inject(method = "drawFG", at = @At("TAIL"), remap = false)
|
||||
private void injectDrawCraftingAmount(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX, int mouseY, CallbackInfo ci) {
|
||||
PatternAccessTermScreen<?> screen = (PatternAccessTermScreen<?>)(Object) this;
|
||||
|
||||
// 调用GuiUtil的通用渲染方法
|
||||
GuiUtil.renderPatternAmounts(guiGraphics, screen);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +1,16 @@
|
|||
package com.extendedae_plus.mixin.ae2;
|
||||
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.Icon;
|
||||
import appeng.client.gui.implementations.PatternProviderScreen;
|
||||
import appeng.client.gui.style.ScreenStyle;
|
||||
import appeng.client.gui.widgets.SettingToggleButton;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.menu.implementations.PatternProviderMenu;
|
||||
import com.extendedae_plus.api.ExPatternButtonsAccessor;
|
||||
import com.extendedae_plus.api.PatternProviderMenuAdvancedSync;
|
||||
import com.extendedae_plus.network.ModNetwork;
|
||||
import com.extendedae_plus.network.ToggleAdvancedBlockingC2SPacket;
|
||||
import com.extendedae_plus.api.ExPatternButtonsAccessor;
|
||||
import com.glodblock.github.extendedae.client.gui.GuiExPatternProvider;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import appeng.client.gui.style.ScreenStyle;
|
|||
import appeng.client.gui.widgets.AETextField;
|
||||
import appeng.client.gui.widgets.IconButton;
|
||||
import appeng.menu.AEBaseMenu;
|
||||
import com.extendedae_plus.util.GuiUtil;
|
||||
import com.glodblock.github.extendedae.client.gui.GuiExPatternTerminal;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.Tooltip;
|
||||
|
|
@ -343,9 +342,6 @@ public abstract class GuiExPatternTerminalMixin extends AEBaseScreen<AEBaseMenu>
|
|||
|
||||
@Inject(method = "drawFG", at = @At("TAIL"), remap = false)
|
||||
private void eap$afterDrawFG(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX, int mouseY, CallbackInfo ci) {
|
||||
// 调用GuiUtil的通用渲染方法显示样板数量
|
||||
GuiUtil.renderPatternAmounts(guiGraphics, this);
|
||||
|
||||
// 原有的搜索高亮逻辑
|
||||
// 仅当任一搜索框非空时绘制叠加层(与原版行为保持一致)
|
||||
boolean searchActive = (this.searchOutField != null && !this.searchOutField.getValue().isEmpty())
|
||||
|
|
|
|||
|
|
@ -2,18 +2,11 @@ package com.extendedae_plus.util;
|
|||
|
||||
import appeng.api.crafting.PatternDetailsHelper;
|
||||
import appeng.api.stacks.GenericStack;
|
||||
import appeng.util.inv.AppEngInternalInventory;
|
||||
import com.extendedae_plus.mixin.ae2.accessor.PatternAccessTermScreenAccessor;
|
||||
import com.extendedae_plus.mixin.ae2.accessor.PatternAccessTermScreenSlotsRowAccessor;
|
||||
import com.extendedae_plus.mixin.extendedae.accessor.GuiExPatternTerminalAccessor;
|
||||
import com.extendedae_plus.mixin.extendedae.accessor.GuiExPatternTerminalSlotsRowAccessor;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
/**
|
||||
* GUI工具类,提供样板获取、绘制等通用功能
|
||||
|
|
@ -84,93 +77,4 @@ public class GuiUtil {
|
|||
guiGraphics.drawString(font, text, (int)(textX / scale), (int)(textY / scale), 0xFFFFFFFF, true);
|
||||
guiGraphics.pose().popPose();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 渲染样板管理终端的数量显示
|
||||
* @param guiGraphics GUI图形上下文
|
||||
* @param screen 屏幕对象
|
||||
*/
|
||||
public static void renderPatternAmounts(GuiGraphics guiGraphics, Object screen) {
|
||||
int scrollLevel;
|
||||
int visibleRows;
|
||||
ArrayList<?> rowsList;
|
||||
|
||||
if (screen instanceof PatternAccessTermScreenAccessor aeAccessor) {
|
||||
var scrollbar = aeAccessor.getScrollbar();
|
||||
if (scrollbar == null) return;
|
||||
scrollLevel = scrollbar.getCurrentScroll();
|
||||
visibleRows = aeAccessor.getVisibleRows();
|
||||
if (visibleRows <= 0) return;
|
||||
rowsList = aeAccessor.getRows();
|
||||
if (rowsList == null || rowsList.isEmpty()) return;
|
||||
} else if (screen instanceof GuiExPatternTerminalAccessor exAccessor) {
|
||||
var scrollbar = exAccessor.getScrollbar();
|
||||
if (scrollbar == null) return;
|
||||
scrollLevel = scrollbar.getCurrentScroll();
|
||||
visibleRows = exAccessor.getVisibleRows();
|
||||
if (visibleRows <= 0) return;
|
||||
rowsList = exAccessor.getRows();
|
||||
if (rowsList == null || rowsList.isEmpty()) return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
// 判断是否为ExtendedAE终端
|
||||
boolean isExtendedAE = screen instanceof GuiExPatternTerminalAccessor;
|
||||
|
||||
// 根据终端类型使用不同的常量(与 AE2/ExtendedAE 源码保持一致)
|
||||
final int SLOT_SIZE = 18; // ROW_HEIGHT == 18, SLOT_SIZE == ROW_HEIGHT
|
||||
final int GUI_PADDING_X = isExtendedAE ? 22 : 8; // ExtendedAE使用22,AE2使用8
|
||||
final int SLOT_Y_OFFSET = isExtendedAE ? 34 : 0; // ExtendedAE需要额外的Y偏移
|
||||
|
||||
var font = Minecraft.getInstance().font;
|
||||
|
||||
for (int i = 0; i < visibleRows; ++i) {
|
||||
int rowIdx = scrollLevel + i;
|
||||
if (rowIdx < 0 || rowIdx >= rowsList.size()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Object row = rowsList.get(rowIdx);
|
||||
if (row instanceof PatternAccessTermScreenSlotsRowAccessor slotsRow) {
|
||||
var container = slotsRow.getContainer();
|
||||
var inventory = container.getInventory();
|
||||
drawRowAmounts(guiGraphics, font, inventory, slotsRow.getOffset(), slotsRow.getSlots(), i, SLOT_SIZE, GUI_PADDING_X, SLOT_Y_OFFSET);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (row instanceof GuiExPatternTerminalSlotsRowAccessor exSlotsRow) {
|
||||
var container = exSlotsRow.getContainer();
|
||||
var inventory = container.getInventory();
|
||||
drawRowAmounts(guiGraphics, font, inventory, exSlotsRow.getOffset(), exSlotsRow.getSlots(), i, SLOT_SIZE, GUI_PADDING_X, SLOT_Y_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawRowAmounts(
|
||||
GuiGraphics guiGraphics,
|
||||
Font font,
|
||||
AppEngInternalInventory inventory,
|
||||
int offset,
|
||||
int slots,
|
||||
int visibleRowIndex,
|
||||
int slotSize,
|
||||
int guiPaddingX,
|
||||
int slotYOffset
|
||||
) {
|
||||
for (int col = 0; col < slots; col++) {
|
||||
int index = offset + col;
|
||||
var pattern = inventory.getStackInSlot(index);
|
||||
if (pattern == null || pattern.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
String amountText = getPatternOutputText(pattern);
|
||||
if (amountText.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
int slotX = col * slotSize + guiPaddingX;
|
||||
int slotY = (visibleRowIndex + 1) * slotSize + slotYOffset;
|
||||
drawAmountText(guiGraphics, font, amountText, slotX, slotY, 0.6f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,12 +4,11 @@
|
|||
"compatibilityLevel": "JAVA_17",
|
||||
"minVersion": "0.8",
|
||||
"client": [
|
||||
"ae2.AEBaseScreenMixin",
|
||||
"PickFromWirelessMixin",
|
||||
"accessor.AbstractContainerScreenAccessor",
|
||||
"accessor.ScreenAccessor",
|
||||
"accessor.ScreenInvoker",
|
||||
"ae2.PatternAccessTermScreenMixin",
|
||||
"ae2.AEBaseScreenMixin",
|
||||
"ae2.PatternEncodingTermScreenMixin",
|
||||
"ae2.PatternProviderScreenMixin",
|
||||
"ae2.QuartzCuttingKnifeItemMixin",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user