add shulker extraction and fix storing techreborn storage (#3111)

* add shulker extraction and fix storing techreborn storage

Only accept when nbt is null.
Adds shulker-extracting support

* fix when storeItemStack was empty

* fix inputting stack at first

* Use MC pair

---------

Co-authored-by: modmuss50 <modmuss50@gmail.com>
This commit is contained in:
AngelBottomless 2023-03-18 21:35:56 +09:00 committed by GitHub
parent 9841d3332d
commit 8b527dbead
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 116 additions and 5 deletions

View file

@ -36,10 +36,12 @@ import net.minecraft.item.SkullItem;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import oshi.util.tuples.Pair;
import reborncore.api.IListInfoProvider;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
@ -90,7 +92,6 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
inventory = new RebornInventory<>(2, "ItemInventory", 64, this);
configureEntity(type);
}
private void configureEntity(TRContent.StorageUnit type) {
// Set capacity to local config unless overridden by server
if(serverCapacity == -1){
@ -184,7 +185,6 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
}
public ItemStack processInput(ItemStack inputStack) {
if (!isValid(INPUT_SLOT, inputStack)){
return inputStack;
}
@ -205,7 +205,21 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
// Amount of items that can be added before reaching capacity
int reminder = maxCapacity - getCurrentCapacity();
DefaultedList<ItemStack> optionalShulkerStack = ItemUtils.getBlockEntityStacks(inputStack);
if (isLocked() && ItemUtils.canExtractFromCachedShulker(optionalShulkerStack, lockedItemStack) > 0 ) {
Pair<Integer, ItemStack> pair = ItemUtils.extractFromShulker(inputStack, optionalShulkerStack, lockedItemStack, reminder);
if (pair.getA() != 0) {
int amount = pair.getA();
if (storeItemStack.isEmpty()) {
storeItemStack = lockedItemStack.copy();
amount = amount -1;
}
addStoredItemCount(amount);
inputStack.setNbt(pair.getB().getNbt());
inventory.setHashChanged();
}
return inputStack;
}
if (inputStack.getCount() <= reminder) {
// Add full stack
if (storeItemStack == ItemStack.EMPTY){
@ -251,7 +265,6 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
if (world == null || world.isClient) {
return;
}
// If there is an item in the input AND stored is less than max capacity
if (!inventory.getStack(INPUT_SLOT).isEmpty() && !isFull()) {
inventory.setStack(INPUT_SLOT, processInput(inventory.getStack(INPUT_SLOT)));
@ -391,10 +404,15 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
}
// do not allow other storage units to avoid NBT overflow. Fix #2580
if (inputStack.isIn(TRContent.ItemTags.STORAGE_UNITS)) {
return false;
NbtCompound tagCompound = inputStack.getNbt();
return (tagCompound == null || tagCompound.getSize() == 0) && (getStoredStack().isEmpty() || ItemUtils.isItemEqual(getStoredStack(), inputStack, true, true));
}
if (isLocked()) {
//allow shulker bundle extraction when locked
if (ItemUtils.canExtractAnyFromShulker(inputStack, lockedItemStack)) {
return true;
}
return ItemUtils.isItemEqual(lockedItemStack, inputStack, true, true);
}