diff --git a/src/main/java/com/buuz135/functionalstorage/block/CompactingDrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/CompactingDrawerBlock.java index 92dd63d..c0874b5 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/CompactingDrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/CompactingDrawerBlock.java @@ -172,7 +172,6 @@ public class CompactingDrawerBlock extends RotatableBlock public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) { TileUtil.getTileEntity(worldIn, pos, DrawerTile.class).ifPresent(tile -> { if (tile.getControllerPos() != null){ - System.out.println(TileUtil.getTileEntity(worldIn, tile.getControllerPos()).get()); TileUtil.getTileEntity(worldIn, tile.getControllerPos(), DrawerControllerTile.class).ifPresent(drawerControllerTile -> { drawerControllerTile.addConnectedDrawers(LinkingToolItem.ActionMode.REMOVE, pos); }); diff --git a/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java index 673ac8f..263a2be 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java @@ -222,7 +222,6 @@ public class DrawerBlock extends RotatableBlock { public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) { TileUtil.getTileEntity(worldIn, pos, DrawerTile.class).ifPresent(tile -> { if (tile.getControllerPos() != null){ - System.out.println(TileUtil.getTileEntity(worldIn, tile.getControllerPos()).get()); TileUtil.getTileEntity(worldIn, tile.getControllerPos(), DrawerControllerTile.class).ifPresent(drawerControllerTile -> { drawerControllerTile.addConnectedDrawers(LinkingToolItem.ActionMode.REMOVE, pos); }); diff --git a/src/main/java/com/buuz135/functionalstorage/block/tile/CompactingDrawerTile.java b/src/main/java/com/buuz135/functionalstorage/block/tile/CompactingDrawerTile.java index 70cb2f3..51b371a 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/tile/CompactingDrawerTile.java +++ b/src/main/java/com/buuz135/functionalstorage/block/tile/CompactingDrawerTile.java @@ -44,6 +44,11 @@ public class CompactingDrawerTile extends ControllableDrawerTile this.handler); //TODO Check for the recipe on load @@ -67,6 +72,11 @@ public class CompactingDrawerTile extends ControllableDrawerTile @Save private BlockPos controllerPos; + @Save + private InventoryComponent> storageUpgrades; + @Save + private InventoryComponent> utilityUpgrades; public ControllableDrawerTile(BasicTileBlock base, BlockPos pos, BlockState state) { super(base, pos, state); + this.addInventory((InventoryComponent) (this.storageUpgrades = new InventoryComponent>("storage_upgrades", 10, 70, getStorageSlotAmount()) + .setInputFilter((stack, integer) -> stack.getItem() instanceof UpgradeItem && ((UpgradeItem) stack.getItem()).getType() == UpgradeItem.Type.STORAGE)) + ); + this.addInventory((InventoryComponent) (this.utilityUpgrades = new InventoryComponent>("utility_upgrades", 114, 70, 3) + .setInputFilter((stack, integer) -> stack.getItem() instanceof UpgradeItem && ((UpgradeItem) stack.getItem()).getType() == UpgradeItem.Type.UTILITY)) + ); + addGuiAddonFactory(() -> new TextScreenAddon("Storage", 10, 59, false, ChatFormatting.DARK_GRAY.getColor())); + addGuiAddonFactory(() -> new TextScreenAddon("Utility", 114, 59, false, ChatFormatting.DARK_GRAY.getColor())); + addGuiAddonFactory(() -> new TextScreenAddon("key.categories.inventory", 8, 92, false, ChatFormatting.DARK_GRAY.getColor()){ + @Override + public String getText() { + return new TranslatableComponent("key.categories.inventory").getString(); + } + }); } public BlockPos getControllerPos() { @@ -47,6 +71,17 @@ public abstract class ControllableDrawerTile this.controllerPos = controllerPos; } + public int getStorageMultiplier(){ + int mult = 1; + for (int i = 0; i < storageUpgrades.getSlots(); i++) { + if (storageUpgrades.getStackInSlot(i).getItem() instanceof StorageUpgradeItem){ + if (mult == 1) mult = ((StorageUpgradeItem) storageUpgrades.getStackInSlot(i).getItem()).getStorageMultiplier(); + else mult *= ((StorageUpgradeItem) storageUpgrades.getStackInSlot(i).getItem()).getStorageMultiplier(); + } + } + return mult; + } + public InteractionResult onSlotActivated(Player playerIn, InteractionHand hand, Direction facing, double hitX, double hitY, double hitZ, int slot) { if (super.onActivated(playerIn, hand, facing, hitX, hitY, hitZ) == InteractionResult.SUCCESS) { return InteractionResult.SUCCESS; @@ -70,6 +105,8 @@ public abstract class ControllableDrawerTile return InteractionResult.SUCCESS; } + public abstract int getStorageSlotAmount(); + public void onClicked(Player playerIn, int slot) { if (isServer() && slot != -1){ HitResult rayTraceResult = RayTraceUtils.rayTraceSimple(this.level, playerIn, 16, 0); diff --git a/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerControllerTile.java b/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerControllerTile.java index c137678..3eb45c5 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerControllerTile.java +++ b/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerControllerTile.java @@ -45,14 +45,17 @@ public class DrawerControllerTile extends ControllableDrawerTile this.handler); } + @Override + public int getStorageSlotAmount() { + return 1; + } + @Override public void serverTick(Level level, BlockPos pos, BlockState state, DrawerControllerTile blockEntity) { super.serverTick(level, pos, state, blockEntity); if (this.connectedDrawers.getConnectedDrawers().size() != this.connectedDrawers.getHandlers().size()){ this.connectedDrawers.setLevel(getLevel()); this.connectedDrawers.rebuild(); - //this.lazyStorage.invalidate(); - //this.lazyStorage = LazyOptional.of(() -> this.handler); markForUpdate(); updateNeigh(); } diff --git a/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerTile.java b/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerTile.java index c0dedd5..769025f 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerTile.java +++ b/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerTile.java @@ -45,6 +45,11 @@ public class DrawerTile extends ControllableDrawerTile { public void onChange() { DrawerTile.this.markForUpdate(); } + + @Override + public int getMultiplier() { + return getStorageMultiplier(); + } }; lazyStorage = LazyOptional.of(() -> this.handler); } @@ -68,6 +73,11 @@ public class DrawerTile extends ControllableDrawerTile { return type; } + @Override + public int getStorageSlotAmount() { + return 4; + } + @Override public IItemHandler getStorage() { return handler; diff --git a/src/main/java/com/buuz135/functionalstorage/inventory/BigInventoryHandler.java b/src/main/java/com/buuz135/functionalstorage/inventory/BigInventoryHandler.java index 072f600..5b15341 100644 --- a/src/main/java/com/buuz135/functionalstorage/inventory/BigInventoryHandler.java +++ b/src/main/java/com/buuz135/functionalstorage/inventory/BigInventoryHandler.java @@ -53,7 +53,7 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa int inserted = Math.min(getSlotLimit(slot) - bigStack.getAmount(), stack.getCount()); if (!simulate){ bigStack.setStack(stack); - bigStack.setAmount(Math.min(bigStack.getAmount() + inserted, type.getSlotAmount())); + bigStack.setAmount(Math.min(bigStack.getAmount() + inserted, getSlotLimit(slot))); onChange(); } if (inserted == stack.getCount() || voidItems) return ItemStack.EMPTY; @@ -92,7 +92,7 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa @Override public int getSlotLimit(int slot) { - return Math.min(Integer.MAX_VALUE, type.getSlotAmount()); + return Math.min(Integer.MAX_VALUE, type.getSlotAmount() * getMultiplier()); } @Override @@ -131,6 +131,8 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa public abstract void onChange(); + public abstract int getMultiplier(); + public class BigStack{ private ItemStack stack; diff --git a/src/main/java/com/buuz135/functionalstorage/inventory/CompactingInventoryHandler.java b/src/main/java/com/buuz135/functionalstorage/inventory/CompactingInventoryHandler.java index 70b869e..c5fc76e 100644 --- a/src/main/java/com/buuz135/functionalstorage/inventory/CompactingInventoryHandler.java +++ b/src/main/java/com/buuz135/functionalstorage/inventory/CompactingInventoryHandler.java @@ -18,7 +18,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe public static String STACK = "Stack"; public static String AMOUNT = "Amount"; - private final int TOTAL_AMOUNT = 8192 * 9 * 9; + private final int TOTAL_AMOUNT = 512 * 9 * 9; private int amount; private boolean voidItems; @@ -51,10 +51,10 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { if (isItemValid(slot, stack)) { CompactingUtil.Result result = this.resultList.get(slot); - int inserted = Math.min(TOTAL_AMOUNT - amount, stack.getCount() * result.getNeeded()); + int inserted = Math.min(getSlotLimit(slot) * result.getNeeded() - amount, stack.getCount() * result.getNeeded()); inserted = (int) (Math.floor(inserted / result.getNeeded()) * result.getNeeded()); if (!simulate){ - this.amount = Math.min(this.amount + inserted, TOTAL_AMOUNT); + this.amount = Math.min(this.amount + inserted, TOTAL_AMOUNT * getMultiplier()); onChange(); } if (inserted == stack.getCount() * result.getNeeded() || voidItems) return ItemStack.EMPTY; @@ -115,7 +115,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe @Override public int getSlotLimit(int slot) { - return (int) Math.floor(TOTAL_AMOUNT / this.resultList.get(slot).getNeeded()); + return (int) Math.min(Integer.MAX_VALUE, Math.floor((TOTAL_AMOUNT * getMultiplier()) / this.resultList.get(slot).getNeeded())); } @Override @@ -156,6 +156,8 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe public abstract void onChange(); + public abstract int getMultiplier(); + public List getResultList() { return resultList; } diff --git a/src/main/java/com/buuz135/functionalstorage/item/UpgradeItem.java b/src/main/java/com/buuz135/functionalstorage/item/UpgradeItem.java index f756d4a..0b17fd3 100644 --- a/src/main/java/com/buuz135/functionalstorage/item/UpgradeItem.java +++ b/src/main/java/com/buuz135/functionalstorage/item/UpgradeItem.java @@ -12,6 +12,10 @@ public class UpgradeItem extends BasicItem { this.type = type; } + public Type getType() { + return type; + } + public static enum Type{ STORAGE, UTILITY