From 1706b5a8daf276a6dd4316a02ca76baf72cae746 Mon Sep 17 00:00:00 2001 From: Nana-Sakura <60061683+Nana-Sakura@users.noreply.github.com> Date: Mon, 24 Aug 2026 22:42:24 +0800 Subject: [PATCH] make level maintainer able to use lite crafting mode (#463) Co-authored-by: Martin Robertz Co-authored-by: AnsonYeung --- dependencies.gradle | 2 +- .../github/client/gui/GuiLevelMaintainer.java | 24 +++++++ .../container/ContainerLevelMaintainer.java | 4 +- .../common/tile/TileLevelMaintainer.java | 65 +++++++++++++++++-- .../network/CPacketLevelMaintainer.java | 10 +++ .../SPacketLevelMaintainerGuiUpdate.java | 8 ++- .../com/glodblock/github/util/NameConst.java | 1 + .../resources/assets/ae2fc/lang/en_US.lang | 1 + 8 files changed, 107 insertions(+), 8 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 621c882b..9cd04b62 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -35,7 +35,7 @@ */ dependencies { api('com.github.GTNewHorizons:NotEnoughItems:2.8.121-GTNH:dev') - api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-1030-GTNH:dev') + api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-1040-GTNH:dev') api('com.github.GTNewHorizons:waila:1.19.31:dev') api("com.github.GTNewHorizons:GTNHLib:0.11.37:dev") diff --git a/src/main/java/com/glodblock/github/client/gui/GuiLevelMaintainer.java b/src/main/java/com/glodblock/github/client/gui/GuiLevelMaintainer.java index 97de772f..4a44a9eb 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiLevelMaintainer.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiLevelMaintainer.java @@ -29,6 +29,8 @@ import appeng.api.storage.data.IAEStackType; import appeng.client.gui.GuiSub; import appeng.client.gui.slots.VirtualMEPhantomSlot; import appeng.client.gui.widgets.GuiTabButton; +import appeng.client.gui.widgets.GuiToggleButton; +import appeng.core.localization.GuiText; import appeng.util.calculators.ArithHelper; import appeng.util.calculators.Calculator; @@ -40,6 +42,7 @@ public class GuiLevelMaintainer extends GuiSub { private final MouseRegionManager mouseRegions = new MouseRegionManager(this); private Widget focusedWidget; private final FontRenderer render; + private GuiToggleButton liteMode; public GuiLevelMaintainer(InventoryPlayer ipl, TileLevelMaintainer tile) { super(new ContainerLevelMaintainer(ipl, tile)); @@ -88,6 +91,15 @@ public class GuiLevelMaintainer extends GuiSub { this.buttonList, this.cont); } + this.buttonList.add( + this.liteMode = new GuiToggleButton( + guiLeft - 18, + guiTop + 2, + 178, + 194, + GuiText.CraftingModeLite.getLocal(), + NameConst.TT_LEVEL_MAINTAINER_LITE_CRAFT_DESC)); + this.liteMode.setState(false); } @Override @@ -209,6 +221,14 @@ public class GuiLevelMaintainer extends GuiSub { return; } } + if (btn == this.liteMode) { + if (isShiftKeyDown()) { + FluidCraft.proxy.netHandler.sendToServer(new CPacketLevelMaintainer(Action.ClearLiteMode)); + } else { + FluidCraft.proxy.netHandler.sendToServer(new CPacketLevelMaintainer(Action.ToggleLiteMode)); + } + return; + } super.actionPerformed(btn); } @@ -227,6 +247,10 @@ public class GuiLevelMaintainer extends GuiSub { component[index].setState(state); } + public void updateComponent(boolean isLiteMode) { + this.liteMode.setState(isLiteMode); + } + private static boolean acceptType(VirtualMEPhantomSlot slot, IAEStackType type, int mouseButton) { return true; } diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelMaintainer.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelMaintainer.java index dbcf5b3e..0feb2bc6 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelMaintainer.java +++ b/src/main/java/com/glodblock/github/client/gui/container/ContainerLevelMaintainer.java @@ -110,7 +110,7 @@ public class ContainerLevelMaintainer extends ContainerSubGui implements IVirtua (EntityPlayerMP) this.getInventoryPlayer().player); } FluidCraft.proxy.netHandler.sendTo( - new SPacketLevelMaintainerGuiUpdate(this.tile.requests, !this.isFirstUpdate), + new SPacketLevelMaintainerGuiUpdate(this.tile.requests, !this.isFirstUpdate, this.tile.isLiteMode()), (EntityPlayerMP) this.getInventoryPlayer().player); this.isFirstUpdate = false; this.updateCount = 0; @@ -126,7 +126,7 @@ public class ContainerLevelMaintainer extends ContainerSubGui implements IVirtua NetworkHandler.instance .sendTo(new PacketVirtualSlot(StorageName.NONE, slotStacks), (EntityPlayerMP) player); FluidCraft.proxy.netHandler.sendTo( - new SPacketLevelMaintainerGuiUpdate(this.tile.requests, false), + new SPacketLevelMaintainerGuiUpdate(this.tile.requests, false, this.tile.isLiteMode()), (EntityPlayerMP) player); } } diff --git a/src/main/java/com/glodblock/github/common/tile/TileLevelMaintainer.java b/src/main/java/com/glodblock/github/common/tile/TileLevelMaintainer.java index bf91e8c2..5d1a727c 100644 --- a/src/main/java/com/glodblock/github/common/tile/TileLevelMaintainer.java +++ b/src/main/java/com/glodblock/github/common/tile/TileLevelMaintainer.java @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableSet; import appeng.api.AEApi; import appeng.api.config.Actionable; +import appeng.api.config.CraftingMode; import appeng.api.config.PowerMultiplier; import appeng.api.features.ILevelViewable; import appeng.api.features.LevelItemInfo; @@ -50,12 +51,14 @@ import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEStack; import appeng.core.AELog; import appeng.me.GridAccessException; +import appeng.me.cache.CraftingGridCache; import appeng.tile.TileEvent; import appeng.tile.events.TileEventType; import appeng.tile.grid.AENetworkTile; import appeng.tile.inventory.IAEAppEngInventory; import appeng.tile.inventory.IAEStackInventory; import appeng.tile.inventory.InvOperation; +import appeng.util.IterationCounter; import appeng.util.Platform; import appeng.util.SettingsFrom; import appeng.util.item.AEItemStack; @@ -72,12 +75,15 @@ public class TileLevelMaintainer extends AENetworkTile public static final String NBT_ENABLE = "enable"; public static final String NBT_STATE = "state"; public static final String NBT_LINK = "link"; + public static final String NBT_LITE_MODE = "lite_mode"; public final RequestInfo[] requests = new RequestInfo[REQ_COUNT]; private final LevelMaintainerInventory inventory = new LevelMaintainerInventory(requests); private int firstRequest = 0; private final BaseActionSource source; private boolean isPowered = false; + private boolean isLiteModeOverridden = false; + private boolean isLiteMode = false; public TileLevelMaintainer() { getProxy().setIdlePowerUsage(1D); @@ -164,6 +170,7 @@ public class TileLevelMaintainer extends AENetworkTile } try { final ICraftingGrid craftingGrid = getProxy().getCrafting(); + final CraftingGridCache craftingGridCache = (CraftingGridCache) craftingGrid; final IGrid grid = getProxy().getGrid(); // Check there are available crafting CPUs before doing any work. @@ -202,7 +209,7 @@ public class TileLevelMaintainer extends AENetworkTile IMEMonitor monitor = getProxy().getStorage().getMEMonitor(craftItem.getStackType()); if (monitor == null) continue; - IAEStack stackInStorage = monitor.getStorageList().findPrecise(craftItem); + IAEStack stackInStorage = monitor.getAvailableItem(craftItem, IterationCounter.fetchNewId()); long stackSize = stackInStorage == null ? 0 : stackInStorage.getStackSize(); @@ -273,9 +280,14 @@ public class TileLevelMaintainer extends AENetworkTile } } else if (itemToBegin != null) { // No jobs to submit, start calculating some item. - - requests[itemToBeginIdx].job = craftingGrid - .beginCraftingJob(this.worldObj, grid, source, itemToBegin, null); + requests[itemToBeginIdx].job = craftingGridCache.beginCraftingJob( + this.worldObj, + grid, + source, + itemToBegin, + CraftingMode.STANDARD, + isLiteMode(), + null); this.updateState(itemToBeginIdx, LevelState.Craft); // Try the next item next time. @@ -369,6 +381,35 @@ public class TileLevelMaintainer extends AENetworkTile this.saveChanges(); } + private boolean getLiteModeDefault() { + try { + final ICraftingGrid craftingGrid = getProxy().getCrafting(); + if (craftingGrid instanceof CraftingGridCache cache) { + return cache.getLiteCraftingDefault(); + } + } catch (GridAccessException ignored) {} + return false; + } + + public boolean isLiteMode() { + return this.isLiteModeOverridden ? this.isLiteMode : getLiteModeDefault(); + } + + public void setLiteMode(boolean liteMode) { + this.isLiteModeOverridden = true; + this.isLiteMode = liteMode; + this.saveChanges(); + } + + public void toggleLiteMode() { + this.setLiteMode(!this.isLiteMode()); + } + + public void clearLiteMode() { + this.isLiteModeOverridden = false; + this.saveChanges(); + } + private void updateLink(int idx, @Nullable ICraftingLink link) { if (requests[idx] == null) return; requests[idx].link = link; @@ -416,6 +457,9 @@ public class TileLevelMaintainer extends AENetworkTile } } data.setTag(NBT_REQUESTS, tagList); + if (this.isLiteModeOverridden) { + data.setBoolean(NBT_LITE_MODE, this.isLiteMode); + } } @TileEvent(TileEventType.WORLD_NBT_READ) @@ -499,6 +543,10 @@ public class TileLevelMaintainer extends AENetworkTile this.requests[i].quantity = quantyties[i]; } } + if (data.hasKey(NBT_LITE_MODE)) { + this.isLiteModeOverridden = true; + this.isLiteMode = data.getBoolean(NBT_LITE_MODE); + } } // Remove old format NBT data from ItemStack @@ -541,6 +589,12 @@ public class TileLevelMaintainer extends AENetworkTile } } } + if (compound.hasKey(NBT_LITE_MODE)) { + this.isLiteModeOverridden = true; + this.isLiteMode = compound.getBoolean(NBT_LITE_MODE); + } else { + this.isLiteModeOverridden = false; + } this.saveChanges(); } @@ -557,6 +611,9 @@ public class TileLevelMaintainer extends AENetworkTile } } compound.setTag(NBT_REQUESTS, tagList); + if (isLiteModeOverridden) { + compound.setBoolean(NBT_LITE_MODE, isLiteMode); + } return compound; } diff --git a/src/main/java/com/glodblock/github/network/CPacketLevelMaintainer.java b/src/main/java/com/glodblock/github/network/CPacketLevelMaintainer.java index 7c5732c5..6674c58e 100644 --- a/src/main/java/com/glodblock/github/network/CPacketLevelMaintainer.java +++ b/src/main/java/com/glodblock/github/network/CPacketLevelMaintainer.java @@ -16,6 +16,8 @@ public class CPacketLevelMaintainer implements IMessage { Batch, Enable, Disable, + ToggleLiteMode, + ClearLiteMode, } private Action action; @@ -25,6 +27,12 @@ public class CPacketLevelMaintainer implements IMessage { @SuppressWarnings("unused") public CPacketLevelMaintainer() {} + public CPacketLevelMaintainer(Action action) { + this.action = action; + this.slotIndex = -1; + this.size = 0; + } + public CPacketLevelMaintainer(Action action, int slotIndex) { this.action = action; this.slotIndex = slotIndex; @@ -62,6 +70,8 @@ public class CPacketLevelMaintainer implements IMessage { case Batch -> clm.getTile().updateBatchSize(message.slotIndex, message.size); case Enable -> clm.getTile().updateStatus(message.slotIndex, false); case Disable -> clm.getTile().updateStatus(message.slotIndex, true); + case ToggleLiteMode -> clm.getTile().toggleLiteMode(); + case ClearLiteMode -> clm.getTile().clearLiteMode(); } clm.updateGui(); } diff --git a/src/main/java/com/glodblock/github/network/SPacketLevelMaintainerGuiUpdate.java b/src/main/java/com/glodblock/github/network/SPacketLevelMaintainerGuiUpdate.java index 2d564e5d..da814cde 100644 --- a/src/main/java/com/glodblock/github/network/SPacketLevelMaintainerGuiUpdate.java +++ b/src/main/java/com/glodblock/github/network/SPacketLevelMaintainerGuiUpdate.java @@ -18,13 +18,15 @@ public class SPacketLevelMaintainerGuiUpdate implements IMessage { private Info[] infoList; private boolean onlyState; + private boolean isLiteMode; @SuppressWarnings("unused") public SPacketLevelMaintainerGuiUpdate() {} - public SPacketLevelMaintainerGuiUpdate(RequestInfo[] requests, boolean onlyState) { + public SPacketLevelMaintainerGuiUpdate(RequestInfo[] requests, boolean onlyState, boolean isLiteMode) { this.infoList = new Info[REQ_COUNT]; this.onlyState = onlyState; + this.isLiteMode = isLiteMode; for (int i = 0; i < REQ_COUNT; i++) { if (requests[i] == null) { @@ -43,6 +45,7 @@ public class SPacketLevelMaintainerGuiUpdate implements IMessage { public void fromBytes(ByteBuf buf) { this.infoList = new Info[REQ_COUNT]; this.onlyState = buf.readBoolean(); + this.isLiteMode = buf.readBoolean(); for (int i = 0; i < REQ_COUNT; i++) { if (buf.readBoolean()) { @@ -64,6 +67,7 @@ public class SPacketLevelMaintainerGuiUpdate implements IMessage { @Override public void toBytes(ByteBuf buf) { buf.writeBoolean(this.onlyState); + buf.writeBoolean(this.isLiteMode); for (Info info : this.infoList) { buf.writeBoolean(info != null); if (info == null) continue; @@ -114,6 +118,8 @@ public class SPacketLevelMaintainerGuiUpdate implements IMessage { gui.updateComponent(i, info.quantity, info.batchSize, info.enable, info.state); } } + + gui.updateComponent(message.isLiteMode); } return null; diff --git a/src/main/java/com/glodblock/github/util/NameConst.java b/src/main/java/com/glodblock/github/util/NameConst.java index 8e9717c3..de6a0a31 100644 --- a/src/main/java/com/glodblock/github/util/NameConst.java +++ b/src/main/java/com/glodblock/github/util/NameConst.java @@ -87,6 +87,7 @@ public class NameConst { public static final String TT_LEVEL_MAINTAINER_NOT_FOUND_DESC = TT_LEVEL_MAINTAINER + "not_found_desc"; public static final String TT_LEVEL_MAINTAINER_CANT_CRAFT = TT_LEVEL_MAINTAINER + "cant_craft"; public static final String TT_LEVEL_MAINTAINER_CANT_CRAFT_DESC = TT_LEVEL_MAINTAINER + "cant_craft_desc"; + public static final String TT_LEVEL_MAINTAINER_LITE_CRAFT_DESC = TT_LEVEL_MAINTAINER + "lite_craft_desc"; public static final String TT_CELL_PORTABLE = TT_KEY + "cell_portable"; public static final String TT_WIRELESS = TT_KEY + "wireless."; public static final String TT_WIRELESS_INSTALLED = TT_WIRELESS + "installed"; diff --git a/src/main/resources/assets/ae2fc/lang/en_US.lang b/src/main/resources/assets/ae2fc/lang/en_US.lang index 17f79fbd..2bc90621 100644 --- a/src/main/resources/assets/ae2fc/lang/en_US.lang +++ b/src/main/resources/assets/ae2fc/lang/en_US.lang @@ -99,6 +99,7 @@ ae2fc.tooltip.level_maintainer.not_found=§4Not Found§r ae2fc.tooltip.level_maintainer.not_found_desc=The Requester is trying to schedule a crafting job but can't find a crafting pattern. ae2fc.tooltip.level_maintainer.cant_craft=§4Can't Craft§r ae2fc.tooltip.level_maintainer.cant_craft_desc=The Requester is trying to schedule a crafting job but the crafting manager cannot process the job. (not enough ingredients, CPU doesn't have enough memory, recursion). +ae2fc.tooltip.level_maintainer.lite_craft_desc=Toggle lite crafting mode. Shift-click to clear override and restore network defaults. ae2fc.tooltip.level_maintainer.batch_size=§6Crafting Batch Size§r ae2fc.tooltip.level_maintainer.batch_size.hint=When craft requests are emitted, the Requester will use the batch size for the request. Using larger batches will increase the speed of stocking up items but will require more crafting storage. ae2fc.tooltip.level_maintainer.request_size=§6Amount to Maintain§r