Skip to content

Commit

Permalink
empty if statements
Browse files Browse the repository at this point in the history
  • Loading branch information
notTamion committed May 26, 2024
1 parent 77c972f commit 30e4070
Showing 1 changed file with 47 additions and 36 deletions.
83 changes: 47 additions & 36 deletions patches/server/1049-Fix-CraftBukkit-drag-system.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,69 @@ Subject: [PATCH] Fix CraftBukkit drag system

== AT ==
public net.minecraft.world.inventory.AbstractContainerMenu quickcraftSlots
public net.minecraft.world.inventory.AbstractContainerMenu quickcraftType

diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index c450447585af4c8cdc87abe871c229ff895c3e53..49a3012064ee3d73cf4d5fa1a9e1713f955d8404 100644
index c450447585af4c8cdc87abe871c229ff895c3e53..e2f9a442878d03d664f48a6df0ef185d3cf622ea 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -3118,6 +3118,51 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
@@ -3118,6 +3118,61 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
}
break;
case QUICK_CRAFT:
+ // Paper start - Fix CraftBukkit drag system
+ if (AbstractContainerMenu.getQuickcraftHeader(packet.getButtonNum()) == 2 && this.player.containerMenu.quickcraftSlots.size() == 1) {
+ if (packet.getButtonNum() == 6) {
+ click = ClickType.RIGHT;
+ action = InventoryAction.PLACE_ONE;
+ } else {
+ click = ClickType.LEFT;
+ Slot slot = this.player.containerMenu.quickcraftSlots.iterator().next();
+ ItemStack clickedItem = slot.getItem();
+ ItemStack cursor = this.player.containerMenu.getCarried();
+ if (clickedItem.isEmpty()) {
+ if (!cursor.isEmpty()) {
+ action = InventoryAction.PLACE_ALL;
+ }
+ } else if (slot.mayPickup(this.player)) {
+ if (cursor.isEmpty()) {
+ action = InventoryAction.PICKUP_ALL;
+ } else if (slot.mayPlace(cursor)) {
+ if (ItemStack.isSameItemSameComponents(clickedItem, cursor)) {
+ int toPlace = cursor.getCount();
+ toPlace = Math.min(toPlace, clickedItem.getMaxStackSize() - clickedItem.getCount());
+ toPlace = Math.min(toPlace, slot.container.getMaxStackSize() - clickedItem.getCount());
+ if (toPlace == 1) {
+ action = InventoryAction.PLACE_ONE;
+ } else if (toPlace == cursor.getCount()) {
+ int currentStatus = this.player.containerMenu.quickcraftStatus;
+ int newStatus = AbstractContainerMenu.getQuickcraftHeader(packet.getButtonNum());
+ if ((currentStatus != 1 || newStatus != 2 && currentStatus != newStatus)) {
+ } else if (this.player.containerMenu.getCarried().isEmpty()) {
+ } else if (newStatus == 0) {
+ } else if (newStatus == 1) {
+ } else if (newStatus == 2) {
+ if (!this.player.containerMenu.quickcraftSlots.isEmpty()) {
+ if (this.player.containerMenu.quickcraftSlots.size() == 1) {
+ if (packet.getButtonNum() == 6) {
+ click = ClickType.RIGHT;
+ action = InventoryAction.PLACE_ONE;
+ } else {
+ click = ClickType.LEFT;
+ Slot slot = this.player.containerMenu.quickcraftSlots.iterator().next();
+ ItemStack clickedItem = slot.getItem();
+ ItemStack cursor = this.player.containerMenu.getCarried();
+ if (clickedItem.isEmpty()) {
+ if (!cursor.isEmpty()) {
+ action = InventoryAction.PLACE_ALL;
+ } else if (toPlace != 0) {
+ action = InventoryAction.PLACE_SOME;
+ }
+ } else if (cursor.getCount() <= slot.getMaxStackSize()) {
+ action = InventoryAction.SWAP_WITH_CURSOR;
+ }
+ } else if (ItemStack.isSameItemSameComponents(cursor, clickedItem)) {
+ if (clickedItem.getCount() >= 0) {
+ if (clickedItem.getCount() + cursor.getCount() <= cursor.getMaxStackSize()) {
+ } else if (slot.mayPickup(this.player)) {
+ if (cursor.isEmpty()) {
+ action = InventoryAction.PICKUP_ALL;
+ } else if (slot.mayPlace(cursor)) {
+ if (ItemStack.isSameItemSameComponents(clickedItem, cursor)) {
+ int toPlace = cursor.getCount();
+ toPlace = Math.min(toPlace, clickedItem.getMaxStackSize() - clickedItem.getCount());
+ toPlace = Math.min(toPlace, slot.container.getMaxStackSize() - clickedItem.getCount());
+ if (toPlace == 1) {
+ action = InventoryAction.PLACE_ONE;
+ } else if (toPlace == cursor.getCount()) {
+ action = InventoryAction.PLACE_ALL;
+ } else if (toPlace != 0) {
+ action = InventoryAction.PLACE_SOME;
+ }
+ } else if (cursor.getCount() <= slot.getMaxStackSize()) {
+ action = InventoryAction.SWAP_WITH_CURSOR;
+ }
+ } else if (ItemStack.isSameItemSameComponents(cursor, clickedItem)) {
+ if (clickedItem.getCount() >= 0) {
+ if (clickedItem.getCount() + cursor.getCount() <= cursor.getMaxStackSize()) {
+ action = InventoryAction.PICKUP_ALL;
+ }
+ }
+ }
+ }
+ }
+ if (!new InventoryClickEvent(inventory, type, this.player.containerMenu.quickcraftSlots.iterator().next().index, click, action).callEvent())
+ break;
+ }
+ }
+ if (!new InventoryClickEvent(inventory, type, this.player.containerMenu.quickcraftSlots.iterator().next().index, click, action).callEvent())
+ break;
+ }
+ // Paper end - Fix CraftBukkit drag system
this.player.containerMenu.clicked(packet.getSlotNum(), packet.getButtonNum(), packet.getClickType(), this.player);
Expand Down

0 comments on commit 30e4070

Please sign in to comment.