Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* MIT License
*
* Copyright (c) 2020 Azercoco & Technici4n
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package aztech.modern_industrialization.inventory;

import net.neoforged.neoforge.items.IItemHandler;

public interface FilledItemStorage {
static boolean isFull(IItemHandler handler) {
return handler instanceof FilledItemStorage filled && filled.isFull();
}

boolean isFull();
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void autoExtractItems(Level world, BlockPos pos, Direction direction) {
}

var target = outputCache.getCapability();
if (target != null) {
if (target != null && !FilledItemStorage.isFull(target)) {
TransferHelper.moveAll(itemStorage.itemHandler, target, true);
}
}
Expand All @@ -112,7 +112,7 @@ public void autoExtractFluids(Level world, BlockPos pos, Direction direction) {
public void autoInsertItems(Level world, BlockPos pos, Direction direction) {
IItemHandler target = world.getCapability(Capabilities.ItemHandler.BLOCK, pos.relative(direction), direction.getOpposite());

if (target != null) {
if (target != null && !FilledItemStorage.isFull(itemStorage.itemHandler)) {
TransferHelper.moveAll(target, itemStorage.itemHandler, false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public MIItemStorage(List<ConfigurableItemStack> stacks) {
super(stacks, false);
}

public class ItemHandler implements IItemHandler, WhitelistedItemStorage {
public class ItemHandler implements IItemHandler, WhitelistedItemStorage, FilledItemStorage {
@Override
public int getSlots() {
return stacks.size();
Expand Down Expand Up @@ -137,5 +137,15 @@ public void getWhitelistedItems(Set<Item> whitelist) {
}
}
}

@Override
public boolean isFull() {
for (var stack : stacks) {
if (!stack.isLockedTo(Items.AIR) && stack.getAmount() < stack.getCapacity()) {
return false;
}
}
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package aztech.modern_industrialization.pipes.item;

import aztech.modern_industrialization.inventory.FilledItemStorage;
import aztech.modern_industrialization.inventory.WhitelistedItemStorage;
import aztech.modern_industrialization.pipes.api.PipeNetwork;
import aztech.modern_industrialization.pipes.api.PipeNetworkData;
Expand Down Expand Up @@ -112,6 +113,10 @@ private void doNetworkTransfer(ServerLevel world) {

private static int moveAll(ServerLevel world, ExtractionSource target, List<? extends ItemSink> sinks, Predicate<ItemStack> filter,
int maxToMove) {
if (sinks.isEmpty()) {
return 0;
}

IItemHandler source = target.storage();
int moved = 0;

Expand Down Expand Up @@ -147,7 +152,7 @@ private List<Aggregate> getAggregatedInsertTargets(ServerLevel world) {
entry.getPos().relative(connection.direction), connection.direction.getOpposite());
}
var target = connection.cache.getCapability();
if (target != null && target.getSlots() > 0) {
if (target != null && target.getSlots() > 0 && !FilledItemStorage.isFull(target)) {
PriorityBucket bucket = priorityBuckets.computeIfAbsent(connection.insertPriority, PriorityBucket::new);
InsertTarget it = new InsertTarget(connection, new ItemSink.HandlerWrapper(target, entry.getPos(), connection.direction));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@

package aztech.modern_industrialization.thirdparty.fabrictransfer.api.bridge;

import aztech.modern_industrialization.inventory.FilledItemStorage;
import aztech.modern_industrialization.thirdparty.fabrictransfer.api.item.ItemVariant;
import aztech.modern_industrialization.thirdparty.fabrictransfer.api.storage.base.SingleSlotStorage;
import aztech.modern_industrialization.thirdparty.fabrictransfer.api.transaction.Transaction;
import com.google.common.primitives.Ints;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.IItemHandler;

public record SlotItemHandler(SingleSlotStorage<ItemVariant> storage) implements IItemHandler {
public record SlotItemHandler(SingleSlotStorage<ItemVariant> storage) implements IItemHandler, FilledItemStorage {
@Override
public int getSlots() {
return 1;
Expand Down Expand Up @@ -83,4 +84,9 @@ public int getSlotLimit(int slot) {
public boolean isItemValid(int slot, ItemStack stack) {
return true;
}

@Override
public boolean isFull() {
return storage.getAmount() >= storage.getCapacity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -58,6 +59,7 @@ public static ItemVariant of(ItemStack stack) {
private static final Logger LOGGER = LoggerFactory.getLogger("fabric-transfer-api-v1/item");

private final ItemStack stack;
private @Nullable Integer maxStackSize;
private final int hashCode;

private ItemVariantImpl(ItemStack stack) {
Expand Down Expand Up @@ -92,7 +94,10 @@ public ItemStack toStack(int count) {

@Override
public int getMaxStackSize() {
return this.stack.getMaxStackSize();
if (maxStackSize == null) {
maxStackSize = stack.getMaxStackSize();
}
return maxStackSize;
}

@Override
Expand Down
Loading