成功修复扩展样板供应器在整合包中的显示问题
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.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mixin(value = ContainerExPatternProvider.class, priority = 1001)
|
@Mixin(value = ContainerExPatternProvider.class, priority = 3000)
|
||||||
public abstract class ContainerExPatternProviderMixin extends PatternProviderMenu {
|
public abstract class ContainerExPatternProviderMixin extends PatternProviderMenu {
|
||||||
|
|
||||||
@GuiSync(11451)
|
@GuiSync(11451)
|
||||||
|
|
@ -28,6 +28,9 @@ public abstract class ContainerExPatternProviderMixin extends PatternProviderMen
|
||||||
@Unique
|
@Unique
|
||||||
public int maxPage = 0;
|
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) {
|
public ContainerExPatternProviderMixin(MenuType<? extends PatternProviderMenu> menuType, int id, Inventory playerInventory, PatternProviderLogicHost host) {
|
||||||
super(menuType, id, playerInventory, host);
|
super(menuType, id, playerInventory, host);
|
||||||
}
|
}
|
||||||
|
|
@ -35,28 +38,28 @@ public abstract class ContainerExPatternProviderMixin extends PatternProviderMen
|
||||||
@Unique
|
@Unique
|
||||||
public void showPage() {
|
public void showPage() {
|
||||||
List<Slot> slots = this.getSlots(SlotSemantics.ENCODED_PATTERN);
|
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;
|
int slot_id = 0;
|
||||||
|
|
||||||
for (Slot s : slots) {
|
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) {
|
if (page_id == this.page) {
|
||||||
// 使用反射修改槽位位置
|
// 当前页的槽位激活
|
||||||
try {
|
((AppEngSlot) s).setActive(true);
|
||||||
Field xField = Slot.class.getDeclaredField("x");
|
} else {
|
||||||
Field yField = Slot.class.getDeclaredField("y");
|
// 其他页的槽位隐藏
|
||||||
xField.setAccessible(true);
|
((AppEngSlot) s).setActive(false);
|
||||||
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) {
|
|
||||||
// 忽略反射错误
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
((AppEngSlot) s).setActive(page_id == this.page);
|
|
||||||
++slot_id;
|
++slot_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +67,7 @@ public abstract class ContainerExPatternProviderMixin extends PatternProviderMen
|
||||||
@Inject(method = "<init>", at = @At("TAIL"), remap = false)
|
@Inject(method = "<init>", at = @At("TAIL"), remap = false)
|
||||||
public void init(int id, Inventory playerInventory, PatternProviderLogicHost host, CallbackInfo ci) {
|
public void init(int id, Inventory playerInventory, PatternProviderLogicHost host, CallbackInfo ci) {
|
||||||
int maxSlots = this.getSlots(SlotSemantics.ENCODED_PATTERN).size();
|
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
|
@Unique
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.inventory.Slot;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mixin(GuiExPatternProvider.class)
|
@Mixin(GuiExPatternProvider.class)
|
||||||
public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<ContainerExPatternProvider> {
|
public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<ContainerExPatternProvider> {
|
||||||
|
|
@ -32,6 +34,9 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
||||||
@Unique
|
@Unique
|
||||||
private VerticalButtonBar rightToolbar;
|
private VerticalButtonBar rightToolbar;
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private static final int SLOTS_PER_PAGE = 36; // 每页显示36个槽位
|
||||||
|
|
||||||
public GuiExPatternProviderMixin(ContainerExPatternProvider menu, Inventory playerInventory, Component title, ScreenStyle style) {
|
public GuiExPatternProviderMixin(ContainerExPatternProvider menu, Inventory playerInventory, Component title, ScreenStyle style) {
|
||||||
super(menu, playerInventory, title, style);
|
super(menu, playerInventory, title, style);
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +46,8 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
||||||
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||||
|
|
||||||
int maxSlots = this.getMenu().getSlots(SlotSemantics.ENCODED_PATTERN).size();
|
int maxSlots = this.getMenu().getSlots(SlotSemantics.ENCODED_PATTERN).size();
|
||||||
if (maxSlots > 36) {
|
// 只有当槽位数超过每页显示数量时才显示翻页信息
|
||||||
|
if (maxSlots > SLOTS_PER_PAGE) {
|
||||||
Font fontRenderer = Minecraft.getInstance().font;
|
Font fontRenderer = Minecraft.getInstance().font;
|
||||||
|
|
||||||
// 获取当前页码
|
// 获取当前页码
|
||||||
|
|
@ -79,6 +85,69 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
||||||
this.nextPage.setVisibility(page + 1 < maxPage);
|
this.nextPage.setVisibility(page + 1 < maxPage);
|
||||||
this.prevPage.setVisibility(page - 1 >= 0);
|
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) {
|
} catch (Exception e) {
|
||||||
// 忽略反射错误
|
// 忽略反射错误
|
||||||
}
|
}
|
||||||
|
|
@ -116,37 +185,41 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
||||||
this.screenStyle = style;
|
this.screenStyle = style;
|
||||||
this.rightToolbar = new VerticalButtonBar();
|
this.rightToolbar = new VerticalButtonBar();
|
||||||
|
|
||||||
// 前进后退按钮
|
// 只有当槽位数超过每页显示数量时才添加翻页按钮
|
||||||
this.prevPage = new ActionEPPButton((b) -> {
|
int maxSlots = this.getMenu().getSlots(SlotSemantics.ENCODED_PATTERN).size();
|
||||||
int currentPage = getCurrentPage();
|
if (maxSlots > SLOTS_PER_PAGE) {
|
||||||
if (currentPage > 0) {
|
// 前进后退按钮
|
||||||
// 发送网络包更新页码
|
this.prevPage = new ActionEPPButton((b) -> {
|
||||||
// 这里简化处理,直接调用setPage方法
|
int currentPage = getCurrentPage();
|
||||||
try {
|
if (currentPage > 0) {
|
||||||
ContainerExPatternProvider menu1 = this.getMenu();
|
// 发送网络包更新页码
|
||||||
java.lang.reflect.Method setPageMethod = menu1.getClass().getMethod("setPage", int.class);
|
// 这里简化处理,直接调用setPage方法
|
||||||
setPageMethod.invoke(menu1, currentPage - 1);
|
try {
|
||||||
} catch (Exception e) {
|
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) -> {
|
this.nextPage = new ActionEPPButton((b) -> {
|
||||||
int currentPage = getCurrentPage();
|
int currentPage = getCurrentPage();
|
||||||
int maxPage = getMaxPage();
|
int maxPage = getMaxPage();
|
||||||
if (currentPage + 1 < maxPage) {
|
if (currentPage + 1 < maxPage) {
|
||||||
try {
|
try {
|
||||||
ContainerExPatternProvider menu1 = this.getMenu();
|
ContainerExPatternProvider menu1 = this.getMenu();
|
||||||
java.lang.reflect.Method setPageMethod = menu1.getClass().getMethod("setPage", int.class);
|
java.lang.reflect.Method setPageMethod = menu1.getClass().getMethod("setPage", int.class);
|
||||||
setPageMethod.invoke(menu1, currentPage + 1);
|
setPageMethod.invoke(menu1, currentPage + 1);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 忽略反射错误
|
// 忽略反射错误
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}, Icon.ARROW_RIGHT);
|
||||||
}, Icon.ARROW_RIGHT);
|
|
||||||
|
|
||||||
this.addToLeftToolbar(this.nextPage);
|
this.addToLeftToolbar(this.nextPage);
|
||||||
this.addToLeftToolbar(this.prevPage);
|
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",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"minVersion": "0.8",
|
"minVersion": "0.8",
|
||||||
"client": [
|
"client": [
|
||||||
"GuiExPatternProviderMixin"
|
"GuiExPatternProviderMixin",
|
||||||
|
"SlotGridLayoutMixin"
|
||||||
],
|
],
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"PartExPatternProviderMixin",
|
|
||||||
"TileExPatternProviderMixin",
|
|
||||||
"ContainerExPatternProviderMixin"
|
"ContainerExPatternProviderMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user