From f6e9a54da74a391acaf88dbf33fb62ac13360e77 Mon Sep 17 00:00:00 2001 From: wdfaESfaef <2622389575@qq.com> Date: Tue, 2 Apr 2024 10:25:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=90=88=E6=88=90?= =?UTF-8?q?=E5=99=A8=E7=89=A9=E5=93=81=E9=97=AA=E7=83=81=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../anvilcraft/inventory/AutoCrafterMenu.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java b/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java index 2a45385dc..26a52dcef 100644 --- a/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java +++ b/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java @@ -56,6 +56,41 @@ public AutoCrafterMenu(int containerId, @NotNull Inventory inventory, @NotNull C } this.updateResult(); } + + @Override + public @NotNull ItemStack quickMoveStack(Player player, int index) { + ItemStack itemStack = ItemStack.EMPTY; + if (index >= this.slots.size()) return itemStack; + Slot slot = this.slots.get(index); + if (!slot.hasItem()) return itemStack; + ItemStack itemStack2 = slot.getItem(); + itemStack = itemStack2.copy(); + + Boolean needMove; + if(index < this.machine.getContainerSize()){ + needMove = !this.moveItemStackTo(itemStack2, this.machine.getContainerSize(), this.machine.getContainerSize() + 36, true); + }else{ + needMove = false; + if (this.getMachine() instanceof AutoCrafterBlockEntity entity) { + for (int i = 0; i < this.machine.getContainerSize(); i++) { + ItemStack filter = getFilter(i); + NonNullList disableds = entity.getDisabled(); + if (filter.is(itemStack.getItem()) || !disableds.get(i)) { + needMove = !this.moveItemStackTo(itemStack2, i, i + 1, false); + } + } + } + } + if (needMove) { + return ItemStack.EMPTY; + } + if (itemStack2.isEmpty()) slot.setByPlayer(ItemStack.EMPTY); + else slot.setChanged(); + if (itemStack2.getCount() == itemStack.getCount()) return ItemStack.EMPTY; + slot.onTake(player, itemStack2); + return itemStack; + } + public @Nullable IFilterBlockEntity getEntity() { return this.machine instanceof IFilterBlockEntity entity ? entity : null; } From cf82e73cf62ed4c0d1d70d04254859e17bed08c7 Mon Sep 17 00:00:00 2001 From: wdfaESfaef <2622389575@qq.com> Date: Wed, 3 Apr 2024 09:50:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E8=A6=81=E6=B1=82?= =?UTF-8?q?=E5=81=9A=E4=BA=86=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../anvilcraft/inventory/AutoCrafterMenu.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java b/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java index 26a52dcef..3178da195 100644 --- a/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java +++ b/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java @@ -65,30 +65,32 @@ public AutoCrafterMenu(int containerId, @NotNull Inventory inventory, @NotNull C if (!slot.hasItem()) return itemStack; ItemStack itemStack2 = slot.getItem(); itemStack = itemStack2.copy(); + if (this.quickMoveFilter(index,itemStack2)) { + return ItemStack.EMPTY; + } + if (itemStack2.isEmpty()) slot.setByPlayer(ItemStack.EMPTY); + else slot.setChanged(); + if (itemStack2.getCount() == itemStack.getCount()) return ItemStack.EMPTY; + slot.onTake(player, itemStack2); + return itemStack; + } - Boolean needMove; + private boolean quickMoveFilter(int index,ItemStack itemStack){ if(index < this.machine.getContainerSize()){ - needMove = !this.moveItemStackTo(itemStack2, this.machine.getContainerSize(), this.machine.getContainerSize() + 36, true); + return !this.moveItemStackTo(itemStack, this.machine.getContainerSize(), this.machine.getContainerSize() + 36, true); }else{ - needMove = false; - if (this.getMachine() instanceof AutoCrafterBlockEntity entity) { + boolean bl = false; + if (this.getMachine() instanceof IFilterBlockEntity entity) { for (int i = 0; i < this.machine.getContainerSize(); i++) { ItemStack filter = getFilter(i); NonNullList disableds = entity.getDisabled(); if (filter.is(itemStack.getItem()) || !disableds.get(i)) { - needMove = !this.moveItemStackTo(itemStack2, i, i + 1, false); + bl = !this.moveItemStackTo(itemStack, i, i + 1, false); } } } + return bl; } - if (needMove) { - return ItemStack.EMPTY; - } - if (itemStack2.isEmpty()) slot.setByPlayer(ItemStack.EMPTY); - else slot.setChanged(); - if (itemStack2.getCount() == itemStack.getCount()) return ItemStack.EMPTY; - slot.onTake(player, itemStack2); - return itemStack; } public @Nullable IFilterBlockEntity getEntity() { From f9385988af5add909b929b575fa029623dadff86 Mon Sep 17 00:00:00 2001 From: wdfaESfaef <2622389575@qq.com> Date: Wed, 3 Apr 2024 13:41:02 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=88=96=E8=AE=B8=E8=BF=99=E4=B9=88?= =?UTF-8?q?=E6=94=B9=E4=B9=9F=E6=B2=A1=E9=97=AE=E9=A2=98=3F=E4=BC=9A?= =?UTF-8?q?=E4=B8=8D=E4=BC=9A=E5=AF=B9=E5=85=B6=E4=BB=96=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E9=80=A0=E6=88=90=E5=BD=B1=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../anvilcraft/inventory/AutoCrafterMenu.java | 36 ------------------- .../anvilcraft/inventory/BaseMachineMenu.java | 26 +++++++++++--- 2 files changed, 21 insertions(+), 41 deletions(-) diff --git a/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java b/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java index 3178da195..c8e0fd221 100644 --- a/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java +++ b/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java @@ -57,42 +57,6 @@ public AutoCrafterMenu(int containerId, @NotNull Inventory inventory, @NotNull C this.updateResult(); } - @Override - public @NotNull ItemStack quickMoveStack(Player player, int index) { - ItemStack itemStack = ItemStack.EMPTY; - if (index >= this.slots.size()) return itemStack; - Slot slot = this.slots.get(index); - if (!slot.hasItem()) return itemStack; - ItemStack itemStack2 = slot.getItem(); - itemStack = itemStack2.copy(); - if (this.quickMoveFilter(index,itemStack2)) { - return ItemStack.EMPTY; - } - if (itemStack2.isEmpty()) slot.setByPlayer(ItemStack.EMPTY); - else slot.setChanged(); - if (itemStack2.getCount() == itemStack.getCount()) return ItemStack.EMPTY; - slot.onTake(player, itemStack2); - return itemStack; - } - - private boolean quickMoveFilter(int index,ItemStack itemStack){ - if(index < this.machine.getContainerSize()){ - return !this.moveItemStackTo(itemStack, this.machine.getContainerSize(), this.machine.getContainerSize() + 36, true); - }else{ - boolean bl = false; - if (this.getMachine() instanceof IFilterBlockEntity entity) { - for (int i = 0; i < this.machine.getContainerSize(); i++) { - ItemStack filter = getFilter(i); - NonNullList disableds = entity.getDisabled(); - if (filter.is(itemStack.getItem()) || !disableds.get(i)) { - bl = !this.moveItemStackTo(itemStack, i, i + 1, false); - } - } - } - return bl; - } - } - public @Nullable IFilterBlockEntity getEntity() { return this.machine instanceof IFilterBlockEntity entity ? entity : null; } diff --git a/src/main/java/dev/dubhe/anvilcraft/inventory/BaseMachineMenu.java b/src/main/java/dev/dubhe/anvilcraft/inventory/BaseMachineMenu.java index 262ddf9ca..89af49df1 100644 --- a/src/main/java/dev/dubhe/anvilcraft/inventory/BaseMachineMenu.java +++ b/src/main/java/dev/dubhe/anvilcraft/inventory/BaseMachineMenu.java @@ -1,8 +1,10 @@ package dev.dubhe.anvilcraft.inventory; import dev.dubhe.anvilcraft.block.entity.BaseMachineBlockEntity; +import dev.dubhe.anvilcraft.block.entity.IFilterBlockEntity; import lombok.Getter; import net.minecraft.core.Direction; +import net.minecraft.core.NonNullList; import net.minecraft.world.Container; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; @@ -29,11 +31,7 @@ protected BaseMachineMenu(@Nullable MenuType menuType, int containerId, @NotN if (!slot.hasItem()) return itemStack; ItemStack itemStack2 = slot.getItem(); itemStack = itemStack2.copy(); - if ( - index < this.machine.getContainerSize() ? - !this.moveItemStackTo(itemStack2, this.machine.getContainerSize(), this.machine.getContainerSize() + 36, true) : - !this.moveItemStackTo(itemStack2, 0, this.machine.getContainerSize(), false) - ) { + if (quickMoveFilter(index,itemStack2)) { return ItemStack.EMPTY; } if (itemStack2.isEmpty()) slot.setByPlayer(ItemStack.EMPTY); @@ -43,6 +41,24 @@ protected BaseMachineMenu(@Nullable MenuType menuType, int containerId, @NotN return itemStack; } + private boolean quickMoveFilter(int index,ItemStack itemStack){ + if(index < this.machine.getContainerSize()){ + return !this.moveItemStackTo(itemStack, this.machine.getContainerSize(), this.machine.getContainerSize() + 36, true); + }else{ + boolean bl = false; + if (this.getMachine() instanceof IFilterBlockEntity entity) { + for (int i = 0; i < this.machine.getContainerSize(); i++) { + ItemStack filter = entity.getFilter().get(i); + NonNullList disableds = entity.getDisabled(); + if (filter.is(itemStack.getItem()) || !disableds.get(i)) { + bl = !this.moveItemStackTo(itemStack, i, i + 1, false); + } + } + } + return bl; + } + } + @Override public boolean stillValid(Player player) { return this.machine.stillValid(player);