Crane extractors take items to inventory when not facing a conveyor

Allows using them as an ad-hoc hopper with a small buffer. Previously their buffer was effectively rudimentary -- it was used for output, but nothing ever inputted into it.
This commit is contained in:
abel1502 2025-06-28 23:14:45 +03:00
parent fa075a3bd4
commit db109d8bcf
No known key found for this signature in database
GPG Key ID: 076926596A536338

View File

@ -10,6 +10,8 @@ import com.hbm.items.ModItems;
import com.hbm.module.ModulePatternMatcher; import com.hbm.module.ModulePatternMatcher;
import com.hbm.tileentity.IControlReceiverFilter; import com.hbm.tileentity.IControlReceiverFilter;
import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.IGUIProvider;
import com.hbm.util.InventoryUtil;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -95,53 +97,61 @@ public class TileEntityCraneExtractor extends TileEntityCraneBase implements IGU
boolean hasSent = false; boolean hasSent = false;
IConveyorBelt belt = null;
if(b instanceof IConveyorBelt) { if(b instanceof IConveyorBelt) {
belt = (IConveyorBelt) b;
}
IConveyorBelt belt = (IConveyorBelt) b; /* try to send items from a connected inv, if present */
if(te instanceof IInventory) {
/* try to send items from a connected inv, if present */ IInventory inv = (IInventory) te;
if(te instanceof IInventory) { int size = access == null ? inv.getSizeInventory() : access.length;
IInventory inv = (IInventory) te; for(int i = 0; i < size; i++) {
int size = access == null ? inv.getSizeInventory() : access.length; int index = access == null ? i : access[i];
ItemStack stack = inv.getStackInSlot(index);
for(int i = 0; i < size; i++) { if(stack != null && (sided == null || sided.canExtractItem(index, stack, inputSide.getOpposite().ordinal()))){
int index = access == null ? i : access[i];
ItemStack stack = inv.getStackInSlot(index);
if(stack != null && (sided == null || sided.canExtractItem(index, stack, inputSide.getOpposite().ordinal()))){ boolean match = this.matchesFilter(stack);
boolean match = this.matchesFilter(stack); if((isWhitelist && match) || (!isWhitelist && !match)) {
stack = stack.copy();
int toSend = Math.min(amount, stack.stackSize);
if((isWhitelist && match) || (!isWhitelist && !match)) { if (belt != null) {
stack = stack.copy();
int toSend = Math.min(amount, stack.stackSize);
inv.decrStackSize(index, toSend); inv.decrStackSize(index, toSend);
stack.stackSize = toSend; stack.stackSize = toSend;
sendItem(stack, belt, outputSide); sendItem(stack, belt, outputSide);
hasSent = true; } else {
break; stack.stackSize = toSend;
ItemStack remaining = InventoryUtil.tryAddItemToInventory(this.slots, stack);
inv.decrStackSize(index, toSend - (remaining == null ? 0 : remaining.stackSize));
} }
hasSent = true;
break;
} }
} }
} }
}
/* if no item has been sent, send buffered items while ignoring the filter */ /* if no item has been sent, send buffered items while ignoring the filter */
if(!hasSent) { if(!hasSent && belt != null) {
for(int i = 9; i < 18; i++) { for(int i = 9; i < 18; i++) {
ItemStack stack = slots[i]; ItemStack stack = slots[i];
if(stack != null){ if(stack != null){
stack = stack.copy(); stack = stack.copy();
int toSend = Math.min(amount, stack.stackSize); int toSend = Math.min(amount, stack.stackSize);
decrStackSize(i, toSend);
stack.stackSize = toSend;
sendItem(stack, belt, outputSide); decrStackSize(i, toSend);
break; stack.stackSize = toSend;
} sendItem(stack, belt, outputSide);
break;
} }
} }
} }