feat: add stub for RequestGridCache
This commit is contained in:
parent
4a72ceb724
commit
bb0c32d2c0
|
@ -8,4 +8,8 @@ public interface IControllerCache extends IGridCache {
|
|||
|
||||
boolean hasConflict();
|
||||
|
||||
boolean hasController();
|
||||
|
||||
IGridHost getController();
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package appeng.api.networking.request;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import appeng.api.networking.IGridCache;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
public interface IRequestGrid extends IGridCache {
|
||||
|
||||
/**
|
||||
* @return A Set of all items, which can be requested
|
||||
*/
|
||||
Set<IAEItemStack> getRequestableItems();
|
||||
|
||||
/**
|
||||
* @param stack The stack of items, which should be requested
|
||||
* @return The stack of items, which coul not be requested,
|
||||
* null if all were requested successfully
|
||||
*/
|
||||
IAEItemStack requestItems(IAEItemStack stack);
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package appeng.api.networking.request;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
public interface IRequestProvider {
|
||||
|
||||
Set<IAEItemStack> getRequestableItems();
|
||||
|
||||
IAEItemStack requestStack(IAEItemStack stack, Actionable actionable);
|
||||
|
||||
}
|
|
@ -29,9 +29,18 @@ import appeng.api.storage.ITerminalHost;
|
|||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.slot.SlotInaccessible;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.helpers.WirelessTerminalGuiObject;
|
||||
import appeng.parts.reporting.PartCraftingTerminal;
|
||||
import appeng.parts.reporting.PartPatternTerminal;
|
||||
import appeng.parts.reporting.PartTerminal;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.legacy.TileCraftTerminal;
|
||||
import appeng.tile.legacy.TileTerminal;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ContainerCraftAmount extends AEBaseContainer {
|
||||
|
@ -78,4 +87,33 @@ public class ContainerCraftAmount extends AEBaseContainer {
|
|||
public void setItemToCraft(@Nonnull final IAEItemStack itemToCreate) {
|
||||
this.itemToCreate = itemToCreate;
|
||||
}
|
||||
|
||||
public void closeGui() {
|
||||
GuiBridge originalGui = null;
|
||||
|
||||
final IActionHost ah = this.getActionHost();
|
||||
if (ah instanceof WirelessTerminalGuiObject) {
|
||||
originalGui = GuiBridge.GUI_WIRELESS_TERM;
|
||||
}
|
||||
|
||||
if (ah instanceof PartTerminal || ah instanceof TileTerminal) {
|
||||
originalGui = GuiBridge.GUI_ME;
|
||||
}
|
||||
|
||||
if (ah instanceof PartCraftingTerminal || ah instanceof TileCraftTerminal) {
|
||||
originalGui = GuiBridge.GUI_CRAFTING_TERMINAL;
|
||||
}
|
||||
|
||||
if (ah instanceof PartPatternTerminal) {
|
||||
originalGui = GuiBridge.GUI_PATTERN_TERMINAL;
|
||||
}
|
||||
|
||||
final TileEntity te = this.getOpenContext().getTile();
|
||||
Platform.openGUI(
|
||||
this.getInventoryPlayer().player,
|
||||
te,
|
||||
this.getOpenContext().getSide(),
|
||||
originalGui
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import appeng.api.networking.IWirelessCache;
|
|||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.pathing.IPathingGrid;
|
||||
import appeng.api.networking.request.IRequestGrid;
|
||||
import appeng.api.networking.security.ISecurityGrid;
|
||||
import appeng.api.networking.spatial.ISpatialCache;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
|
@ -534,6 +535,7 @@ public final class Registration {
|
|||
gcr.registerGridCache(IWirelessCache.class, WirelessGridCache.class);
|
||||
gcr.registerGridCache(IControllerCache.class, ControllerGridCache.class);
|
||||
gcr.registerGridCache(IAssemblerCache.class, AssemblerGridCache.class);
|
||||
gcr.registerGridCache(IRequestGrid.class, RequestGridCache.class);
|
||||
|
||||
registries.externalStorage().addExternalStorageInterface(new AEExternalHandler());
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ import appeng.api.networking.IGridHost;
|
|||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingJob;
|
||||
import appeng.api.networking.request.IRequestGrid;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import appeng.container.implementations.ContainerCraftAmount;
|
||||
import appeng.container.implementations.ContainerCraftConfirm;
|
||||
|
@ -82,7 +84,17 @@ public class PacketCraftRequest extends AppEngPacket {
|
|||
}
|
||||
|
||||
cca.getItemToCraft().setStackSize(this.amount);
|
||||
final ContainerOpenContext context = cca.getOpenContext();
|
||||
if (context == null) return;
|
||||
|
||||
IRequestGrid rg = g.getCache(IRequestGrid.class);
|
||||
IAEItemStack leftover = rg.requestItems(cca.getItemToCraft());
|
||||
|
||||
if (leftover == null) {
|
||||
final TileEntity te = context.getTile();
|
||||
cca.closeGui();
|
||||
return;
|
||||
}
|
||||
Future<ICraftingJob> futureJob = null;
|
||||
try {
|
||||
final ICraftingGrid cg = g.getCache(ICraftingGrid.class);
|
||||
|
@ -90,11 +102,10 @@ public class PacketCraftRequest extends AppEngPacket {
|
|||
cca.getWorld(),
|
||||
cca.getGrid(),
|
||||
cca.getActionSrc(),
|
||||
cca.getItemToCraft(),
|
||||
leftover,
|
||||
null
|
||||
);
|
||||
|
||||
final ContainerOpenContext context = cca.getOpenContext();
|
||||
if (context != null) {
|
||||
final TileEntity te = context.getTile();
|
||||
Platform.openGUI(
|
||||
|
|
|
@ -74,4 +74,17 @@ public class ControllerGridCache implements IControllerCache {
|
|||
return controllers.size() > 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasController() {
|
||||
return !controllers.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridHost getController() {
|
||||
for (TileLegacyController c : controllers) {
|
||||
return c;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,172 @@
|
|||
package appeng.me.cache;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.IControllerCache;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.IGridStorage;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPostCacheConstruction;
|
||||
import appeng.api.networking.request.IRequestGrid;
|
||||
import appeng.api.networking.request.IRequestProvider;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.storage.ICellProvider;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class RequestGridCache implements IRequestGrid, IMEInventoryHandler<IAEItemStack>, ICellProvider {
|
||||
|
||||
private IGrid grid;
|
||||
private IStorageGrid storageGrid;
|
||||
private IControllerCache controllerGrid;
|
||||
private Map<AEItemStack, Set<IRequestProvider>> requestable = new HashMap<>();
|
||||
private Set<IRequestProvider> requestProviders = new HashSet<>();
|
||||
|
||||
public RequestGridCache(IGrid grid) {
|
||||
this.grid = grid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateTick() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeNode(IGridNode gridNode, IGridHost machine) {
|
||||
if (machine instanceof IRequestProvider) {
|
||||
requestProviders.remove(machine);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNode(IGridNode gridNode, IGridHost machine) {
|
||||
if (machine instanceof IRequestProvider) {
|
||||
requestProviders.add((IRequestProvider)machine);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSplit(IGridStorage destinationStorage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin(IGridStorage sourceStorage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateGridStorage(IGridStorage destinationStorage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<IAEItemStack> getRequestableItems() {
|
||||
Set<IAEItemStack> list = new HashSet<>();
|
||||
for(AEItemStack stack : requestable.keySet()) {
|
||||
list.add(stack.copy());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack requestItems(IAEItemStack stack) {
|
||||
// TODO: Implement request mechanism
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src) {
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList<IAEItemStack> out) {
|
||||
Set<AEItemStack> items = requestable.keySet();
|
||||
for (IAEItemStack s : items) {
|
||||
IAEItemStack stack = s.copy();
|
||||
stack.reset();
|
||||
stack.setCountRequestable(1); // TODO: use a value, that makes sense
|
||||
out.add(stack);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel() {
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessRestriction getAccess() {
|
||||
return AccessRestriction.WRITE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrioritized(IAEItemStack input) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccept(IAEItemStack input) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlot() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validForPass(int i) {
|
||||
return i == 1;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void afterCacheConstruction(final MENetworkPostCacheConstruction cacheConstruction) {
|
||||
this.storageGrid = this.grid.getCache(IStorageGrid.class);
|
||||
this.controllerGrid = this.grid.getCache(IControllerCache.class);
|
||||
this.storageGrid.registerCellProvider(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray(StorageChannel channel) {
|
||||
final List<IMEInventoryHandler> list = new ArrayList<>(1);
|
||||
|
||||
if (channel == StorageChannel.ITEMS) {
|
||||
list.add(this);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public boolean useLegacyCrafting() {
|
||||
ICraftingGrid craftingGrid = grid.getCache(ICraftingGrid.class);
|
||||
return craftingGrid.getCpus().isEmpty() && controllerGrid.hasController();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue