feat:
一、调整样板供应器状态控制器界面样式,使用ae背景图片 二、添加全局设置样板供应器级别翻倍限制
This commit is contained in:
parent
60be80c397
commit
35057b1237
|
|
@ -1,108 +1,243 @@
|
|||
package com.extendedae_plus.client.screen;
|
||||
|
||||
import appeng.client.gui.Icon;
|
||||
import com.extendedae_plus.menu.NetworkPatternControllerMenu;
|
||||
import com.extendedae_plus.network.GlobalToggleProviderModesC2SPacket;
|
||||
import com.extendedae_plus.network.SetGlobalScalingLimitC2SPacket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class GlobalProviderModesScreen extends AbstractContainerScreen<NetworkPatternControllerMenu> {
|
||||
private static final Component CUSTOM_TITLE = Component.translatable("extendedae_plus.screen.global_controller_title");
|
||||
private static final Component CUSTOM_TITLE = Component.translatable("block.extendedae_plus.network_pattern_controller");
|
||||
private static final ResourceLocation BACKGROUND = ResourceLocation.fromNamespaceAndPath("ae2", "textures/guis/background.png");
|
||||
|
||||
private EditBox inputField;
|
||||
private static final int INPUT_WIDTH = 50;
|
||||
private static final int INPUT_HEIGHT = 14;
|
||||
|
||||
// 布局常量
|
||||
private static final int IMAGE_WIDTH = 210;
|
||||
private static final int IMAGE_HEIGHT = 165;
|
||||
private static final int BTN_W = 62;
|
||||
private static final int BTN_H = 18;
|
||||
private static final int BTN_SPACING = 6;
|
||||
private static final int START_Y = 25;
|
||||
private static final int LABEL_INPUT_SPACING = 18;
|
||||
|
||||
// AE2 风格按钮颜色
|
||||
private static final int BTN_BG = 0xFF3A3A3A;
|
||||
private static final int BTN_BG_HOVER = 0xFF4A4A4A;
|
||||
private static final int BTN_BORDER_LIGHT = 0xFFAAAAAA;
|
||||
private static final int BTN_BORDER_DARK = 0xFF555555;
|
||||
|
||||
public GlobalProviderModesScreen(NetworkPatternControllerMenu menu, Inventory inv, Component title) {
|
||||
super(menu, inv, title);
|
||||
this.imageWidth = 240;
|
||||
this.imageHeight = 140;
|
||||
this.imageWidth = IMAGE_WIDTH;
|
||||
this.imageHeight = IMAGE_HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
int w = 70; // 按钮宽
|
||||
int h = 20; // 按钮高
|
||||
int s = 8; // 按钮间距
|
||||
int y = this.topPos + 28; // 第一行 Y
|
||||
// 计算三列按钮的左侧起点,使其在面板内水平居中
|
||||
int totalW3 = w * 3 + s * 2;
|
||||
int x = this.leftPos + (this.imageWidth - totalW3) / 2;
|
||||
|
||||
// 行1:三个单项切换
|
||||
this.addRenderableWidget(Button.builder(Component.translatable("gui.extendedae_plus.global.toggle_blocking"), b ->
|
||||
int centerX = this.leftPos + this.imageWidth / 2;
|
||||
int row1Y = this.topPos + START_Y;
|
||||
int row2Y = row1Y + BTN_H + BTN_SPACING;
|
||||
int row3Y = row2Y + BTN_H + BTN_SPACING;
|
||||
|
||||
// 第一行:三个切换按钮,居中
|
||||
int totalW3 = BTN_W * 3 + BTN_SPACING * 2;
|
||||
int row1X = centerX - totalW3 / 2;
|
||||
|
||||
addRenderableWidget(new AEStyleButton(row1X, row1Y, BTN_W, BTN_H,
|
||||
Component.translatable("gui.extendedae_plus.global.toggle_blocking"), b ->
|
||||
PacketDistributor.sendToServer(new GlobalToggleProviderModesC2SPacket(
|
||||
GlobalToggleProviderModesC2SPacket.Operation.TOGGLE,
|
||||
GlobalToggleProviderModesC2SPacket.Operation.NOOP,
|
||||
GlobalToggleProviderModesC2SPacket.Operation.NOOP,
|
||||
this.menu.getBlockEntityPos()
|
||||
))).bounds(x, y, w, h).build());
|
||||
))));
|
||||
|
||||
this.addRenderableWidget(Button.builder(Component.translatable("gui.extendedae_plus.global.toggle_adv_blocking"), b ->
|
||||
addRenderableWidget(new AEStyleButton(row1X + BTN_W + BTN_SPACING, row1Y, BTN_W, BTN_H,
|
||||
Component.translatable("gui.extendedae_plus.global.toggle_adv_blocking"), b ->
|
||||
PacketDistributor.sendToServer(new GlobalToggleProviderModesC2SPacket(
|
||||
GlobalToggleProviderModesC2SPacket.Operation.NOOP,
|
||||
GlobalToggleProviderModesC2SPacket.Operation.TOGGLE,
|
||||
GlobalToggleProviderModesC2SPacket.Operation.NOOP,
|
||||
this.menu.getBlockEntityPos()
|
||||
))).bounds(x + w + s, y, w, h).build());
|
||||
))));
|
||||
|
||||
this.addRenderableWidget(Button.builder(Component.translatable("gui.extendedae_plus.global.toggle_smart_doubling"), b ->
|
||||
addRenderableWidget(new AEStyleButton(row1X + (BTN_W + BTN_SPACING) * 2, row1Y, BTN_W, BTN_H,
|
||||
Component.translatable("gui.extendedae_plus.global.toggle_smart_doubling"), b ->
|
||||
PacketDistributor.sendToServer(new GlobalToggleProviderModesC2SPacket(
|
||||
GlobalToggleProviderModesC2SPacket.Operation.NOOP,
|
||||
GlobalToggleProviderModesC2SPacket.Operation.NOOP,
|
||||
GlobalToggleProviderModesC2SPacket.Operation.TOGGLE,
|
||||
this.menu.getBlockEntityPos()
|
||||
))).bounds(x + (w + s) * 2, y, w, h).build());
|
||||
))));
|
||||
|
||||
// 行2:一键全开/全关
|
||||
int y2 = y + h + 12;
|
||||
// 第二行:两列按钮,总宽并居中
|
||||
int totalW2 = w * 2 + s;
|
||||
int x2 = this.leftPos + (this.imageWidth - totalW2) / 2;
|
||||
this.addRenderableWidget(Button.builder(Component.translatable("gui.extendedae_plus.global.all_on"), b ->
|
||||
// 第二行:全开/全关按钮,居中
|
||||
int totalW2 = BTN_W * 2 + BTN_SPACING;
|
||||
int row2X = centerX - totalW2 / 2;
|
||||
|
||||
addRenderableWidget(new AEStyleButton(row2X, row2Y, BTN_W, BTN_H,
|
||||
Component.translatable("gui.extendedae_plus.global.all_on"), b ->
|
||||
PacketDistributor.sendToServer(new GlobalToggleProviderModesC2SPacket(
|
||||
GlobalToggleProviderModesC2SPacket.Operation.SET_TRUE,
|
||||
GlobalToggleProviderModesC2SPacket.Operation.SET_TRUE,
|
||||
GlobalToggleProviderModesC2SPacket.Operation.SET_TRUE,
|
||||
this.menu.getBlockEntityPos()
|
||||
))).bounds(x2, y2, w, h).build());
|
||||
))));
|
||||
|
||||
this.addRenderableWidget(Button.builder(Component.translatable("gui.extendedae_plus.global.all_off"), b ->
|
||||
addRenderableWidget(new AEStyleButton(row2X + BTN_W + BTN_SPACING, row2Y, BTN_W, BTN_H,
|
||||
Component.translatable("gui.extendedae_plus.global.all_off"), b ->
|
||||
PacketDistributor.sendToServer(new GlobalToggleProviderModesC2SPacket(
|
||||
GlobalToggleProviderModesC2SPacket.Operation.SET_FALSE,
|
||||
GlobalToggleProviderModesC2SPacket.Operation.SET_FALSE,
|
||||
GlobalToggleProviderModesC2SPacket.Operation.SET_FALSE,
|
||||
this.menu.getBlockEntityPos()
|
||||
))).bounds(x2 + w + s, y2, w, h).build());
|
||||
))));
|
||||
|
||||
// 输入框区域 - 整体居中布局
|
||||
int inputRowY = row3Y + LABEL_INPUT_SPACING;
|
||||
int labelWidth = this.font.width(Component.translatable("gui.extendedae_plus.global.supplier_doubling_limit"));
|
||||
int totalWidth = labelWidth + 8 + INPUT_WIDTH + 6 + 18; // 标签 + 间距 + 输入框 + 间距 + 按钮(18宽)
|
||||
int startX = centerX - totalWidth / 2;
|
||||
int labelX = startX;
|
||||
int inputX = startX + labelWidth + 8;
|
||||
int confirmX = inputX + INPUT_WIDTH + 6;
|
||||
|
||||
inputField = createInputField(inputX, inputRowY + 2);
|
||||
this.addRenderableWidget(inputField);
|
||||
|
||||
addRenderableWidget(new AEConfirmButton(confirmX, inputRowY,
|
||||
Component.translatable("gui.extendedae_plus.global.confirm_tooltip"), b -> {
|
||||
String value = inputField.getValue();
|
||||
// 数据校验:解析并发送有效数值
|
||||
try {
|
||||
String sValue = (value == null || value.isBlank()) ? "0" : value.replaceFirst("^0+(?=.)", "");
|
||||
int limit = Integer.parseInt(sValue);
|
||||
PacketDistributor.sendToServer(new SetGlobalScalingLimitC2SPacket(limit, this.menu.getBlockEntityPos()));
|
||||
} catch (NumberFormatException ignored) {
|
||||
// 输入值无效,重置为0
|
||||
inputField.setValue("0");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private EditBox createInputField(int x, int y) {
|
||||
EditBox input = new EditBox(this.font, x, y, INPUT_WIDTH, INPUT_HEIGHT, Component.empty());
|
||||
input.setMaxLength(6);
|
||||
input.setBordered(true);
|
||||
input.setValue("0");
|
||||
input.setTextColor(0xFFFFFF);
|
||||
// 添加数据校验响应器
|
||||
input.setResponder(s -> {
|
||||
try {
|
||||
String sValue = (s == null || s.isBlank()) ? "0" : s.replaceFirst("^0+(?=.)", "");
|
||||
if (!sValue.equals(s)) {
|
||||
input.setValue(sValue);
|
||||
}
|
||||
Integer.parseInt(sValue); // 验证是否为有效整数
|
||||
} catch (Throwable ignored) {
|
||||
// 输入无效,重置为0
|
||||
input.setValue("0");
|
||||
}
|
||||
});
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(net.minecraft.client.gui.GuiGraphics gfx, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(gfx, mouseX, mouseY, partialTicks);
|
||||
protected void renderBg(GuiGraphics gfx, float partialTicks, int mouseX, int mouseY) {
|
||||
// 将256x256背景图压缩/拉伸到界面尺寸
|
||||
gfx.blit(BACKGROUND, this.leftPos, this.topPos, this.imageWidth, this.imageHeight, 0, 0, 256, 256, 256, 256);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(@NotNull GuiGraphics gfx, int mouseX, int mouseY, float partialTicks) {
|
||||
super.render(gfx, mouseX, mouseY, partialTicks);
|
||||
gfx.drawString(this.font, CUSTOM_TITLE, this.leftPos + 10, this.topPos + 8, 0xFFFFFF, false);
|
||||
|
||||
// 绘制标题
|
||||
gfx.drawString(this.font, CUSTOM_TITLE, this.leftPos + 8, this.topPos + 6, 0x404040, false);
|
||||
|
||||
int centerX = this.leftPos + this.imageWidth / 2;
|
||||
int row1Y = this.topPos + START_Y;
|
||||
int row2Y = row1Y + BTN_H + BTN_SPACING;
|
||||
int row3Y = row2Y + BTN_H + BTN_SPACING;
|
||||
int inputRowY = row3Y + LABEL_INPUT_SPACING;
|
||||
|
||||
// 计算居中位置并绘制标签
|
||||
int labelWidth = this.font.width(Component.translatable("gui.extendedae_plus.global.supplier_doubling_limit"));
|
||||
int totalWidth = labelWidth + 8 + INPUT_WIDTH + 6 + 18;
|
||||
int startX = centerX - totalWidth / 2;
|
||||
int labelX = startX;
|
||||
gfx.drawString(this.font, Component.translatable("gui.extendedae_plus.global.supplier_doubling_limit"), labelX, inputRowY + 4, 0x000000, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderLabels(net.minecraft.client.gui.GuiGraphics gfx, int mouseX, int mouseY) {
|
||||
// 不绘制默认的玩家物品栏标题(例如“物品栏”),避免与自定义面板重叠
|
||||
// 标题已在 render() 中手动绘制
|
||||
protected void renderLabels(GuiGraphics gfx, int mouseX, int mouseY) {
|
||||
// 不绘制默认的玩家物品栏标题
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg(net.minecraft.client.gui.GuiGraphics gfx, float partialTicks, int mouseX, int mouseY) {
|
||||
// 半透明全屏遮罩,避免底层 HUD(准星/物品栏文字)透出
|
||||
gfx.fill(0, 0, this.width, this.height, 0xC0000000);
|
||||
// AE2 风格按钮
|
||||
private static class AEStyleButton extends Button {
|
||||
private static final int TEXT_COLOR = 0xFFFFFF;
|
||||
|
||||
// 在按钮区域绘制一个半透明面板,提升可读性
|
||||
int pad = 6;
|
||||
int panelLeft = this.leftPos - pad;
|
||||
int panelTop = this.topPos - pad;
|
||||
int panelRight = this.leftPos + this.imageWidth + pad;
|
||||
int panelBottom = this.topPos + this.imageHeight + pad;
|
||||
gfx.fill(panelLeft, panelTop, panelRight, panelBottom, 0xA01E1E1E);
|
||||
// 边框
|
||||
gfx.fill(panelLeft, panelTop, panelRight, panelTop + 1, 0x80FFFFFF);
|
||||
gfx.fill(panelLeft, panelBottom - 1, panelRight, panelBottom, 0x80000000);
|
||||
gfx.fill(panelLeft, panelTop, panelLeft + 1, panelBottom, 0x80FFFFFF);
|
||||
gfx.fill(panelRight - 1, panelTop, panelRight, panelBottom, 0x80000000);
|
||||
public AEStyleButton(int x, int y, int width, int height, Component message, OnPress onPress) {
|
||||
super(x, y, width, height, message, onPress, DEFAULT_NARRATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partial) {
|
||||
if (this.visible) {
|
||||
int bgColor = isHovered() && this.active ? BTN_BG_HOVER : BTN_BG;
|
||||
|
||||
// 填充背景
|
||||
guiGraphics.fill(getX(), getY(), getX() + width, getY() + height, bgColor);
|
||||
|
||||
// 绘制1像素边框 - 上亮下暗的立体效果
|
||||
guiGraphics.fill(getX(), getY(), getX() + width, getY() + 1, BTN_BORDER_LIGHT);
|
||||
guiGraphics.fill(getX(), getY(), getX() + 1, getY() + height, BTN_BORDER_LIGHT);
|
||||
guiGraphics.fill(getX() + width - 1, getY(), getX() + width, getY() + height, BTN_BORDER_DARK);
|
||||
guiGraphics.fill(getX(), getY() + height - 1, getX() + width, getY() + height, BTN_BORDER_DARK);
|
||||
|
||||
// 使用原生 Button 的文本渲染方式
|
||||
renderString(guiGraphics, Minecraft.getInstance().font, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AE2 风格确认按钮(带 Tooltip)
|
||||
private static class AEConfirmButton extends Button {
|
||||
private final Component tooltip;
|
||||
|
||||
public AEConfirmButton(int x, int y, Component tooltip, OnPress onPress) {
|
||||
super(x, y, 18, 20, Component.empty(), onPress, DEFAULT_NARRATION);
|
||||
this.tooltip = tooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partial) {
|
||||
if (this.visible) {
|
||||
// 绘制按钮背景
|
||||
Icon background = isHovered() ? Icon.TOOLBAR_BUTTON_BACKGROUND_HOVER : Icon.TOOLBAR_BUTTON_BACKGROUND;
|
||||
background.getBlitter().dest(getX(), getY()).blit(guiGraphics);
|
||||
|
||||
// 绘制确认图标(居中)
|
||||
Icon.VALID.getBlitter().dest(getX() + 1, getY() + 2).blit(guiGraphics);
|
||||
|
||||
if (isHovered()) {
|
||||
guiGraphics.renderTooltip(Minecraft.getInstance().font, tooltip, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import com.extendedae_plus.network.ScaleEncodingPatternC2SPacket;
|
|||
import com.extendedae_plus.network.ScalePatternsC2SPacket;
|
||||
import com.extendedae_plus.network.SetPatternHighlightS2CPacket;
|
||||
import com.extendedae_plus.network.SetPerProviderScalingLimitC2SPacket;
|
||||
import com.extendedae_plus.network.SetGlobalScalingLimitC2SPacket;
|
||||
import com.extendedae_plus.network.SetProviderPageS2CPacket;
|
||||
import com.extendedae_plus.network.UploadEncodedPatternToProviderC2SPacket;
|
||||
import com.extendedae_plus.network.UploadInventoryPatternToProviderC2SPacket;
|
||||
|
|
@ -84,5 +85,6 @@ public class ModNetwork {
|
|||
|
||||
registrar.playToServer(EAPConfigButtonPacket.TYPE, EAPConfigButtonPacket.STREAM_CODEC, EAPConfigButtonPacket::handleOnServer);
|
||||
registrar.playToServer(SetPerProviderScalingLimitC2SPacket.TYPE, SetPerProviderScalingLimitC2SPacket.STREAM_CODEC, SetPerProviderScalingLimitC2SPacket::handle);
|
||||
registrar.playToServer(SetGlobalScalingLimitC2SPacket.TYPE, SetGlobalScalingLimitC2SPacket.STREAM_CODEC, SetGlobalScalingLimitC2SPacket::handle);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,144 @@
|
|||
package com.extendedae_plus.network;
|
||||
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IInWorldGridNodeHost;
|
||||
import appeng.blockentity.crafting.PatternProviderBlockEntity;
|
||||
import appeng.helpers.patternprovider.PatternProviderLogic;
|
||||
import appeng.helpers.patternprovider.PatternProviderLogicHost;
|
||||
import appeng.parts.crafting.PatternProviderPart;
|
||||
import com.extendedae_plus.ExtendedAEPlus;
|
||||
import com.extendedae_plus.api.smartDoubling.ISmartDoublingHolder;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* C2S: 设置网络中所有样板供应器的翻倍限制值
|
||||
*/
|
||||
public class SetGlobalScalingLimitC2SPacket implements CustomPacketPayload {
|
||||
|
||||
public static final Type<SetGlobalScalingLimitC2SPacket> TYPE = new Type<>(
|
||||
ResourceLocation.fromNamespaceAndPath(ExtendedAEPlus.MODID, "set_global_scaling_limit"));
|
||||
|
||||
public static final StreamCodec<FriendlyByteBuf, SetGlobalScalingLimitC2SPacket> STREAM_CODEC = StreamCodec.of(
|
||||
(buf, packet) -> {
|
||||
buf.writeInt(packet.limit);
|
||||
buf.writeBlockPos(packet.controllerPos);
|
||||
},
|
||||
buf -> new SetGlobalScalingLimitC2SPacket(buf.readInt(), buf.readBlockPos())
|
||||
);
|
||||
|
||||
private final int limit;
|
||||
private final BlockPos controllerPos;
|
||||
|
||||
public SetGlobalScalingLimitC2SPacket(int limit, BlockPos controllerPos) {
|
||||
this.limit = limit;
|
||||
this.controllerPos = controllerPos;
|
||||
}
|
||||
|
||||
public static void handle(final SetGlobalScalingLimitC2SPacket message, final IPayloadContext context) {
|
||||
context.enqueueWork(() -> {
|
||||
if (!(context.player() instanceof ServerPlayer player)) return;
|
||||
|
||||
var level = player.serverLevel();
|
||||
var blockEntity = level.getBlockEntity(message.controllerPos);
|
||||
|
||||
if (!(blockEntity instanceof IInWorldGridNodeHost gridNodeHost)) return;
|
||||
|
||||
var gridNode = gridNodeHost.getGridNode(null);
|
||||
if (gridNode == null) return;
|
||||
|
||||
IGrid grid = gridNode.getGrid();
|
||||
if (grid == null) return;
|
||||
|
||||
int affectedCount = applyToAllPatternProviders(grid, message.limit);
|
||||
|
||||
player.displayClientMessage(
|
||||
Component.translatable("extendedae_plus.message.global_scaling_limit_applied", affectedCount, message.limit),
|
||||
true);
|
||||
});
|
||||
}
|
||||
|
||||
private static int applyToAllPatternProviders(IGrid grid, int limit) {
|
||||
int affectedCount = 0;
|
||||
Set<PatternProviderLogic> uniqueLogics = new HashSet<>();
|
||||
|
||||
// 1. AE2 原生的方块实体形式
|
||||
collectLogicsFromMachineSet(grid.getMachines(PatternProviderBlockEntity.class), uniqueLogics);
|
||||
collectLogicsFromMachineSet(grid.getActiveMachines(PatternProviderBlockEntity.class), uniqueLogics);
|
||||
|
||||
// 2. AE2 原生的电缆零件形式
|
||||
collectLogicsFromMachineSet(grid.getMachines(PatternProviderPart.class), uniqueLogics);
|
||||
collectLogicsFromMachineSet(grid.getActiveMachines(PatternProviderPart.class), uniqueLogics);
|
||||
|
||||
// 3. 任何实现了 PatternProviderLogicHost 接口的机器
|
||||
collectLogicsFromMachineSet(grid.getMachines(PatternProviderLogicHost.class), uniqueLogics);
|
||||
collectLogicsFromMachineSet(grid.getActiveMachines(PatternProviderLogicHost.class), uniqueLogics);
|
||||
|
||||
// 4. 兼容 ExtendedAE
|
||||
collectByReflection(grid, uniqueLogics, "com.glodblock.github.extendedae.common.parts.PartExPatternProvider");
|
||||
collectByReflection(grid, uniqueLogics, "com.glodblock.github.extendedae.common.tileentities.TileExPatternProvider");
|
||||
|
||||
for (PatternProviderLogic logic : uniqueLogics) {
|
||||
if (applyToLogic(logic, limit)) {
|
||||
affectedCount++;
|
||||
}
|
||||
}
|
||||
return affectedCount;
|
||||
}
|
||||
|
||||
private static void collectLogicsFromMachineSet(Set<?> machineSet, Set<PatternProviderLogic> target) {
|
||||
if (machineSet == null) return;
|
||||
for (Object obj : machineSet) {
|
||||
addLogicIfPresent(target, obj);
|
||||
}
|
||||
}
|
||||
|
||||
private static void collectByReflection(IGrid grid, Set<PatternProviderLogic> target, String className) {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(className);
|
||||
collectLogicsFromMachineSet(grid.getMachines(clazz), target);
|
||||
collectLogicsFromMachineSet(grid.getActiveMachines(clazz), target);
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
|
||||
private static void addLogicIfPresent(Set<PatternProviderLogic> target, Object obj) {
|
||||
if (obj == null) return;
|
||||
try {
|
||||
if (obj instanceof PatternProviderLogicHost host && host.getLogic() != null) {
|
||||
target.add(host.getLogic());
|
||||
return;
|
||||
}
|
||||
var method = obj.getClass().getMethod("getLogic");
|
||||
Object result = method.invoke(obj);
|
||||
if (result instanceof PatternProviderLogic logic) {
|
||||
target.add(logic);
|
||||
}
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
|
||||
private static boolean applyToLogic(PatternProviderLogic logic, int limit) {
|
||||
if (logic instanceof ISmartDoublingHolder holder) {
|
||||
holder.eap$setProviderSmartDoublingLimit(limit);
|
||||
try {
|
||||
logic.saveChanges();
|
||||
} catch (Throwable ignored) {}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Type<? extends CustomPacketPayload> type() {
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,9 @@
|
|||
"gui.extendedae_plus.per_provider_limit.tooltip": "Per-item distribution limit: %s",
|
||||
"gui.extendedae_plus.global.all_on": "All On",
|
||||
"gui.extendedae_plus.global.all_off": "All Off",
|
||||
"gui.extendedae_plus.global.supplier_doubling_limit": "Supplier Doubling Limit:",
|
||||
"gui.extendedae_plus.global.confirm_tooltip": "Confirm doubling limit value",
|
||||
"extendedae_plus.message.global_scaling_limit_applied": "Set scaling limit to %2$s for %1$s providers",
|
||||
|
||||
"itemGroup.extendedae_plus.main": "ExtendedAE Plus",
|
||||
"item.extendedae_plus.wireless_transceiver": "Wireless Transceiver",
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@
|
|||
"gui.extendedae_plus.per_provider_limit.tooltip": "单样物品发配数量上限: %s",
|
||||
"gui.extendedae_plus.global.all_on": "全部开启",
|
||||
"gui.extendedae_plus.global.all_off": "全部关闭",
|
||||
"gui.extendedae_plus.global.supplier_doubling_limit": "供应器翻倍限制设置:",
|
||||
"gui.extendedae_plus.global.confirm_tooltip": "确认设置翻倍限制数值",
|
||||
"extendedae_plus.message.global_scaling_limit_applied": "已为 %s 个供应器设置翻倍限制为 %s",
|
||||
|
||||
"itemGroup.extendedae_plus.main": "扩展AE Plus",
|
||||
"item.extendedae_plus.wireless_transceiver": "无线收发器",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user