Universal Level Maintainer Gui

This commit is contained in:
Kogepan229 committed 2025-10-31 00:31:24 +09:00
1 parent 3107ecf1c0
commit e1afdf1c53
7 files changed
+117 -181

No files matched your search

@@ -5,12 +5,11 @@ import net.minecraft.tileentity.TileEntity;
import com.glodblock.github.api.ISide;
import appeng.api.implementations.tiles.ISegmentedInventory;
import appeng.api.networking.IGridHost;
import appeng.api.util.DimensionalCoord;
import appeng.helpers.ICustomNameObject;
public interface ILevelViewable extends IGridHost, ISide, ISegmentedInventory, ICustomNameObject {
public interface ILevelViewable extends IGridHost, ISide, ICustomNameObject {
DimensionalCoord getLocation();
@@ -2,12 +2,10 @@ package com.glodblock.github.client.gui;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
@@ -41,21 +39,15 @@ import com.glodblock.github.util.Util;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.DimensionalCoord;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.slots.VirtualMEPhantomSlot;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotFake;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketNEIDragClick;
import appeng.util.calculators.ArithHelper;
import appeng.util.calculators.Calculator;
import codechicken.nei.VisiblityData;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.TaggedInventoryArea;
import cofh.core.render.CoFHFontRenderer;
import cpw.mods.fml.common.Optional;
@Optional.Interface(modid = "NotEnoughItems", iface = "codechicken.nei.api.INEIGuiHandler")
public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
public class GuiLevelMaintainer extends AEBaseGui {
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/level_maintainer.png");
private final ContainerLevelMaintainer cont;
@@ -64,6 +56,7 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
private Widget focusedWidget;
private final CoFHFontRenderer render;
protected ItemStack icon = null;
private final VirtualMEPhantomSlot[] slots = new VirtualMEPhantomSlot[TileLevelMaintainer.REQ_COUNT];
protected GuiType originalGui;
protected Util.DimensionalCoordSide originalBlockPos;
@@ -120,6 +113,12 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
@Override
public void initGui() {
super.initGui();
for (int i = 0; i < slots.length; i++) {
slots[i] = new VirtualMEPhantomSlot(27, 20 + i * 19, this.cont.getTile().getAEStackInventory(), i);
this.registerVirtualSlots(slots[i]);
}
for (int i = 0; i < TileLevelMaintainer.REQ_COUNT; i++) {
component[i] = new Component(
new Widget(
@@ -277,59 +276,6 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
FluidCraft.proxy.netHandler.sendToServer(message);
}
@Override
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) {
return currentVisibility;
}
@Override
public Iterable<Integer> getItemSpawnSlots(GuiContainer gui, ItemStack item) {
return Collections.emptyList();
}
@Override
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui) {
return null;
}
@Override
protected void handleMouseClick(Slot slot, int slotIdx, int ctrlDown, int mouseButton) {
if (slot instanceof SlotFluidConvertingFake && this.cont.getPlayerInv().getItemStack() == null) {
slot.putStack(null);
this.component[slot.getSlotIndex()].reset();
}
super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton);
}
@Override
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) {
if (draggedStack == null) {
return false;
}
draggedStack.stackSize = 0;
Slot slotAtPosition = this.getSlotAtPosition(mouseX, mouseY);
if (slotAtPosition == null) {
return false;
}
for (int i = 0; i < this.cont.getRequestSlots().length; i++) {
SlotFluidConvertingFake slot = this.cont.getRequestSlots()[i];
if (slotAtPosition.equals(slot)) {
slot.putStack(draggedStack);
component[i].reset();
NetworkHandler.instance.sendToServer(new PacketNEIDragClick(draggedStack, slot.getSlotIndex()));
return true;
}
}
return false;
}
@Override
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
return false;
}
public void updateComponent(int index, long quantity, long batchSize, boolean isEnabled, LevelState state) {
if (index < 0 || index >= TileLevelMaintainer.REQ_COUNT) return;
component[index].setEnable(isEnabled);
@@ -7,19 +7,26 @@ import net.minecraft.item.ItemStack;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.tile.TileLevelMaintainer;
import com.glodblock.github.inventory.AeItemStackHandler;
import com.glodblock.github.inventory.slot.SlotFluidConvertingFake;
import com.glodblock.github.network.SPacketLevelMaintainerGuiUpdate;
import appeng.api.config.SecurityPermissions;
import appeng.api.storage.data.IAEStack;
import appeng.client.StorageName;
import appeng.container.AEBaseContainer;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketVirtualSlot;
import appeng.helpers.IVirtualSlotHolder;
import appeng.helpers.InventoryAction;
import appeng.tile.inventory.IAEStackInventory;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class ContainerLevelMaintainer extends AEBaseContainer {
public class ContainerLevelMaintainer extends AEBaseContainer implements IVirtualSlotHolder {
private final TileLevelMaintainer tile;
private final SlotFluidConvertingFake[] requestSlots = new SlotFluidConvertingFake[TileLevelMaintainer.REQ_COUNT];
private static final int UPDATE_INTERVAL = 20;
private boolean isFirstUpdate = true;
@@ -28,12 +35,7 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
public ContainerLevelMaintainer(InventoryPlayer ipl, TileLevelMaintainer tile) {
super(ipl, tile);
this.tile = tile;
AeItemStackHandler request = new AeItemStackHandler(tile.getRequestSlots());
for (int y = 0; y < TileLevelMaintainer.REQ_COUNT; y++) {
SlotFluidConvertingFake slot = new SlotFluidConvertingFake(request, y, 27, 20 + y * 19);
addSlotToContainer(slot);
requestSlots[y] = slot;
}
bindPlayerInventory(ipl, 0, 130);
}
@@ -41,10 +43,6 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
return tile;
}
public SlotFluidConvertingFake[] getRequestSlots() {
return this.requestSlots;
}
@Override
public void doAction(EntityPlayerMP player, InventoryAction action, int slotId, long id) {
if (getSlot(slotId) instanceof SlotFluidConvertingFake slot) {
@@ -70,12 +68,15 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
return null;
}
for (int i = 0; i < this.getRequestSlots().length; i++) {
SlotFluidConvertingFake slot = this.getRequestSlots()[i];
if (!slot.getHasStack()) {
ItemStack itemStack = this.inventorySlots.get(idx).getStack();
tile.updateStack(i, itemStack.copy());
break;
ItemStack clickedStack = this.inventorySlots.get(idx).getStack();
if (clickedStack != null) {
IAEStackInventory inventory = this.getTile().getAEStackInventory();
for (int i = 0; i < inventory.getSizeInventory(); i++) {
IAEStack<?> stack = inventory.getAEStackInSlot(i);
if (stack == null) {
tile.updateStack(i, AEItemStack.create(clickedStack));
break;
}
}
}
@@ -98,10 +99,36 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
}
public void updateGui() {
if (this.isFirstUpdate) {
Int2ObjectMap<IAEStack<?>> list = new Int2ObjectOpenHashMap<>();
for (int i = 0; i < this.tile.requests.length; i++) {
TileLevelMaintainer.RequestInfo info = this.tile.requests[i];
list.put(i, info != null ? info.getAEStack() : null);
}
NetworkHandler.instance.sendTo(
new PacketVirtualSlot(StorageName.NONE, list),
(EntityPlayerMP) this.getInventoryPlayer().player);
}
FluidCraft.proxy.netHandler.sendTo(
new SPacketLevelMaintainerGuiUpdate(this.tile.requests, !this.isFirstUpdate),
(EntityPlayerMP) this.getInventoryPlayer().player);
this.isFirstUpdate = false;
this.updateCount = 0;
}
@Override
public void receiveSlotStacks(StorageName invName, Int2ObjectMap<IAEStack<?>> slotStacks) {
for (var entry : slotStacks.int2ObjectEntrySet()) {
this.tile.updateStack(entry.getIntKey(), entry.getValue());
}
if (!this.tile.getWorldObj().isRemote) {
for (var player : this.crafters) {
NetworkHandler.instance
.sendTo(new PacketVirtualSlot(StorageName.NONE, slotStacks), (EntityPlayerMP) player);
FluidCraft.proxy.netHandler.sendTo(
new SPacketLevelMaintainerGuiUpdate(this.tile.requests, false),
(EntityPlayerMP) player);
}
}
}
}
@@ -1,10 +1,8 @@
package com.glodblock.github.common.tile;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.Future;
import java.util.stream.Stream;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@@ -23,8 +21,6 @@ import com.glodblock.github.api.registries.LevelState;
import com.glodblock.github.common.Config;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.crossmod.thaumcraft.ThaumicEnergisticsCrafting;
import com.glodblock.github.inventory.AeItemStackHandler;
import com.glodblock.github.inventory.AeStackInventory;
import com.glodblock.github.util.ModAndClassUtil;
import com.google.common.collect.ImmutableSet;
@@ -53,13 +49,16 @@ import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.client.StorageName;
import appeng.core.AELog;
import appeng.me.GridAccessException;
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.Platform;
import appeng.util.SettingsFrom;
import appeng.util.item.AEItemStack;
import io.netty.buffer.ByteBuf;
@@ -77,10 +76,9 @@ public class TileLevelMaintainer extends AENetworkTile
public static final String NBT_LINK = "link";
public final RequestInfo[] requests = new RequestInfo[REQ_COUNT];
private final LevelMaintainerInventory inventory = new LevelMaintainerInventory(requests, this);
private final LevelMaintainerInventory inventory = new LevelMaintainerInventory(requests);
private int firstRequest = 0;
private final BaseActionSource source;
private final IInventory inv = new AeItemStackHandler(inventory);
private boolean isPowered = false;
public TileLevelMaintainer() {
@@ -89,7 +87,7 @@ public class TileLevelMaintainer extends AENetworkTile
source = new MachineSource(this);
}
public AeStackInventory<IAEItemStack> getRequestSlots() {
public IAEStackInventory getAEStackInventory() {
return inventory;
}
@@ -182,7 +180,7 @@ public class TileLevelMaintainer extends AENetworkTile
// If there is none, find the next request we can begin calculating.
ICraftingJob jobToSubmit = null;
int jobToSubmitIdx = -1;
IAEItemStack itemToBegin = null;
IAEStack<?> itemToBegin = null;
int itemToBeginIdx = -1;
for (int j = 0; j < REQ_COUNT; ++j) {
@@ -198,17 +196,19 @@ public class TileLevelMaintainer extends AENetworkTile
continue;
}
IAEItemStack craftItem = requests[i].itemStack.copy();
IAEStack<?> aeItem = null;
IAEStack<?> craftItem = requests[i].stack.copy();
craftItem.setStackSize(batchSize);
IAEStack<?> aeItem = craftItem.getItem() instanceof ItemFluidDrop
? invFluid.findPrecise(ItemFluidDrop.getAeFluidStack(craftItem))
: invItems.findPrecise(craftItem);
if (ModAndClassUtil.ThE) {
if (ThaumicEnergisticsCrafting.isAspectStack(craftItem.getItemStack())) {
aeItem = ThaumicEnergisticsCrafting.convertAspectStack(craftItem);
if (craftItem instanceof IAEItemStack ais) {
if (ModAndClassUtil.ThE && ThaumicEnergisticsCrafting.isAspectStack(ais.getItemStack())) {
aeItem = ThaumicEnergisticsCrafting.convertAspectStack(ais);
} else {
aeItem = invItems.findPrecise(ais);
}
} else if (craftItem instanceof IAEFluidStack afs) {
aeItem = invFluid.findPrecise(afs);
}
long stackSize = aeItem == null ? 0 : aeItem.getStackSize();
@@ -335,22 +335,12 @@ public class TileLevelMaintainer extends AENetworkTile
return isPowered;
}
public IInventory getInventory() {
return inv;
}
public IInventory getInventoryByName(String name) {
if (Objects.equals(name, "config")) return new AeItemStackHandler(this.inventory);
return null;
}
@Override
public LevelItemInfo[] getLevelItemInfoList() {
return Arrays.stream(this.requests).map(request -> {
if (request == null) return null;
return new LevelItemInfo(
AEItemStack.create(request.itemStack.getItemStack()),
request.getAEStack(),
request.getQuantity(),
request.getBatchSize(),
request.getState());
@@ -384,11 +374,10 @@ public class TileLevelMaintainer extends AENetworkTile
this.saveChanges();
}
public void updateStack(int idx, @Nullable ItemStack stack) {
public void updateStack(int idx, @Nullable IAEStack<?> stack) {
if (stack == null) {
requests[idx] = null;
} else {
stack = this.removeRecursion(stack);
requests[idx] = new RequestInfo(stack, this);
}
this.saveChanges();
@@ -478,7 +467,7 @@ public class TileLevelMaintainer extends AENetworkTile
ItemStack craftStack = ItemStack.loadItemStackFromNBT(itemTag.getCompoundTag("Stack"));
craftStack = removeRecursion(craftStack);
if (craftStack == null) continue;
requests[i] = new RequestInfo(craftStack, this);
requests[i] = new RequestInfo(Platform.convertStack(AEItemStack.create(craftStack)), this);
if (itemTag.hasKey("Enable")) {
requests[i].enable = itemTag.getBoolean("Enable");
}
@@ -519,7 +508,7 @@ public class TileLevelMaintainer extends AENetworkTile
for (int i = 0; i < REQ_COUNT; i++) {
if (stacks[i] == null) continue;
this.requests[i] = new RequestInfo(stacks[i], this);
this.requests[i] = new RequestInfo(Platform.convertStack(AEItemStack.create(stacks[i])), this);
this.requests[i].batchSize = batches[i];
this.requests[i].quantity = quantyties[i];
}
@@ -628,7 +617,7 @@ public class TileLevelMaintainer extends AENetworkTile
public static class RequestInfo {
private final TileLevelMaintainer tile;
private @NotNull IAEItemStack itemStack;
private @NotNull IAEStack<?> stack;
private long quantity;
private long batchSize;
private boolean enable;
@@ -638,9 +627,9 @@ public class TileLevelMaintainer extends AENetworkTile
@Nullable
private ICraftingLink link;
public RequestInfo(@NotNull ItemStack stack, TileLevelMaintainer tile) {
public RequestInfo(@NotNull IAEStack<?> stack, TileLevelMaintainer tile) {
this.tile = tile;
itemStack = AEItemStack.create(stack);
this.stack = stack.copy();
quantity = 0;
batchSize = 0;
enable = false;
@@ -651,8 +640,8 @@ public class TileLevelMaintainer extends AENetworkTile
public RequestInfo(NBTTagCompound tag, TileLevelMaintainer tile) throws IllegalArgumentException {
this.tile = tile;
itemStack = AEItemStack.loadItemStackFromNBT(tag.getCompoundTag(NBT_STACK));
if (itemStack == null) {
stack = Platform.readStackNBT(tag.getCompoundTag(NBT_STACK), true);
if (stack == null) {
throw new IllegalArgumentException("ItemStack cannot be null!");
}
quantity = tag.getLong(NBT_QUANTITY);
@@ -670,7 +659,7 @@ public class TileLevelMaintainer extends AENetworkTile
}
public void loadFromNBT(NBTTagCompound tag) {
itemStack = AEItemStack.loadItemStackFromNBT(tag.getCompoundTag(NBT_STACK));
stack = Platform.readStackNBT(tag.getCompoundTag(NBT_STACK), true);
quantity = tag.getLong(NBT_QUANTITY);
batchSize = tag.getLong(NBT_BATCH);
enable = tag.getBoolean(NBT_ENABLE);
@@ -687,7 +676,7 @@ public class TileLevelMaintainer extends AENetworkTile
public NBTTagCompound writeToNBT(boolean includeLink) {
NBTTagCompound tag = new NBTTagCompound();
NBTTagCompound stackTag = new NBTTagCompound();
itemStack.writeToNBT(stackTag);
Platform.writeStackNBT(stack, stackTag, true);
tag.setTag(NBT_STACK, stackTag);
tag.setLong(NBT_QUANTITY, quantity);
tag.setLong(NBT_BATCH, batchSize);
@@ -701,8 +690,8 @@ public class TileLevelMaintainer extends AENetworkTile
return tag;
}
public IAEItemStack getAEItemStack() {
return this.itemStack;
public IAEStack<?> getAEStack() {
return this.stack;
}
public long getQuantity() {
@@ -722,43 +711,38 @@ public class TileLevelMaintainer extends AENetworkTile
}
}
private static class LevelMaintainerInventory implements AeStackInventory<IAEItemStack> {
private class LevelMaintainerInventory extends IAEStackInventory {
private final RequestInfo[] requests;
private final TileLevelMaintainer tile;
private LevelMaintainerInventory(RequestInfo[] requests, TileLevelMaintainer tile) {
this.requests = requests;
this.tile = tile;
public LevelMaintainerInventory(RequestInfo[] requests) {
super(null, requests.length, StorageName.NONE);
}
@Override
public @NotNull Iterator<IAEItemStack> iterator() {
return Arrays.stream(requests).map(info -> info != null ? info.itemStack : null).iterator();
}
@Override
public int getSlotCount() {
public int getSizeInventory() {
return requests.length;
}
@Override
public @Nullable IAEItemStack getStack(int slot) {
return requests[slot] != null ? requests[slot].itemStack : null;
}
@Override
public void setStack(int slot, @Nullable IAEItemStack stack) {
if (stack == null) {
this.tile.updateStack(slot, null);
} else {
this.tile.updateStack(slot, stack.getItemStack());
public IAEStack<?> getAEStackInSlot(int n) {
if (requests[n] != null) {
return requests[n].stack;
}
return null;
}
@Override
public Stream<IAEItemStack> stream() {
return Arrays.stream(requests).map(info -> info != null ? info.itemStack : null);
public void putAEStackInSlot(int slot, IAEStack<?> aes) {
if (aes == null) {
updateStack(slot, (IAEStack<?>) null);
} else {
updateStack(slot, aes);
}
super.putAEStackInSlot(slot, aes);
}
@Override
public void markDirty() {
}
}
}
@@ -3,7 +3,6 @@ package com.glodblock.github.crossmod.opencomputers;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@@ -13,6 +12,10 @@ import com.glodblock.github.common.tile.TileLevelMaintainer;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.NameConst;
import appeng.api.storage.data.IAEStack;
import appeng.tile.inventory.IAEStackInventory;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import cpw.mods.fml.common.registry.GameRegistry;
import li.cil.oc.api.driver.EnvironmentProvider;
import li.cil.oc.api.driver.NamedBlock;
@@ -44,7 +47,7 @@ public class DriverLevelMaintainer extends DriverSidedTileEntity {
super(tileEntity, NameConst.BLOCK_LEVEL_MAINTAINER);
}
private int getSlot(Arguments args, IInventory inv, int index, int def) {
private int getSlot(Arguments args, IAEStackInventory inv, int index, int def) {
if (index >= 0 && index < args.count()) {
int slot = args.checkInteger(index) - 1;
if (slot < 0 || slot >= inv.getSizeInventory()) {
@@ -93,10 +96,11 @@ public class DriverLevelMaintainer extends DriverSidedTileEntity {
@Callback(doc = "function([slot:number]):table -- Get the slot status.")
public Object[] getSlot(Context context, Arguments args) {
IInventory config = tileEntity.getInventory();
int slot = getSlot(args, config, 0, 0);
ItemStack stack = config.getStackInSlot(slot);
if (stack != null) {
IAEStackInventory inventory = tileEntity.getAEStackInventory();
int slot = getSlot(args, inventory, 0, 0);
IAEStack<?> aeStack = inventory.getAEStackInSlot(slot);
if (aeStack != null) {
ItemStack stack = Platform.stackConvert(aeStack).getItemStack();
Map<String, Object> result = new HashMap<>();
result.put("damage", stack.getItemDamage());
result.put("hasTag", stack.hasTagCompound());
@@ -122,7 +126,7 @@ public class DriverLevelMaintainer extends DriverSidedTileEntity {
if (dbStack == null) {
throw new IllegalArgumentException("Invalid slot");
}
tileEntity.updateStack(slot, dbStack);
tileEntity.updateStack(slot, AEItemStack.create(dbStack));
} else {
throw new IllegalArgumentException("Not a database");
}
@@ -37,7 +37,7 @@ public class LevelMaintainerWailaDataProvider extends BaseWailaDataProvider {
tileLevelMaintainer);
currentToolTip.add(
Tooltip.tileLevelMaintainerFormat(
request.getAEItemStack().getItemStack().getDisplayName(),
request.getAEStack().getDisplayName(),
request.getQuantity(),
request.getBatchSize(),
request.isEnable()));
@@ -1,24 +0,0 @@
package com.glodblock.github.nei;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import com.glodblock.github.client.gui.GuiLevelMaintainer;
import codechicken.nei.api.INEIGuiAdapter;
public class AE2FC_NEIGuiHandler extends INEIGuiAdapter {
@Override
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
return false;
}
@Override
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) {
if (gui instanceof GuiLevelMaintainer guiLevelMaintainer) {
return guiLevelMaintainer.handleDragNDrop(gui, mouseX, mouseY, draggedStack, button);
}
return super.handleDragNDrop(gui, mouseX, mouseY, draggedStack, button);
}
}