make level maintainer able to use lite crafting mode (#463)

Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: AnsonYeung <nanolify@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-08-24 21:42:24 +07:00
1 parent d89808dc0b
commit 1706b5a8da
8 files changed
+107 -8

No files matched your search

@@ -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;
}
@@ -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);
}
}
@@ -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;
}
@@ -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();
}
@@ -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;
@@ -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";