成功修复扩展样板供应器在整合包中的显示问题
This commit is contained in:
parent
d270c7e556
commit
5c58f9884c
|
|
@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(value = ContainerExPatternProvider.class, priority = 1001)
|
||||
@Mixin(value = ContainerExPatternProvider.class, priority = 3000)
|
||||
public abstract class ContainerExPatternProviderMixin extends PatternProviderMenu {
|
||||
|
||||
@GuiSync(11451)
|
||||
|
|
@ -28,6 +28,9 @@ public abstract class ContainerExPatternProviderMixin extends PatternProviderMen
|
|||
@Unique
|
||||
public int maxPage = 0;
|
||||
|
||||
@Unique
|
||||
private static final int SLOTS_PER_PAGE = 36; // 每页显示36个槽位
|
||||
|
||||
public ContainerExPatternProviderMixin(MenuType<? extends PatternProviderMenu> menuType, int id, Inventory playerInventory, PatternProviderLogicHost host) {
|
||||
super(menuType, id, playerInventory, host);
|
||||
}
|
||||
|
|
@ -35,28 +38,28 @@ public abstract class ContainerExPatternProviderMixin extends PatternProviderMen
|
|||
@Unique
|
||||
public void showPage() {
|
||||
List<Slot> slots = this.getSlots(SlotSemantics.ENCODED_PATTERN);
|
||||
int totalSlots = slots.size();
|
||||
|
||||
// 如果总槽位数不超过36个,不需要翻页
|
||||
if (totalSlots <= SLOTS_PER_PAGE) {
|
||||
for (Slot s : slots) {
|
||||
((AppEngSlot) s).setActive(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int slot_id = 0;
|
||||
|
||||
for (Slot s : slots) {
|
||||
int page_id = slot_id / 36;
|
||||
int page_id = slot_id / SLOTS_PER_PAGE;
|
||||
|
||||
if (page_id > 0 && page_id == this.page) {
|
||||
// 使用反射修改槽位位置
|
||||
try {
|
||||
Field xField = Slot.class.getDeclaredField("x");
|
||||
Field yField = Slot.class.getDeclaredField("y");
|
||||
xField.setAccessible(true);
|
||||
yField.setAccessible(true);
|
||||
|
||||
Slot baseSlot = slots.get(slot_id % 36);
|
||||
xField.set(s, xField.get(baseSlot));
|
||||
yField.set(s, yField.get(baseSlot));
|
||||
} catch (Exception e) {
|
||||
// 忽略反射错误
|
||||
}
|
||||
if (page_id == this.page) {
|
||||
// 当前页的槽位激活
|
||||
((AppEngSlot) s).setActive(true);
|
||||
} else {
|
||||
// 其他页的槽位隐藏
|
||||
((AppEngSlot) s).setActive(false);
|
||||
}
|
||||
|
||||
((AppEngSlot) s).setActive(page_id == this.page);
|
||||
++slot_id;
|
||||
}
|
||||
}
|
||||
|
|
@ -64,7 +67,7 @@ public abstract class ContainerExPatternProviderMixin extends PatternProviderMen
|
|||
@Inject(method = "<init>", at = @At("TAIL"), remap = false)
|
||||
public void init(int id, Inventory playerInventory, PatternProviderLogicHost host, CallbackInfo ci) {
|
||||
int maxSlots = this.getSlots(SlotSemantics.ENCODED_PATTERN).size();
|
||||
this.maxPage = (maxSlots + 36 - 1) / 36;
|
||||
this.maxPage = (maxSlots + SLOTS_PER_PAGE - 1) / SLOTS_PER_PAGE;
|
||||
}
|
||||
|
||||
@Unique
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import net.minecraft.client.gui.Font;
|
|||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
|
@ -22,6 +23,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(GuiExPatternProvider.class)
|
||||
public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<ContainerExPatternProvider> {
|
||||
|
|
@ -32,6 +34,9 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
|||
@Unique
|
||||
private VerticalButtonBar rightToolbar;
|
||||
|
||||
@Unique
|
||||
private static final int SLOTS_PER_PAGE = 36; // 每页显示36个槽位
|
||||
|
||||
public GuiExPatternProviderMixin(ContainerExPatternProvider menu, Inventory playerInventory, Component title, ScreenStyle style) {
|
||||
super(menu, playerInventory, title, style);
|
||||
}
|
||||
|
|
@ -41,7 +46,8 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
|||
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
|
||||
int maxSlots = this.getMenu().getSlots(SlotSemantics.ENCODED_PATTERN).size();
|
||||
if (maxSlots > 36) {
|
||||
// 只有当槽位数超过每页显示数量时才显示翻页信息
|
||||
if (maxSlots > SLOTS_PER_PAGE) {
|
||||
Font fontRenderer = Minecraft.getInstance().font;
|
||||
|
||||
// 获取当前页码
|
||||
|
|
@ -79,6 +85,69 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
|||
this.nextPage.setVisibility(page + 1 < maxPage);
|
||||
this.prevPage.setVisibility(page - 1 >= 0);
|
||||
}
|
||||
|
||||
// 调整槽位位置
|
||||
this.adjustSlotPositions(page);
|
||||
} catch (Exception e) {
|
||||
// 忽略反射错误
|
||||
}
|
||||
}
|
||||
|
||||
@Unique
|
||||
private void adjustSlotPositions(int currentPage) {
|
||||
try {
|
||||
List<Slot> slots = this.getMenu().getSlots(SlotSemantics.ENCODED_PATTERN);
|
||||
int totalSlots = slots.size();
|
||||
|
||||
if (totalSlots <= SLOTS_PER_PAGE) {
|
||||
return; // 不需要翻页
|
||||
}
|
||||
|
||||
int slot_id = 0;
|
||||
for (Slot s : slots) {
|
||||
int page_id = slot_id / SLOTS_PER_PAGE;
|
||||
|
||||
if (page_id == currentPage) {
|
||||
// 当前页的槽位需要调整位置
|
||||
int slotInPage = slot_id % SLOTS_PER_PAGE;
|
||||
int row = slotInPage / 9; // 0-3
|
||||
int col = slotInPage % 9; // 0-8
|
||||
|
||||
// 计算目标位置(始终在前4行)
|
||||
int x = 8 + col * 18;
|
||||
int y = 42 + row * 18;
|
||||
|
||||
// 使用反射设置槽位位置,支持混淆环境
|
||||
Field xField = null;
|
||||
Field yField = null;
|
||||
|
||||
// 尝试不同的字段名(开发环境和生产环境可能不同)
|
||||
String[] xFieldNames = {"x", "field_75262_c"};
|
||||
String[] yFieldNames = {"y", "field_75263_d"};
|
||||
|
||||
for (String fieldName : xFieldNames) {
|
||||
try {
|
||||
xField = Slot.class.getDeclaredField(fieldName);
|
||||
xField.setAccessible(true);
|
||||
break;
|
||||
} catch (NoSuchFieldException ignored) {}
|
||||
}
|
||||
|
||||
for (String fieldName : yFieldNames) {
|
||||
try {
|
||||
yField = Slot.class.getDeclaredField(fieldName);
|
||||
yField.setAccessible(true);
|
||||
break;
|
||||
} catch (NoSuchFieldException ignored) {}
|
||||
}
|
||||
|
||||
if (xField != null && yField != null) {
|
||||
xField.set(s, x);
|
||||
yField.set(s, y);
|
||||
}
|
||||
}
|
||||
++slot_id;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 忽略反射错误
|
||||
}
|
||||
|
|
@ -116,37 +185,41 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
|||
this.screenStyle = style;
|
||||
this.rightToolbar = new VerticalButtonBar();
|
||||
|
||||
// 前进后退按钮
|
||||
this.prevPage = new ActionEPPButton((b) -> {
|
||||
int currentPage = getCurrentPage();
|
||||
if (currentPage > 0) {
|
||||
// 发送网络包更新页码
|
||||
// 这里简化处理,直接调用setPage方法
|
||||
try {
|
||||
ContainerExPatternProvider menu1 = this.getMenu();
|
||||
java.lang.reflect.Method setPageMethod = menu1.getClass().getMethod("setPage", int.class);
|
||||
setPageMethod.invoke(menu1, currentPage - 1);
|
||||
} catch (Exception e) {
|
||||
// 忽略反射错误
|
||||
// 只有当槽位数超过每页显示数量时才添加翻页按钮
|
||||
int maxSlots = this.getMenu().getSlots(SlotSemantics.ENCODED_PATTERN).size();
|
||||
if (maxSlots > SLOTS_PER_PAGE) {
|
||||
// 前进后退按钮
|
||||
this.prevPage = new ActionEPPButton((b) -> {
|
||||
int currentPage = getCurrentPage();
|
||||
if (currentPage > 0) {
|
||||
// 发送网络包更新页码
|
||||
// 这里简化处理,直接调用setPage方法
|
||||
try {
|
||||
ContainerExPatternProvider menu1 = this.getMenu();
|
||||
java.lang.reflect.Method setPageMethod = menu1.getClass().getMethod("setPage", int.class);
|
||||
setPageMethod.invoke(menu1, currentPage - 1);
|
||||
} catch (Exception e) {
|
||||
// 忽略反射错误
|
||||
}
|
||||
}
|
||||
}
|
||||
}, Icon.ARROW_LEFT);
|
||||
}, Icon.ARROW_LEFT);
|
||||
|
||||
this.nextPage = new ActionEPPButton((b) -> {
|
||||
int currentPage = getCurrentPage();
|
||||
int maxPage = getMaxPage();
|
||||
if (currentPage + 1 < maxPage) {
|
||||
try {
|
||||
ContainerExPatternProvider menu1 = this.getMenu();
|
||||
java.lang.reflect.Method setPageMethod = menu1.getClass().getMethod("setPage", int.class);
|
||||
setPageMethod.invoke(menu1, currentPage + 1);
|
||||
} catch (Exception e) {
|
||||
// 忽略反射错误
|
||||
this.nextPage = new ActionEPPButton((b) -> {
|
||||
int currentPage = getCurrentPage();
|
||||
int maxPage = getMaxPage();
|
||||
if (currentPage + 1 < maxPage) {
|
||||
try {
|
||||
ContainerExPatternProvider menu1 = this.getMenu();
|
||||
java.lang.reflect.Method setPageMethod = menu1.getClass().getMethod("setPage", int.class);
|
||||
setPageMethod.invoke(menu1, currentPage + 1);
|
||||
} catch (Exception e) {
|
||||
// 忽略反射错误
|
||||
}
|
||||
}
|
||||
}
|
||||
}, Icon.ARROW_RIGHT);
|
||||
}, Icon.ARROW_RIGHT);
|
||||
|
||||
this.addToLeftToolbar(this.nextPage);
|
||||
this.addToLeftToolbar(this.prevPage);
|
||||
this.addToLeftToolbar(this.nextPage);
|
||||
this.addToLeftToolbar(this.prevPage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package com.extendedae_plus.mixin;
|
||||
|
||||
import com.glodblock.github.extendedae.common.parts.PartExPatternProvider;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
|
||||
@Mixin(PartExPatternProvider.class)
|
||||
public class PartExPatternProviderMixin {
|
||||
|
||||
@ModifyConstant(method = "createLogic", remap = false, constant = @Constant(intValue = 36))
|
||||
private int modifyContainer(int constant) {
|
||||
return 108;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package com.extendedae_plus.mixin;
|
||||
|
||||
import com.glodblock.github.extendedae.common.tileentities.TileExPatternProvider;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
|
||||
@Mixin(TileExPatternProvider.class)
|
||||
public class TileExPatternProviderMixin {
|
||||
|
||||
@ModifyConstant(method = "createLogic", remap = false, constant = @Constant(intValue = 36))
|
||||
private int modifyContainer(int constant) {
|
||||
return 108;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,11 +4,10 @@
|
|||
"compatibilityLevel": "JAVA_17",
|
||||
"minVersion": "0.8",
|
||||
"client": [
|
||||
"GuiExPatternProviderMixin"
|
||||
"GuiExPatternProviderMixin",
|
||||
"SlotGridLayoutMixin"
|
||||
],
|
||||
"mixins": [
|
||||
"PartExPatternProviderMixin",
|
||||
"TileExPatternProviderMixin",
|
||||
"ContainerExPatternProviderMixin"
|
||||
],
|
||||
"injectors": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user