Improved auto rightclick interaction for when the drawer is empty, closes #36

This commit is contained in:
Buuz135 2022-06-06 16:11:48 +02:00
parent 27259e04d4
commit 5cf93081cd
2 changed files with 55 additions and 50 deletions

View File

@ -68,8 +68,10 @@ public abstract class ControllableDrawerTile<T extends ControllableDrawerTile<T>
for (int i = 0; i < storageUpgrades.getSlots(); i++) {
if (storageUpgrades.getStackInSlot(i).getItem() instanceof StorageUpgradeItem) {
if (i == slot) continue;
if (mult == 1) mult = ((StorageUpgradeItem) storageUpgrades.getStackInSlot(i).getItem()).getStorageMultiplier();
else mult *= ((StorageUpgradeItem) storageUpgrades.getStackInSlot(i).getItem()).getStorageMultiplier();
if (mult == 1)
mult = ((StorageUpgradeItem) storageUpgrades.getStackInSlot(i).getItem()).getStorageMultiplier();
else
mult *= ((StorageUpgradeItem) storageUpgrades.getStackInSlot(i).getItem()).getStorageMultiplier();
}
}
for (int i = 0; i < getStorage().getSlots(); i++) {
@ -219,7 +221,8 @@ public abstract class ControllableDrawerTile<T extends ControllableDrawerTile<T>
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();
if (mult == 1)
mult = ((StorageUpgradeItem) storageUpgrades.getStackInSlot(i).getItem()).getStorageMultiplier();
else mult *= ((StorageUpgradeItem) storageUpgrades.getStackInSlot(i).getItem()).getStorageMultiplier();
}
}
@ -237,7 +240,8 @@ public abstract class ControllableDrawerTile<T extends ControllableDrawerTile<T>
public InteractionResult onSlotActivated(Player playerIn, InteractionHand hand, Direction facing, double hitX, double hitY, double hitZ, int slot) {
ItemStack stack = playerIn.getItemInHand(hand);
if (stack.getItem().equals(FunctionalStorage.CONFIGURATION_TOOL.get()) || stack.getItem().equals(FunctionalStorage.LINKING_TOOL.get())) return InteractionResult.PASS;
if (stack.getItem().equals(FunctionalStorage.CONFIGURATION_TOOL.get()) || stack.getItem().equals(FunctionalStorage.LINKING_TOOL.get()))
return InteractionResult.PASS;
if (!stack.isEmpty() && stack.getItem() instanceof UpgradeItem) {
InventoryComponent component = ((UpgradeItem) stack.getItem()).getType() == UpgradeItem.Type.STORAGE ? storageUpgrades : utilityUpgrades;
for (int i = 0; i < component.getSlots(); i++) {
@ -253,11 +257,12 @@ public abstract class ControllableDrawerTile<T extends ControllableDrawerTile<T>
if (slot == -1) {
openGui(playerIn);
} else if (isServer()) {
if (!stack.isEmpty() && getStorage().isItemValid(slot, stack)) {
if (!stack.isEmpty() && getStorage().insertItem(slot, stack, true).getCount() != stack.getCount()) {
playerIn.setItemInHand(hand, getStorage().insertItem(slot, stack, false));
return InteractionResult.SUCCESS;
} else if (System.currentTimeMillis() - INTERACTION_LOGGER.getOrDefault(playerIn.getUUID(), System.currentTimeMillis()) < 300) {
for (ItemStack itemStack : playerIn.getInventory().items) {
if (!itemStack.isEmpty() && !getStorage().getStackInSlot(slot).isEmpty() && getStorage().insertItem(slot, itemStack, true).getCount() != itemStack.getCount()) {
if (!itemStack.isEmpty() && getStorage().insertItem(slot, itemStack, true).getCount() != itemStack.getCount()) {
itemStack.setCount(getStorage().insertItem(slot, itemStack.copy(), false).getCount());
}
}

View File

@ -85,7 +85,7 @@ public class DrawerTile extends ControllableDrawerTile<DrawerTile> {
public InteractionResult onSlotActivated(Player playerIn, InteractionHand hand, Direction facing, double hitX, double hitY, double hitZ, int slot) {
ItemStack stack = playerIn.getItemInHand(hand);
if (stack.getItem().equals(FunctionalStorage.CONFIGURATION_TOOL.get()) || stack.getItem().equals(FunctionalStorage.LINKING_TOOL.get())) return InteractionResult.PASS;
if (slot != -1 && isLocked() && !playerIn.getItemInHand(hand).isEmpty()){
if (slot != -1 && !playerIn.getItemInHand(hand).isEmpty()){
BigInventoryHandler.BigStack bigStack = getHandler().getStoredStacks().get(slot);
if (bigStack.getStack().isEmpty()){
bigStack.setStack(playerIn.getItemInHand(hand));