test
This commit is contained in:
@@ -96,7 +96,7 @@ public class InventoryInterfaceBlockEntity extends BlockEntity {
|
||||
ItemStack cappedStack = insertedStack.copy();
|
||||
cappedStack.setCount(Math.min(insertedStack.getMaxCount(), remainingToInsert));
|
||||
|
||||
ItemStack remaining = insertStackIntoInventory(targetedBlockEntityInventory, cappedStack.copy());
|
||||
ItemStack remaining = insertStackIntoInventory(targetedBlockEntityInventory, cappedStack.copy(), false);
|
||||
if (!remaining.isEmpty()) {
|
||||
ItemStack reverseStack = stack.copy();
|
||||
reverseStack.setCount(remaining.getCount() + remainingToInsert);
|
||||
|
@@ -92,7 +92,7 @@ public class DisplayBlock extends ConnectedBlock implements PolymerTexturedBlock
|
||||
if (storageBlockEntity instanceof DisplayBlockEntity displayBlockEntity) {
|
||||
displayBlockEntity.reindexDrives();
|
||||
int maxFit = howMuchFits(displayBlockEntity.targetItem, player.getInventory());
|
||||
int finalCount = Math.min(player.isSneaking() ? displayBlockEntity.targetItem.getCount() : 1, maxFit);
|
||||
int finalCount = Math.min(player.isSneaking() ? displayBlockEntity.targetItem.getMaxCount() : 1, maxFit);
|
||||
ItemStack insertedStack = displayBlockEntity.targetItem.copy();
|
||||
insertedStack.setCount(finalCount);
|
||||
|
||||
@@ -119,7 +119,7 @@ public class DisplayBlock extends ConnectedBlock implements PolymerTexturedBlock
|
||||
ItemStack cappedStack = insertedStack.copy();
|
||||
cappedStack.setCount(Math.min(insertedStack.getMaxCount(), remainingToInsert));
|
||||
|
||||
ItemStack remaining = insertStackIntoInventory(player.getInventory(), cappedStack.copy());
|
||||
ItemStack remaining = insertStackIntoInventory(player.getInventory(), cappedStack.copy(), true);
|
||||
if (!remaining.isEmpty()) {
|
||||
ItemStack reverseStack = displayBlockEntity.targetItem.copy();
|
||||
reverseStack.setCount(remaining.getCount() + remainingToInsert);
|
||||
@@ -161,15 +161,41 @@ public class DisplayBlock extends ConnectedBlock implements PolymerTexturedBlock
|
||||
displayBlockMangementScreen.updateDisplay();
|
||||
displayBlockMangementScreen.open();
|
||||
} else {
|
||||
ItemStack stack1 = stack.copy();
|
||||
stack1.setCount(player.isSneaking() ? stack.getCount() : 1);
|
||||
int canPutIn = stack1.getCount() - displayBlockEntity.network.putItemStackRemainder(stack1);
|
||||
if (canPutIn > 0) {
|
||||
removeFromInventory(player.getInventory(), stack, canPutIn);
|
||||
ItemStack stack1;
|
||||
boolean wasEmpty = false;
|
||||
if (!stack.isEmpty()) {
|
||||
stack1 = stack.copy();
|
||||
} else {
|
||||
stack1 = displayBlockEntity.targetItem.copy();
|
||||
wasEmpty = true;
|
||||
}
|
||||
displayBlockEntity.itemElement.setItem(displayBlockEntity.targetItem);
|
||||
displayBlockEntity.itemCount += canPutIn;
|
||||
displayBlockEntity.textDisplayElement.setText(Text.of(String.valueOf(displayBlockEntity.itemCount)));
|
||||
int canPutInTemp = 0;
|
||||
if (wasEmpty) {
|
||||
for (int i = 9; i < 45; i++) {
|
||||
ItemStack stack2 = player.getInventory().getStack(i);
|
||||
if (!ItemStack.areItemsAndComponentsEqual(stack1, stack2)) {
|
||||
continue;
|
||||
}
|
||||
stack1.setCount(player.isSneaking() ? (stack1.getCount() == 0 ? stack1.getMaxCount() : stack1.getCount()) : 1);
|
||||
int canPutIn = stack1.getCount() - displayBlockEntity.network.putItemStackRemainder(stack1);
|
||||
if (canPutIn > 0) {
|
||||
removeFromInventory(player.getInventory(), stack2, canPutIn);
|
||||
}
|
||||
canPutInTemp += canPutIn;
|
||||
}
|
||||
} else {
|
||||
if (ItemStack.areItemsAndComponentsEqual(stack1, stack)) {
|
||||
stack1.setCount(player.isSneaking() ? (stack1.getCount() == 0 ? stack1.getMaxCount() : stack1.getCount()) : 1);
|
||||
int canPutIn = stack1.getCount() - displayBlockEntity.network.putItemStackRemainder(stack1);
|
||||
if (canPutIn > 0) {
|
||||
removeFromInventory(player.getInventory(), stack, canPutIn);
|
||||
}
|
||||
canPutInTemp += canPutIn;
|
||||
}
|
||||
}
|
||||
displayBlockEntity.itemElement.setItem(displayBlockEntity.targetItem);
|
||||
displayBlockEntity.itemCount += canPutInTemp;
|
||||
displayBlockEntity.textDisplayElement.setText(Text.of(String.valueOf(displayBlockEntity.itemCount)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -233,9 +233,15 @@ public class StorageOperations {
|
||||
return maxInsert; // Return the maximum insertion count
|
||||
}
|
||||
|
||||
public static ItemStack insertStackIntoInventory(Inventory inventory, ItemStack stack) {
|
||||
public static ItemStack insertStackIntoInventory(Inventory inventory, ItemStack stack, boolean mainOnly) {
|
||||
int startSlot = 0;
|
||||
int endSlot = inventory.size();
|
||||
if (mainOnly) {
|
||||
startSlot = 9;
|
||||
endSlot = 45;
|
||||
}
|
||||
// First, try to merge with existing stacks
|
||||
for (int i = 0; i < inventory.size(); i++) {
|
||||
for (int i = startSlot; i < endSlot; i++) {
|
||||
ItemStack slotStack = inventory.getStack(i);
|
||||
if (canCombine(slotStack, stack)) {
|
||||
int transferAmount = Math.min(stack.getCount(), slotStack.getMaxCount() - slotStack.getCount());
|
||||
@@ -251,7 +257,7 @@ public class StorageOperations {
|
||||
}
|
||||
|
||||
// Next, try to find an empty slot
|
||||
for (int i = 0; i < inventory.size(); i++) {
|
||||
for (int i = startSlot; i < endSlot; i++) {
|
||||
ItemStack slotStack = inventory.getStack(i);
|
||||
if (slotStack.isEmpty()) {
|
||||
inventory.setStack(i, stack.copy());
|
||||
|
@@ -359,7 +359,7 @@ public class StorageScreen extends PagedGui implements Searchable {
|
||||
ItemStack cappedStack = insertedStack.copy();
|
||||
cappedStack.setCount(Math.min(insertedStack.getMaxCount(), remainingToInsert));
|
||||
|
||||
ItemStack remaining = insertStackIntoInventory(playerInventory, cappedStack.copy());
|
||||
ItemStack remaining = insertStackIntoInventory(playerInventory, cappedStack.copy(), true);
|
||||
if (!remaining.isEmpty()) {
|
||||
ItemStack reverseStack = stack.copy();
|
||||
reverseStack.setCount(remaining.getCount() + remainingToInsert);
|
||||
|
Reference in New Issue
Block a user