Skip to content

Commit

Permalink
import export cable refactoring execution inside of capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Lothrazar committed Dec 1, 2024
1 parent 0374faf commit 33bcd6a
Show file tree
Hide file tree
Showing 26 changed files with 390 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import com.lothrazar.storagenetwork.block.main.TileMain;
import com.lothrazar.storagenetwork.capability.handler.FilterItemStackHandler;
import com.lothrazar.storagenetwork.util.RequestBatch;
import net.minecraft.core.Direction;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
Expand Down Expand Up @@ -45,23 +46,6 @@ public interface IConnectableItemAutoIO {
*/
ItemStack insertStack(ItemStack stack, boolean simulate);

/**
* This is called whenever its your storages turn to import another item. Use the first used slot for this if you have a slot based inventory. If its not a simulation actually remove the stack from
* your storage!
* <p>
* Apply your own transfer rate here!
* <p>
* If your ioDirection is set to IN, this should never get called, unless another malicious mod is doing it.
*
* @param size
* The size of the stack that should be extracted
* @param simulate
* Whether or not this is just a simulation
* @return The stack that has been requested, if you have it
*/
@Deprecated
ItemStack extractNextStack(int size, boolean simulate);

default IItemHandler getItemHandler() {
return null;
}
Expand Down Expand Up @@ -110,7 +94,11 @@ default boolean isOperationMode() {
* The network main. Use this to e.g. query amount of items.
* @return Whether or not this IConnectableLink should be processed this tick.
*/
boolean runNow(DimPos connectablePos, TileMain main);
boolean canRunNow(DimPos connectablePos, TileMain main);

RequestBatch runExport(TileMain main);

void runImport(TileMain main);

/**
* If this block is used with an ioDirection of OUT and has its getSupportedTransferDirection set to OUT, then this list will be consolidated by the main and available items in the network matching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
*/
public interface IConnectableItemProcessing {



Direction facingInventory();

/**
Expand All @@ -24,17 +22,7 @@ public interface IConnectableItemProcessing {

void setPriority(int value);

/**
* Called every tick to see if an operation should be processed now, i.e. this can be used to add cooldown times or disable operations via redstone signal.
*
* @param connectablePos
* The position of your block, including the world
* @param main
* The network main. Use this to e.g. query amount of items.
* @return Whether or not this IConnectableLink should be processed this tick.
*/
boolean runNow(TileMain main);

void execute(TileMain main);
/**
* TODO:
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,6 @@ public boolean mouseScrolled(double x, double y, double mouseButton) {
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
getNetwork().mouseClicked(mouseX, mouseY, mouseButton);
// var size = getNetwork().getSize();
// if (size.isCrafting()) {
// //TODO: this is part of crafting grid, to clear it out. should be its own button class
// int rectX = 63;
// int rectY = 110;
//
// // TODO: revise above
// if (isHovering(rectX, rectY, 7, 7, mouseX, mouseY)) {
// System.out.println("clear cancelled do nothing,");
//
// // PacketRegistry.INSTANCE.sendToServer(new ClearRecipeMessage());
// // PacketRegistry.INSTANCE.sendToServer(new RequestMessage(0, ItemStack.EMPTY, false, false));
// return true;
// }
// }
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void onChunkUnloaded() {
try {
TileMain maybe = UtilTileEntity.getTileMainForConnectable(connectable);
if (maybe != null) {
maybe.nw.setShouldRefresh();
maybe.getNetwork().setShouldRefresh();
}
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.lothrazar.storagenetwork.block.cable.processing;

import com.lothrazar.storagenetwork.api.IConnectableItemProcessing;
import com.lothrazar.storagenetwork.block.TileCableWithFacing;
import com.lothrazar.storagenetwork.capability.CapabilityConnectableLink;
import com.lothrazar.storagenetwork.capability.CapabilityConnectableProcessing;
import com.lothrazar.storagenetwork.registry.SsnRegistry;
import com.lothrazar.storagenetwork.registry.StorageNetworkCapabilities;
import net.minecraft.core.BlockPos;
Expand All @@ -15,12 +16,12 @@

public class TileCableProcess extends TileCableWithFacing {

protected CapabilityConnectableLink itemStorage;
protected CapabilityConnectableProcessing itemStorage;
private ProcessRequestModel processModel = new ProcessRequestModel();

public TileCableProcess(BlockPos pos, BlockState state) {
super(SsnRegistry.Tiles.PROCESS_KABEL.get(), pos, state);
this.itemStorage = new CapabilityConnectableLink(this);
this.itemStorage = new CapabilityConnectableProcessing(this);
}

@Override
Expand All @@ -45,8 +46,8 @@ public void setDirection(Direction direction) {

@Override
public <T> LazyOptional<T> getCapability(Capability<T> capability, Direction facing) {
if (capability == StorageNetworkCapabilities.CONNECTABLE_ITEM_STORAGE_CAPABILITY) {
LazyOptional<CapabilityConnectableLink> cap = LazyOptional.of(() -> itemStorage);
if (capability == StorageNetworkCapabilities.PROCESSING_CAPABILITY) {
LazyOptional<IConnectableItemProcessing> cap = LazyOptional.of(() -> itemStorage);
return cap.cast();
}
return super.getCapability(capability, facing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void update() {
// StorageNetwork.log("exchange update started");
this.stacks.clear();
int i = 0;
for (ItemStack stack : tileMain.nw.getStacks()) {
for (ItemStack stack : tileMain.getNetwork().getStacks()) {
if (i >= this.stacks.size()) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, LivingEnt
if (!worldIn.isClientSide) {
BlockEntity tileAtPos = worldIn.getBlockEntity(pos);
if (tileAtPos instanceof TileMain main) {
main.nw.setShouldRefresh();
main.getNetwork().setShouldRefresh();
}
}
}
Expand All @@ -60,16 +60,16 @@ public InteractionResult use(BlockState state, Level worldIn, BlockPos pos,

private void displayConnections(Player playerIn, BlockEntity tileHere) {
TileMain tileMain = (TileMain) tileHere;
int total = tileMain.nw.getConnectableSize();
int total = tileMain.getNetwork().getConnectableSize();
if (total == 0) {
return;
}
playerIn.sendSystemMessage(
Component.translatable(ChatFormatting.LIGHT_PURPLE +
UtilTileEntity.lang("chat.main.emptyslots") + tileMain.nw.emptySlots()));
UtilTileEntity.lang("chat.main.emptyslots") + tileMain.getNetwork().emptySlots()));
playerIn.sendSystemMessage(Component.translatable(ChatFormatting.DARK_AQUA +
UtilTileEntity.lang("chat.main.connectables") + total));
List<Entry<String, Integer>> listDisplayStrings = tileMain.nw.getDisplayStrings();
List<Entry<String, Integer>> listDisplayStrings = tileMain.getNetwork().getDisplayStrings();
for (Entry<String, Integer> e : listDisplayStrings) {
playerIn.sendSystemMessage(Component.translatable(ChatFormatting.AQUA + " " + e.getValue() + ": " + e.getKey()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ public ItemStack request(ItemStackMatcher matcher, int size, boolean simulate) {
}

public void executeRequestBatch(RequestBatch batch) {
if (batch == null) {
return;
}
Batch<StackProvider> availableItems = new Batch<StackProvider>();
for (IConnectableLink storage : getSortedConnectableStorage()) {
storage.addToStackProviderBatch(availableItems);
Expand Down
Loading

0 comments on commit 33bcd6a

Please sign in to comment.