diff options
Diffstat (limited to 'patch-remap/mache-spigotflower/net/minecraft/world/inventory/GrindstoneMenu.java.patch')
-rw-r--r-- | patch-remap/mache-spigotflower/net/minecraft/world/inventory/GrindstoneMenu.java.patch | 299 |
1 files changed, 299 insertions, 0 deletions
diff --git a/patch-remap/mache-spigotflower/net/minecraft/world/inventory/GrindstoneMenu.java.patch b/patch-remap/mache-spigotflower/net/minecraft/world/inventory/GrindstoneMenu.java.patch new file mode 100644 index 0000000000..54f2aafccf --- /dev/null +++ b/patch-remap/mache-spigotflower/net/minecraft/world/inventory/GrindstoneMenu.java.patch @@ -0,0 +1,299 @@ +--- a/net/minecraft/world/inventory/GrindstoneMenu.java ++++ b/net/minecraft/world/inventory/GrindstoneMenu.java +@@ -9,7 +9,6 @@ + import net.minecraft.world.SimpleContainer; + import net.minecraft.world.entity.ExperienceOrb; + import net.minecraft.world.entity.player.Inventory; +-import net.minecraft.world.entity.player.Player; + import net.minecraft.world.item.Item; + import net.minecraft.world.item.ItemStack; + import net.minecraft.world.item.Items; +@@ -18,9 +17,30 @@ + import net.minecraft.world.level.Level; + import net.minecraft.world.level.block.Blocks; + import net.minecraft.world.phys.Vec3; ++// CraftBukkit start ++import org.bukkit.Location; ++import org.bukkit.craftbukkit.inventory.CraftInventoryGrindstone; ++import org.bukkit.craftbukkit.inventory.CraftInventoryView; ++import org.bukkit.entity.Player; ++// CraftBukkit end + + public class GrindstoneMenu extends AbstractContainerMenu { + ++ // CraftBukkit start ++ private CraftInventoryView bukkitEntity = null; ++ private Player player; ++ ++ @Override ++ public CraftInventoryView getBukkitView() { ++ if (bukkitEntity != null) { ++ return bukkitEntity; ++ } ++ ++ CraftInventoryGrindstone inventory = new CraftInventoryGrindstone(this.repairSlots, this.resultSlots); ++ bukkitEntity = new CraftInventoryView(this.player, inventory, this); ++ return bukkitEntity; ++ } ++ // CraftBukkit end + public static final int MAX_NAME_LENGTH = 35; + public static final int INPUT_SLOT = 0; + public static final int ADDITIONAL_SLOT = 1; +@@ -33,52 +53,54 @@ + final Container repairSlots; + private final ContainerLevelAccess access; + +- public GrindstoneMenu(int i, Inventory inventory) { +- this(i, inventory, ContainerLevelAccess.NULL); ++ public GrindstoneMenu(int containerId, Inventory playerInventory) { ++ this(containerId, playerInventory, ContainerLevelAccess.NULL); + } + +- public GrindstoneMenu(int i, Inventory inventory, final ContainerLevelAccess containerlevelaccess) { +- super(MenuType.GRINDSTONE, i); ++ public GrindstoneMenu(int containerId, Inventory playerInventory, final ContainerLevelAccess access) { ++ super(MenuType.GRINDSTONE, containerId); + this.resultSlots = new ResultContainer(); + this.repairSlots = new SimpleContainer(2) { + @Override +- @Override + public void setChanged() { + super.setChanged(); + GrindstoneMenu.this.slotsChanged(this); + } ++ ++ // CraftBukkit start ++ @Override ++ public Location getLocation() { ++ return access.getLocation(); ++ } ++ // CraftBukkit end + }; +- this.access = containerlevelaccess; ++ this.access = access; + this.addSlot(new Slot(this.repairSlots, 0, 49, 19) { + @Override +- @Override +- public boolean mayPlace(ItemStack itemstack) { +- return itemstack.isDamageableItem() || itemstack.is(Items.ENCHANTED_BOOK) || itemstack.isEnchanted(); ++ public boolean mayPlace(ItemStack stack) { ++ return stack.isDamageableItem() || stack.is(Items.ENCHANTED_BOOK) || stack.isEnchanted(); + } + }); + this.addSlot(new Slot(this.repairSlots, 1, 49, 40) { + @Override +- @Override +- public boolean mayPlace(ItemStack itemstack) { +- return itemstack.isDamageableItem() || itemstack.is(Items.ENCHANTED_BOOK) || itemstack.isEnchanted(); ++ public boolean mayPlace(ItemStack stack) { ++ return stack.isDamageableItem() || stack.is(Items.ENCHANTED_BOOK) || stack.isEnchanted(); + } + }); + this.addSlot(new Slot(this.resultSlots, 2, 129, 34) { + @Override +- @Override +- public boolean mayPlace(ItemStack itemstack) { ++ public boolean mayPlace(ItemStack stack) { + return false; + } + + @Override +- @Override +- public void onTake(Player player, ItemStack itemstack) { +- containerlevelaccess.execute((level, blockpos) -> { +- if (level instanceof ServerLevel) { +- ExperienceOrb.award((ServerLevel) level, Vec3.atCenterOf(blockpos), this.getExperienceAmount(level)); ++ public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) { ++ access.execute((world, blockposition) -> { ++ if (world instanceof ServerLevel) { ++ ExperienceOrb.award((ServerLevel) world, Vec3.atCenterOf(blockposition), this.getExperienceAmount(world)); + } + +- level.levelEvent(1042, blockpos, 0); ++ world.levelEvent(1042, blockposition, 0); + }); + GrindstoneMenu.this.repairSlots.setItem(0, ItemStack.EMPTY); + GrindstoneMenu.this.repairSlots.setItem(1, ItemStack.EMPTY); +@@ -98,9 +120,9 @@ + } + } + +- private int getExperienceFromItem(ItemStack itemstack) { ++ private int getExperienceFromItem(ItemStack stack) { + int j = 0; +- Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(itemstack); ++ Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(stack); + Iterator iterator = map.entrySet().iterator(); + + while (iterator.hasNext()) { +@@ -121,21 +143,21 @@ + + for (j = 0; j < 3; ++j) { + for (int k = 0; k < 9; ++k) { +- this.addSlot(new Slot(inventory, k + j * 9 + 9, 8 + k * 18, 84 + j * 18)); ++ this.addSlot(new Slot(playerInventory, k + j * 9 + 9, 8 + k * 18, 84 + j * 18)); + } + } + + for (j = 0; j < 9; ++j) { +- this.addSlot(new Slot(inventory, j, 8 + j * 18, 142)); ++ this.addSlot(new Slot(playerInventory, j, 8 + j * 18, 142)); + } + ++ player = (Player) playerInventory.player.getBukkitEntity(); // CraftBukkit + } + + @Override +- @Override +- public void slotsChanged(Container container) { +- super.slotsChanged(container); +- if (container == this.repairSlots) { ++ public void slotsChanged(Container inventory) { ++ super.slotsChanged(inventory); ++ if (inventory == this.repairSlots) { + this.createResult(); + } + +@@ -151,7 +173,7 @@ + boolean flag2 = !itemstack.isEmpty() && !itemstack.is(Items.ENCHANTED_BOOK) && !itemstack.isEnchanted() || !itemstack1.isEmpty() && !itemstack1.is(Items.ENCHANTED_BOOK) && !itemstack1.isEnchanted(); + + if (itemstack.getCount() > 1 || itemstack1.getCount() > 1 || !flag1 && flag2) { +- this.resultSlots.setItem(0, ItemStack.EMPTY); ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareGrindstoneEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit + this.broadcastChanges(); + return; + } +@@ -162,7 +184,7 @@ + + if (flag1) { + if (!itemstack.is(itemstack1.getItem())) { +- this.resultSlots.setItem(0, ItemStack.EMPTY); ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareGrindstoneEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit + this.broadcastChanges(); + return; + } +@@ -176,7 +198,7 @@ + itemstack2 = this.mergeEnchants(itemstack, itemstack1); + if (!itemstack2.isDamageableItem()) { + if (!ItemStack.matches(itemstack, itemstack1)) { +- this.resultSlots.setItem(0, ItemStack.EMPTY); ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareGrindstoneEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit + this.broadcastChanges(); + return; + } +@@ -189,18 +211,18 @@ + i = flag3 ? itemstack.getDamageValue() : itemstack1.getDamageValue(); + itemstack2 = flag3 ? itemstack : itemstack1; + } +- +- this.resultSlots.setItem(0, this.removeNonCurses(itemstack2, i, b0)); ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareGrindstoneEvent(getBukkitView(), this.removeNonCurses(itemstack2, i, b0)); // CraftBukkit + } else { +- this.resultSlots.setItem(0, ItemStack.EMPTY); ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareGrindstoneEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit + } + ++ sendAllDataToRemote(); // CraftBukkit - SPIGOT-6686: Always send completed inventory to stay in sync with client + this.broadcastChanges(); + } + +- private ItemStack mergeEnchants(ItemStack itemstack, ItemStack itemstack1) { +- ItemStack itemstack2 = itemstack.copy(); +- Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(itemstack1); ++ private ItemStack mergeEnchants(ItemStack copyTo, ItemStack copyFrom) { ++ ItemStack itemstack2 = copyTo.copy(); ++ Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(copyFrom); + Iterator iterator = map.entrySet().iterator(); + + while (iterator.hasNext()) { +@@ -215,18 +237,18 @@ + return itemstack2; + } + +- private ItemStack removeNonCurses(ItemStack itemstack, int i, int j) { +- ItemStack itemstack1 = itemstack.copyWithCount(j); ++ private ItemStack removeNonCurses(ItemStack stack, int damage, int count) { ++ ItemStack itemstack1 = stack.copyWithCount(count); + + itemstack1.removeTagKey("Enchantments"); + itemstack1.removeTagKey("StoredEnchantments"); +- if (i > 0) { +- itemstack1.setDamageValue(i); ++ if (damage > 0) { ++ itemstack1.setDamageValue(damage); + } else { + itemstack1.removeTagKey("Damage"); + } + +- Map<Enchantment, Integer> map = (Map) EnchantmentHelper.getEnchantments(itemstack).entrySet().stream().filter((entry) -> { ++ Map<Enchantment, Integer> map = (Map) EnchantmentHelper.getEnchantments(stack).entrySet().stream().filter((entry) -> { + return ((Enchantment) entry.getKey()).isCurse(); + }).collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + +@@ -234,8 +256,8 @@ + itemstack1.setRepairCost(0); + if (itemstack1.is(Items.ENCHANTED_BOOK) && map.size() == 0) { + itemstack1 = new ItemStack(Items.BOOK); +- if (itemstack.hasCustomHoverName()) { +- itemstack1.setHoverName(itemstack.getHoverName()); ++ if (stack.hasCustomHoverName()) { ++ itemstack1.setHoverName(stack.getHoverName()); + } + } + +@@ -247,25 +269,23 @@ + } + + @Override +- @Override +- public void removed(Player player) { ++ public void removed(net.minecraft.world.entity.player.Player player) { + super.removed(player); +- this.access.execute((level, blockpos) -> { ++ this.access.execute((world, blockposition) -> { + this.clearContainer(player, this.repairSlots); + }); + } + + @Override +- @Override +- public boolean stillValid(Player player) { ++ public boolean stillValid(net.minecraft.world.entity.player.Player player) { ++ if (!this.checkReachable) return true; // CraftBukkit + return stillValid(this.access, player, Blocks.GRINDSTONE); + } + + @Override +- @Override +- public ItemStack quickMoveStack(Player player, int i) { ++ public ItemStack quickMoveStack(net.minecraft.world.entity.player.Player player, int index) { + ItemStack itemstack = ItemStack.EMPTY; +- Slot slot = (Slot) this.slots.get(i); ++ Slot slot = (Slot) this.slots.get(index); + + if (slot != null && slot.hasItem()) { + ItemStack itemstack1 = slot.getItem(); +@@ -274,19 +294,19 @@ + ItemStack itemstack2 = this.repairSlots.getItem(0); + ItemStack itemstack3 = this.repairSlots.getItem(1); + +- if (i == 2) { ++ if (index == 2) { + if (!this.moveItemStackTo(itemstack1, 3, 39, true)) { + return ItemStack.EMPTY; + } + + slot.onQuickCraft(itemstack1, itemstack); +- } else if (i != 0 && i != 1) { ++ } else if (index != 0 && index != 1) { + if (!itemstack2.isEmpty() && !itemstack3.isEmpty()) { +- if (i >= 3 && i < 30) { ++ if (index >= 3 && index < 30) { + if (!this.moveItemStackTo(itemstack1, 30, 39, false)) { + return ItemStack.EMPTY; + } +- } else if (i >= 30 && i < 39 && !this.moveItemStackTo(itemstack1, 3, 30, false)) { ++ } else if (index >= 30 && index < 39 && !this.moveItemStackTo(itemstack1, 3, 30, false)) { + return ItemStack.EMPTY; + } + } else if (!this.moveItemStackTo(itemstack1, 0, 2, false)) { |