diff options
Diffstat (limited to 'patch-remap/mache-vineflower-stripped/net/minecraft/world/inventory/AnvilMenu.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower-stripped/net/minecraft/world/inventory/AnvilMenu.java.patch | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower-stripped/net/minecraft/world/inventory/AnvilMenu.java.patch b/patch-remap/mache-vineflower-stripped/net/minecraft/world/inventory/AnvilMenu.java.patch new file mode 100644 index 0000000000..85a10c1c6c --- /dev/null +++ b/patch-remap/mache-vineflower-stripped/net/minecraft/world/inventory/AnvilMenu.java.patch @@ -0,0 +1,171 @@ +--- a/net/minecraft/world/inventory/AnvilMenu.java ++++ b/net/minecraft/world/inventory/AnvilMenu.java +@@ -20,6 +19,10 @@ + import net.minecraft.world.level.block.state.BlockState; + 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; + public static final int ADDITIONAL_SLOT = 1; +@@ -42,6 +46,11 @@ + 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 containerId, Inventory playerInventory) { + this(containerId, playerInventory, ContainerLevelAccess.NULL); +@@ -68,7 +78,7 @@ + + @Override + protected boolean mayPickup(Player player, boolean hasStack) { +- return (player.getAbilities().instabuild || player.experienceLevel >= this.cost.get()) && this.cost.get() > 0; ++ 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 +@@ -90,14 +101,16 @@ + this.inputSlots.setItem(1, ItemStack.EMPTY); + } + +- this.cost.set(0); +- this.access.execute((level, blockPos) -> { +- BlockState blockState = level.getBlockState(blockPos); +- if (!player.getAbilities().instabuild && blockState.is(BlockTags.ANVIL) && player.getRandom().nextFloat() < 0.12F) { +- BlockState blockState1 = AnvilBlock.damage(blockState); +- if (blockState1 == null) { +- level.removeBlock(blockPos, false); +- level.levelEvent(1029, blockPos, 0); ++ 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 && iblockdata.is(BlockTags.ANVIL) && player.getRandom().nextFloat() < 0.12F) { ++ IBlockData iblockdata1 = AnvilBlock.damage(iblockdata); ++ ++ if (iblockdata1 == null) { ++ world.removeBlock(blockposition, false); ++ world.levelEvent(1029, blockposition, 0); + } else { + level.setBlock(blockPos, blockState1, 2); + level.levelEvent(1030, blockPos, 0); +@@ -113,24 +128,29 @@ + ItemStack item = this.inputSlots.getItem(0); + this.cost.set(1); + int i = 0; +- int i1 = 0; +- int i2 = 0; +- if (item.isEmpty()) { +- this.resultSlots.setItem(0, ItemStack.EMPTY); +- this.cost.set(0); ++ byte b0 = 0; ++ byte b1 = 0; ++ ++ if (itemstack.isEmpty()) { ++ 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 itemStack = item.copy(); + ItemStack item1 = this.inputSlots.getItem(1); + Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(itemStack); + int var19 = i1 + item.getBaseRepairCost() + (item1.isEmpty() ? 0 : item1.getBaseRepairCost()); + this.repairItemCountCost = 0; +- if (!item1.isEmpty()) { +- boolean flag = item1.is(Items.ENCHANTED_BOOK) && !EnchantedBookItem.getEnchantments(item1).isEmpty(); +- if (itemStack.isDamageableItem() && itemStack.getItem().isValidRepairItem(item, item1)) { +- int min = Math.min(itemStack.getDamageValue(), itemStack.getMaxDamage() / 4); +- if (min <= 0) { +- this.resultSlots.setItem(0, ItemStack.EMPTY); +- this.cost.set(0); ++ if (!itemstack2.isEmpty()) { ++ boolean flag = itemstack2.is(Items.ENCHANTED_BOOK) && !EnchantedBookItem.getEnchantments(itemstack2).isEmpty(); ++ int k; ++ int l; ++ int i1; ++ ++ if (itemstack1.isDamageableItem() && itemstack1.getItem().isValidRepairItem(itemstack, itemstack2)) { ++ k = Math.min(itemstack1.getDamageValue(), itemstack1.getMaxDamage() / 4); ++ if (k <= 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; + } + +@@ -144,9 +164,9 @@ + + this.repairItemCountCost = i3; + } else { +- if (!flag && (!itemStack.is(item1.getItem()) || !itemStack.isDamageableItem())) { +- this.resultSlots.setItem(0, ItemStack.EMPTY); +- this.cost.set(0); ++ if (!flag && (!itemstack1.is(itemstack2.getItem()) || !itemstack1.isDamageableItem())) { ++ 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; + } + +@@ -224,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; + } + } +@@ -248,12 +279,12 @@ + itemStack = ItemStack.EMPTY; + } + +- if (i2 == i && i2 > 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) { +- itemStack = ItemStack.EMPTY; ++ if (this.cost.get() >= maximumRepairCost && !this.player.getAbilities().instabuild) { // CraftBukkit ++ itemstack1 = ItemStack.EMPTY; + } + + if (!itemStack.isEmpty()) { +@@ -270,7 +302,8 @@ + EnchantmentHelper.setEnchantments(enchantments, itemStack); + } + +- this.resultSlots.setItem(0, itemStack); ++ 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(); + } + } +@@ -308,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 + } |