aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower/net/minecraft/world/inventory/AnvilMenu.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-spigotflower/net/minecraft/world/inventory/AnvilMenu.java.patch')
-rw-r--r--patch-remap/mache-spigotflower/net/minecraft/world/inventory/AnvilMenu.java.patch240
1 files changed, 240 insertions, 0 deletions
diff --git a/patch-remap/mache-spigotflower/net/minecraft/world/inventory/AnvilMenu.java.patch b/patch-remap/mache-spigotflower/net/minecraft/world/inventory/AnvilMenu.java.patch
new file mode 100644
index 0000000000..32ada24941
--- /dev/null
+++ b/patch-remap/mache-spigotflower/net/minecraft/world/inventory/AnvilMenu.java.patch
@@ -0,0 +1,240 @@
+--- a/net/minecraft/world/inventory/AnvilMenu.java
++++ b/net/minecraft/world/inventory/AnvilMenu.java
+@@ -16,9 +16,13 @@
+ import net.minecraft.world.item.enchantment.Enchantment;
+ import net.minecraft.world.item.enchantment.EnchantmentHelper;
+ import net.minecraft.world.level.block.AnvilBlock;
+-import net.minecraft.world.level.block.state.BlockState;
++import net.minecraft.world.level.block.state.IBlockData;
+ import org.slf4j.Logger;
+
++// CraftBukkit start
++import org.bukkit.craftbukkit.inventory.CraftInventoryView;
++// CraftBukkit end
++
+ public class AnvilMenu extends ItemCombinerMenu {
+
+ public static final int INPUT_SLOT = 0;
+@@ -27,10 +31,10 @@
+ private static final Logger LOGGER = LogUtils.getLogger();
+ private static final boolean DEBUG_COST = false;
+ public static final int MAX_NAME_LENGTH = 50;
+- private int repairItemCountCost;
++ public int repairItemCountCost;
+ @Nullable
+- private String itemName;
+- private final DataSlot cost;
++ public String itemName;
++ public final DataSlot cost;
+ private static final int COST_FAIL = 0;
+ private static final int COST_BASE = 1;
+ private static final int COST_ADDED_BASE = 1;
+@@ -42,19 +46,23 @@
+ private static final int ADDITIONAL_SLOT_X_PLACEMENT = 76;
+ private static final int RESULT_SLOT_X_PLACEMENT = 134;
+ private static final int SLOT_Y_PLACEMENT = 47;
++ // CraftBukkit start
++ public static final int DEFAULT_DENIED_COST = -1;
++ public int maximumRepairCost = 40;
++ private CraftInventoryView bukkitEntity;
++ // CraftBukkit end
+
+- public AnvilMenu(int i, Inventory inventory) {
+- this(i, inventory, ContainerLevelAccess.NULL);
++ public AnvilMenu(int containerId, Inventory playerInventory) {
++ this(containerId, playerInventory, ContainerLevelAccess.NULL);
+ }
+
+- public AnvilMenu(int i, Inventory inventory, ContainerLevelAccess containerlevelaccess) {
+- super(MenuType.ANVIL, i, inventory, containerlevelaccess);
++ public AnvilMenu(int containerId, Inventory playerInventory, ContainerLevelAccess access) {
++ super(MenuType.ANVIL, containerId, playerInventory, access);
+ this.cost = DataSlot.standalone();
+ this.addDataSlot(this.cost);
+ }
+
+ @Override
+- @Override
+ protected ItemCombinerMenuSlotDefinition createInputSlotDefinitions() {
+ return ItemCombinerMenuSlotDefinition.create().withSlot(0, 27, 47, (itemstack) -> {
+ return true;
+@@ -64,20 +72,17 @@
+ }
+
+ @Override
+- @Override
+- protected boolean isValidBlock(BlockState blockstate) {
+- return blockstate.is(BlockTags.ANVIL);
++ protected boolean isValidBlock(IBlockData state) {
++ return state.is(BlockTags.ANVIL);
+ }
+
+ @Override
+- @Override
+- protected boolean mayPickup(Player player, boolean flag) {
+- return (player.getAbilities().instabuild || player.experienceLevel >= this.cost.get()) && this.cost.get() > 0;
++ protected boolean mayPickup(Player player, boolean hasStack) {
++ return (player.getAbilities().instabuild || player.experienceLevel >= this.cost.get()) && this.cost.get() > AnvilMenu.DEFAULT_DENIED_COST && hasStack; // CraftBukkit - allow cost 0 like a free item
+ }
+
+ @Override
+- @Override
+- protected void onTake(Player player, ItemStack itemstack) {
++ protected void onTake(Player player, ItemStack stack) {
+ if (!player.getAbilities().instabuild) {
+ player.giveExperienceLevels(-this.cost.get());
+ }
+@@ -96,29 +101,28 @@
+ this.inputSlots.setItem(1, ItemStack.EMPTY);
+ }
+
+- this.cost.set(0);
+- this.access.execute((level, blockpos) -> {
+- BlockState blockstate = level.getBlockState(blockpos);
++ this.cost.set(DEFAULT_DENIED_COST); // CraftBukkit - use a variable for set a cost for denied item
++ this.access.execute((world, blockposition) -> {
++ IBlockData iblockdata = world.getBlockState(blockposition);
+
+- if (!player.getAbilities().instabuild && blockstate.is(BlockTags.ANVIL) && player.getRandom().nextFloat() < 0.12F) {
+- BlockState blockstate1 = AnvilBlock.damage(blockstate);
++ if (!player.getAbilities().instabuild && iblockdata.is(BlockTags.ANVIL) && player.getRandom().nextFloat() < 0.12F) {
++ IBlockData iblockdata1 = AnvilBlock.damage(iblockdata);
+
+- if (blockstate1 == null) {
+- level.removeBlock(blockpos, false);
+- level.levelEvent(1029, blockpos, 0);
++ if (iblockdata1 == null) {
++ world.removeBlock(blockposition, false);
++ world.levelEvent(1029, blockposition, 0);
+ } else {
+- level.setBlock(blockpos, blockstate1, 2);
+- level.levelEvent(1030, blockpos, 0);
++ world.setBlock(blockposition, iblockdata1, 2);
++ world.levelEvent(1030, blockposition, 0);
+ }
+ } else {
+- level.levelEvent(1030, blockpos, 0);
++ world.levelEvent(1030, blockposition, 0);
+ }
+
+ });
+ }
+
+ @Override
+- @Override
+ public void createResult() {
+ ItemStack itemstack = this.inputSlots.getItem(0);
+
+@@ -128,8 +132,8 @@
+ byte b1 = 0;
+
+ if (itemstack.isEmpty()) {
+- this.resultSlots.setItem(0, ItemStack.EMPTY);
+- this.cost.set(0);
++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit
++ this.cost.set(DEFAULT_DENIED_COST); // CraftBukkit - use a variable for set a cost for denied item
+ } else {
+ ItemStack itemstack1 = itemstack.copy();
+ ItemStack itemstack2 = this.inputSlots.getItem(1);
+@@ -146,8 +150,8 @@
+ if (itemstack1.isDamageableItem() && itemstack1.getItem().isValidRepairItem(itemstack, itemstack2)) {
+ k = Math.min(itemstack1.getDamageValue(), itemstack1.getMaxDamage() / 4);
+ if (k <= 0) {
+- this.resultSlots.setItem(0, ItemStack.EMPTY);
+- this.cost.set(0);
++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit
++ this.cost.set(DEFAULT_DENIED_COST); // CraftBukkit - use a variable for set a cost for denied item
+ return;
+ }
+
+@@ -161,8 +165,8 @@
+ this.repairItemCountCost = i1;
+ } else {
+ if (!flag && (!itemstack1.is(itemstack2.getItem()) || !itemstack1.isDamageableItem())) {
+- this.resultSlots.setItem(0, ItemStack.EMPTY);
+- this.cost.set(0);
++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit
++ this.cost.set(DEFAULT_DENIED_COST); // CraftBukkit - use a variable for set a cost for denied item
+ return;
+ }
+
+@@ -251,8 +255,8 @@
+ }
+
+ if (flag2 && !flag1) {
+- this.resultSlots.setItem(0, ItemStack.EMPTY);
+- this.cost.set(0);
++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit
++ this.cost.set(DEFAULT_DENIED_COST); // CraftBukkit - use a variable for set a cost for denied item
+ return;
+ }
+ }
+@@ -275,11 +279,11 @@
+ itemstack1 = ItemStack.EMPTY;
+ }
+
+- if (b1 == i && b1 > 0 && this.cost.get() >= 40) {
+- this.cost.set(39);
++ if (b1 == i && b1 > 0 && this.cost.get() >= maximumRepairCost) { // CraftBukkit
++ this.cost.set(maximumRepairCost - 1); // CraftBukkit
+ }
+
+- if (this.cost.get() >= 40 && !this.player.getAbilities().instabuild) {
++ if (this.cost.get() >= maximumRepairCost && !this.player.getAbilities().instabuild) { // CraftBukkit
+ itemstack1 = ItemStack.EMPTY;
+ }
+
+@@ -298,17 +302,18 @@
+ EnchantmentHelper.setEnchantments(map, itemstack1);
+ }
+
+- this.resultSlots.setItem(0, itemstack1);
++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1); // CraftBukkit
++ sendAllDataToRemote(); // CraftBukkit - SPIGOT-6686: Always send completed inventory to stay in sync with client
+ this.broadcastChanges();
+ }
+ }
+
+- public static int calculateIncreasedRepairCost(int i) {
+- return i * 2 + 1;
++ public static int calculateIncreasedRepairCost(int oldRepairCost) {
++ return oldRepairCost * 2 + 1;
+ }
+
+- public boolean setItemName(String s) {
+- String s1 = validateName(s);
++ public boolean setItemName(String itemName) {
++ String s1 = validateName(itemName);
+
+ if (s1 != null && !s1.equals(this.itemName)) {
+ this.itemName = s1;
+@@ -330,8 +335,8 @@
+ }
+
+ @Nullable
+- private static String validateName(String s) {
+- String s1 = SharedConstants.filterText(s);
++ private static String validateName(String itemName) {
++ String s1 = SharedConstants.filterText(itemName);
+
+ return s1.length() <= 50 ? s1 : null;
+ }
+@@ -339,4 +344,18 @@
+ public int getCost() {
+ return this.cost.get();
+ }
++
++ // CraftBukkit start
++ @Override
++ public CraftInventoryView getBukkitView() {
++ if (bukkitEntity != null) {
++ return bukkitEntity;
++ }
++
++ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryAnvil(
++ access.getLocation(), this.inputSlots, this.resultSlots, this);
++ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this);
++ return bukkitEntity;
++ }
++ // CraftBukkit end
+ }