mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-30 05:05:19 -05:00
Implement forge item extract
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
|
||||
package dev.architectury.transfer.fabric;
|
||||
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.Iterables;
|
||||
import dev.architectury.transfer.ResourceView;
|
||||
import dev.architectury.transfer.TransferAction;
|
||||
import dev.architectury.transfer.TransferHandler;
|
||||
@@ -80,7 +80,7 @@ public class FabricStorageTransferHandler<F, S> implements TransferHandler<S> {
|
||||
return new FabricStorageResourceView((StorageView<F>) ((InventoryStorage) storage).getSlots().get(index));
|
||||
}
|
||||
try (Transaction transaction = Transaction.openNested(this.transaction)) {
|
||||
return new FabricStorageResourceView(Iterators.get(storage.iterator(transaction), index));
|
||||
return new FabricStorageResourceView(Iterables.get(storage.iterable(transaction), index));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import dev.architectury.transfer.access.BlockLookup;
|
||||
import dev.architectury.transfer.access.ItemLookup;
|
||||
import dev.architectury.transfer.fluid.FluidTransfer;
|
||||
import dev.architectury.transfer.forge.ForgeBlockLookupRegistration;
|
||||
import dev.architectury.transfer.forge.ForgeItemLookupRegistration;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -296,8 +295,8 @@ public class FluidTransferImpl {
|
||||
|
||||
@Override
|
||||
public FluidStack extract(FluidStack toExtract, TransferAction action) {
|
||||
// TODO: implement
|
||||
return null;
|
||||
// impossible to extract from a forge handler with an index
|
||||
return blank();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -163,8 +163,22 @@ public class ItemTransferImpl {
|
||||
|
||||
@Override
|
||||
public ItemStack extract(ItemStack toExtract, TransferAction action) {
|
||||
// TODO: implement
|
||||
return null;
|
||||
for (int i = 0; i < handler.getSlots(); i++) {
|
||||
ItemStack slot = handler.getStackInSlot(i);
|
||||
|
||||
if (ItemHandlerHelper.canItemStacksStack(toExtract, slot)) {
|
||||
int toExtractCount = toExtract.getCount();
|
||||
ItemStack left = handler.extractItem(i, toExtractCount, action == TransferAction.SIMULATE);
|
||||
|
||||
if (left.isEmpty()) {
|
||||
return toExtract;
|
||||
}
|
||||
|
||||
toExtract = left;
|
||||
}
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user