diff --git a/src/main/java/gripe/_90/appliede/client/screen/EMCInterfaceScreen.java b/src/main/java/gripe/_90/appliede/client/screen/EMCInterfaceScreen.java index 23213ca..f8561d4 100644 --- a/src/main/java/gripe/_90/appliede/client/screen/EMCInterfaceScreen.java +++ b/src/main/java/gripe/_90/appliede/client/screen/EMCInterfaceScreen.java @@ -21,8 +21,6 @@ public class EMCInterfaceScreen extends AEBaseScreen public EMCInterfaceScreen(M menu, Inventory playerInventory, Component title, ScreenStyle style) { super(menu, playerInventory, title, style); - - widgets.addOpenPriorityButton(); var configSlots = menu.getSlots(SlotSemantics.CONFIG); for (int i = 0; i < configSlots.size(); i++) { diff --git a/src/main/java/gripe/_90/appliede/me/misc/EMCInterfaceLogic.java b/src/main/java/gripe/_90/appliede/me/misc/EMCInterfaceLogic.java index 49adfff..6715b04 100644 --- a/src/main/java/gripe/_90/appliede/me/misc/EMCInterfaceLogic.java +++ b/src/main/java/gripe/_90/appliede/me/misc/EMCInterfaceLogic.java @@ -1,14 +1,10 @@ package gripe._90.appliede.me.misc; import java.util.List; -import java.util.Optional; -import java.util.OptionalInt; import org.jetbrains.annotations.Nullable; import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ForgeCapabilities; @@ -38,20 +34,15 @@ import gripe._90.appliede.me.service.KnowledgeService; -@SuppressWarnings("UnstableApiUsage") public class EMCInterfaceLogic implements IActionHost, IGridTickable { protected final EMCInterfaceLogicHost host; protected final IManagedGridNode mainNode; - @Nullable - private MEStorage localInvHandler; - private final ConfigInventory config; private final ConfigInventory storage; - - protected final IActionSource requestSource = new RequestSource(); + private final MEStorage localInvHandler; private final GenericStack[] plannedWork; - private int priority = 0; + private final IActionSource source = IActionSource.ofMachine(this); private final LazyOptional storageHolder; private final LazyOptional localInvHolder; @@ -60,20 +51,23 @@ public EMCInterfaceLogic(IManagedGridNode node, EMCInterfaceLogicHost host) { this(node, host, 9); } + @SuppressWarnings("UnstableApiUsage") public EMCInterfaceLogic(IManagedGridNode node, EMCInterfaceLogicHost host, int slots) { this.host = host; - config = ConfigInventory.configStacks(AEItemKey.filter(), slots, this::onConfigRowChanged, false); - storage = ConfigInventory.storage(new StorageFilter(), slots, this::onStorageChanged); - plannedWork = new GenericStack[slots]; mainNode = node.setFlags(GridFlags.REQUIRE_CHANNEL) .addService(IGridTickable.class, this) .setIdlePowerUsage(10); + config = ConfigInventory.configStacks(AEItemKey.filter(), slots, this::onConfigRowChanged, false); + storage = ConfigInventory.storage(new StorageFilter(), slots, this::onStorageChanged); + localInvHandler = new DelegatingMEInventory(storage); + plannedWork = new GenericStack[slots]; + config.useRegisteredCapacities(); storage.useRegisteredCapacities(); storageHolder = LazyOptional.of(() -> storage).lazyMap(GenericStackItemStorage::new); - localInvHolder = LazyOptional.of(this::getInventory); + localInvHolder = LazyOptional.of(() -> localInvHandler); } public ConfigInventory getConfig() { @@ -84,19 +78,9 @@ public ConfigInventory getStorage() { return storage; } - public int getPriority() { - return priority; - } - - public void setPriority(int priority) { - this.priority = priority; - host.saveChanges(); - } - public void readFromNBT(CompoundTag tag) { config.readFromChildTag(tag, "config"); storage.readFromChildTag(tag, "storage"); - priority = tag.getInt("priority"); updatePlan(); notifyNeighbours(); @@ -105,15 +89,6 @@ public void readFromNBT(CompoundTag tag) { public void writeToNBT(CompoundTag tag) { config.writeToChildTag(tag, "config"); storage.writeToChildTag(tag, "storage"); - tag.putInt("priority", priority); - } - - private MEStorage getInventory() { - if (localInvHandler == null) { - localInvHandler = new Inventory(); - } - - return localInvHandler; } @Nullable @@ -230,7 +205,7 @@ private boolean tryUsePlan(int slot, AEKey what, int amount) { var depositedItems = grid.getService(KnowledgeService.class) .getStorage() - .insertItem(item, amount, Actionable.MODULATE, requestSource, false); + .insertItem(item, amount, Actionable.MODULATE, source, false); if (depositedItems > 0) { storage.extract(slot, what, depositedItems, Actionable.MODULATE); @@ -253,7 +228,7 @@ private boolean acquireFromNetwork(IGrid grid, int slot, AEKey what, long amount var acquiredItems = grid.getService(KnowledgeService.class) .getStorage() - .extractItem(item, amount, Actionable.MODULATE, requestSource, true); + .extractItem(item, amount, Actionable.MODULATE, source, true); if (acquiredItems > 0) { var inserted = storage.insert(slot, what, acquiredItems, Actionable.MODULATE); @@ -323,71 +298,6 @@ public void invalidateCaps() { localInvHolder.invalidate(); } - private class Inventory extends DelegatingMEInventory { - private Inventory() { - super(storage); - } - - @Override - public long insert(AEKey what, long amount, Actionable mode, IActionSource source) { - return getRequestInterfacePriority(source).isPresent() && isSameGrid(source) - ? 0 - : super.insert(what, amount, mode, source); - } - - @Override - public long extract(AEKey what, long amount, Actionable mode, IActionSource source) { - var requestPriority = getRequestInterfacePriority(source); - return requestPriority.isPresent() && requestPriority.getAsInt() <= getPriority() && isSameGrid(source) - ? 0 - : super.extract(what, amount, mode, source); - } - - private OptionalInt getRequestInterfacePriority(IActionSource source) { - return source.context(RequestContext.class) - .map(ctx -> OptionalInt.of(ctx.getPriority())) - .orElseGet(OptionalInt::empty); - } - - private boolean isSameGrid(IActionSource source) { - return source.machine() - .map(IActionHost::getActionableNode) - .map(IGridNode::getGrid) - .orElse(null) - == mainNode.getGrid(); - } - - @Override - public Component getDescription() { - return host.getMainMenuIcon().getHoverName(); - } - } - - private class RequestSource implements IActionSource { - private final RequestContext context = new RequestContext(); - - @Override - public Optional player() { - return Optional.empty(); - } - - @Override - public Optional machine() { - return Optional.of(EMCInterfaceLogic.this); - } - - @Override - public Optional context(Class key) { - return key == RequestContext.class ? Optional.of(key.cast(context)) : Optional.empty(); - } - } - - private class RequestContext { - public int getPriority() { - return priority; - } - } - private class StorageFilter implements AEKeyFilter { @Override public boolean matches(AEKey what) { diff --git a/src/main/java/gripe/_90/appliede/me/misc/EMCInterfaceLogicHost.java b/src/main/java/gripe/_90/appliede/me/misc/EMCInterfaceLogicHost.java index dafeee7..6dd7e5c 100644 --- a/src/main/java/gripe/_90/appliede/me/misc/EMCInterfaceLogicHost.java +++ b/src/main/java/gripe/_90/appliede/me/misc/EMCInterfaceLogicHost.java @@ -5,8 +5,8 @@ import appeng.api.networking.IGridNode; import appeng.api.networking.IGridNodeListener; +import appeng.api.storage.ISubMenuHost; import appeng.helpers.IConfigInvHost; -import appeng.helpers.IPriorityHost; import appeng.helpers.externalstorage.GenericStackInv; import appeng.menu.ISubMenu; import appeng.menu.MenuOpener; @@ -14,7 +14,7 @@ import gripe._90.appliede.menu.EMCInterfaceMenu; -public interface EMCInterfaceLogicHost extends IPriorityHost, IConfigInvHost { +public interface EMCInterfaceLogicHost extends IConfigInvHost, ISubMenuHost { IGridNodeListener NODE_LISTENER = new IGridNodeListener<>() { @Override public void onSaveChanges(EMCInterfaceLogicHost host, IGridNode node) { @@ -40,16 +40,6 @@ public void onGridChanged(EMCInterfaceLogicHost host, IGridNode node) { EMCInterfaceLogic getInterfaceLogic(); - @Override - default int getPriority() { - return getInterfaceLogic().getPriority(); - } - - @Override - default void setPriority(int priority) { - getInterfaceLogic().setPriority(priority); - } - @Override default GenericStackInv getConfig() { return getInterfaceLogic().getConfig(); diff --git a/src/main/resources/assets/ae2/screens/appliede/emc_interface.json b/src/main/resources/assets/ae2/screens/appliede/emc_interface.json index f42d1cc..52f21f7 100644 --- a/src/main/resources/assets/ae2/screens/appliede/emc_interface.json +++ b/src/main/resources/assets/ae2/screens/appliede/emc_interface.json @@ -46,12 +46,6 @@ } }, "widgets": { - "openPriority": { - "left": 154, - "top": 0, - "width": 16, - "height": 16 - }, "amtButton1": { "left": 8, "top": 35,