aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/inventory/AnvilMenu.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/inventory/AnvilMenu.java.patch')
-rw-r--r--patch-remap/mache-vineflower/net/minecraft/world/inventory/AnvilMenu.java.patch470
1 files changed, 470 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/inventory/AnvilMenu.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/inventory/AnvilMenu.java.patch
new file mode 100644
index 0000000000..4bf0394d19
--- /dev/null
+++ b/patch-remap/mache-vineflower/net/minecraft/world/inventory/AnvilMenu.java.patch
@@ -0,0 +1,470 @@
+--- a/net/minecraft/world/inventory/AnvilMenu.java
++++ b/net/minecraft/world/inventory/AnvilMenu.java
+@@ -1,11 +1,11 @@
+ package net.minecraft.world.inventory;
+
+ import com.mojang.logging.LogUtils;
++import java.util.Iterator;
+ import java.util.Map;
+ import javax.annotation.Nullable;
+ import net.minecraft.SharedConstants;
+ import net.minecraft.Util;
+-import net.minecraft.core.BlockPos;
+ import net.minecraft.network.chat.Component;
+ import net.minecraft.tags.BlockTags;
+ import net.minecraft.world.entity.player.Inventory;
+@@ -15,22 +15,26 @@
+ import net.minecraft.world.item.Items;
+ import net.minecraft.world.item.enchantment.Enchantment;
+ import net.minecraft.world.item.enchantment.EnchantmentHelper;
+-import net.minecraft.world.level.Level;
+ 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;
+ public static final int ADDITIONAL_SLOT = 1;
+ public static final int RESULT_SLOT = 2;
+ 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 = DataSlot.standalone();
++ 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,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);
+@@ -49,26 +58,27 @@
+
+ public AnvilMenu(int containerId, Inventory playerInventory, ContainerLevelAccess access) {
+ super(MenuType.ANVIL, containerId, playerInventory, access);
++ this.cost = DataSlot.standalone();
+ this.addDataSlot(this.cost);
+ }
+
+ @Override
+ protected ItemCombinerMenuSlotDefinition createInputSlotDefinitions() {
+- return ItemCombinerMenuSlotDefinition.create()
+- .withSlot(0, 27, 47, itemStack -> true)
+- .withSlot(1, 76, 47, itemStack -> true)
+- .withResultSlot(2, 134, 47)
+- .build();
++ return ItemCombinerMenuSlotDefinition.create().withSlot(0, 27, 47, (itemstack) -> {
++ return true;
++ }).withSlot(1, 76, 47, (itemstack) -> {
++ return true;
++ }).withResultSlot(2, 134, 47).build();
+ }
+
+ @Override
+- protected boolean isValidBlock(BlockState state) {
++ protected boolean isValidBlock(IBlockData state) {
+ return state.is(BlockTags.ANVIL);
+ }
+
+ @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
+@@ -79,10 +89,11 @@
+
+ this.inputSlots.setItem(0, ItemStack.EMPTY);
+ if (this.repairItemCountCost > 0) {
+- ItemStack item = this.inputSlots.getItem(1);
+- if (!item.isEmpty() && item.getCount() > this.repairItemCountCost) {
+- item.shrink(this.repairItemCountCost);
+- this.inputSlots.setItem(1, item);
++ ItemStack itemstack1 = this.inputSlots.getItem(1);
++
++ if (!itemstack1.isEmpty() && itemstack1.getCount() > this.repairItemCountCost) {
++ itemstack1.shrink(this.repairItemCountCost);
++ this.inputSlots.setItem(1, itemstack1);
+ } else {
+ this.inputSlots.setItem(1, ItemStack.EMPTY);
+ }
+@@ -90,133 +101,153 @@
+ 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);
++ world.setBlock(blockposition, iblockdata1, 2);
++ world.levelEvent(1030, blockposition, 0);
+ }
+ } else {
+- level.levelEvent(1030, blockPos, 0);
++ world.levelEvent(1030, blockposition, 0);
+ }
++
+ });
+ }
+
+ @Override
+ public void createResult() {
+- ItemStack item = this.inputSlots.getItem(0);
++ ItemStack itemstack = 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());
++ ItemStack itemstack1 = itemstack.copy();
++ ItemStack itemstack2 = this.inputSlots.getItem(1);
++ Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(itemstack1);
++ int j = b0 + itemstack.getBaseRepairCost() + (itemstack2.isEmpty() ? 0 : itemstack2.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;
+ }
+
+- int i3;
+- for (i3 = 0; min > 0 && i3 < item1.getCount(); i3++) {
+- int i4 = itemStack.getDamageValue() - min;
+- itemStack.setDamageValue(i4);
+- i++;
+- min = Math.min(itemStack.getDamageValue(), itemStack.getMaxDamage() / 4);
++ for (i1 = 0; k > 0 && i1 < itemstack2.getCount(); ++i1) {
++ l = itemstack1.getDamageValue() - k;
++ itemstack1.setDamageValue(l);
++ ++i;
++ k = Math.min(itemstack1.getDamageValue(), itemstack1.getMaxDamage() / 4);
+ }
+
+- this.repairItemCountCost = i3;
++ this.repairItemCountCost = i1;
+ } 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;
+ }
+
+- if (itemStack.isDamageableItem() && !flag) {
+- int minx = item.getMaxDamage() - item.getDamageValue();
+- int i3 = item1.getMaxDamage() - item1.getDamageValue();
+- int i4 = i3 + itemStack.getMaxDamage() * 12 / 100;
+- int i5 = minx + i4;
+- int i6 = itemStack.getMaxDamage() - i5;
+- if (i6 < 0) {
+- i6 = 0;
++ if (itemstack1.isDamageableItem() && !flag) {
++ k = itemstack.getMaxDamage() - itemstack.getDamageValue();
++ i1 = itemstack2.getMaxDamage() - itemstack2.getDamageValue();
++ l = i1 + itemstack1.getMaxDamage() * 12 / 100;
++ int j1 = k + l;
++ int k1 = itemstack1.getMaxDamage() - j1;
++
++ if (k1 < 0) {
++ k1 = 0;
+ }
+
+- if (i6 < itemStack.getDamageValue()) {
+- itemStack.setDamageValue(i6);
++ if (k1 < itemstack1.getDamageValue()) {
++ itemstack1.setDamageValue(k1);
+ i += 2;
+ }
+ }
+
+- Map<Enchantment, Integer> enchantments1 = EnchantmentHelper.getEnchantments(item1);
++ Map<Enchantment, Integer> map1 = EnchantmentHelper.getEnchantments(itemstack2);
+ boolean flag1 = false;
+ boolean flag2 = false;
++ Iterator iterator = map1.keySet().iterator();
+
+- for (Enchantment enchantment : enchantments1.keySet()) {
++ while (iterator.hasNext()) {
++ Enchantment enchantment = (Enchantment) iterator.next();
++
+ if (enchantment != null) {
+- int i7 = enchantments.getOrDefault(enchantment, 0);
+- int i8 = enchantments1.get(enchantment);
+- int var29 = i7 == i8 ? i8 + 1 : Math.max(i8, i7);
+- boolean canEnchant = enchantment.canEnchant(item);
+- if (this.player.getAbilities().instabuild || item.is(Items.ENCHANTED_BOOK)) {
+- canEnchant = true;
++ int l1 = (Integer) map.getOrDefault(enchantment, 0);
++ int i2 = (Integer) map1.get(enchantment);
++
++ i2 = l1 == i2 ? i2 + 1 : Math.max(i2, l1);
++ boolean flag3 = enchantment.canEnchant(itemstack);
++
++ if (this.player.getAbilities().instabuild || itemstack.is(Items.ENCHANTED_BOOK)) {
++ flag3 = true;
+ }
+
+- for (Enchantment enchantment1 : enchantments.keySet()) {
++ Iterator iterator1 = map.keySet().iterator();
++
++ while (iterator1.hasNext()) {
++ Enchantment enchantment1 = (Enchantment) iterator1.next();
++
+ if (enchantment1 != enchantment && !enchantment.isCompatibleWith(enchantment1)) {
+- canEnchant = false;
+- i++;
++ flag3 = false;
++ ++i;
+ }
+ }
+
+- if (!canEnchant) {
++ if (!flag3) {
+ flag2 = true;
+ } else {
+ flag1 = true;
+- if (var29 > enchantment.getMaxLevel()) {
+- var29 = enchantment.getMaxLevel();
++ if (i2 > enchantment.getMaxLevel()) {
++ i2 = enchantment.getMaxLevel();
+ }
+
+- enchantments.put(enchantment, var29);
+- int i9 = 0;
++ map.put(enchantment, i2);
++ int j2 = 0;
++
+ switch (enchantment.getRarity()) {
+ case COMMON:
+- i9 = 1;
++ j2 = 1;
+ break;
+ case UNCOMMON:
+- i9 = 2;
++ j2 = 2;
+ break;
+ case RARE:
+- i9 = 4;
++ j2 = 4;
+ break;
+ case VERY_RARE:
+- i9 = 8;
++ j2 = 8;
+ }
+
+ if (flag) {
+- i9 = Math.max(1, i9 / 2);
++ j2 = Math.max(1, j2 / 2);
+ }
+
+- i += i9 * var29;
+- if (item.getCount() > 1) {
++ i += j2 * i2;
++ if (itemstack.getCount() > 1) {
+ i = 40;
+ }
+ }
+@@ -224,53 +255,55 @@
+ }
+
+ 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;
+ }
+ }
+ }
+
+ if (this.itemName != null && !Util.isBlank(this.itemName)) {
+- if (!this.itemName.equals(item.getHoverName().getString())) {
+- i2 = 1;
+- i += i2;
+- itemStack.setHoverName(Component.literal(this.itemName));
++ if (!this.itemName.equals(itemstack.getHoverName().getString())) {
++ b1 = 1;
++ i += b1;
++ itemstack1.setHoverName(Component.literal(this.itemName));
+ }
+- } else if (item.hasCustomHoverName()) {
+- i2 = 1;
+- i += i2;
+- itemStack.resetHoverName();
++ } else if (itemstack.hasCustomHoverName()) {
++ b1 = 1;
++ i += b1;
++ itemstack1.resetHoverName();
+ }
+
+- this.cost.set(var19 + i);
++ this.cost.set(j + i);
+ if (i <= 0) {
+- itemStack = ItemStack.EMPTY;
++ itemstack1 = 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()) {
+- int baseRepairCost = itemStack.getBaseRepairCost();
+- if (!item1.isEmpty() && baseRepairCost < item1.getBaseRepairCost()) {
+- baseRepairCost = item1.getBaseRepairCost();
++ if (!itemstack1.isEmpty()) {
++ int k2 = itemstack1.getBaseRepairCost();
++
++ if (!itemstack2.isEmpty() && k2 < itemstack2.getBaseRepairCost()) {
++ k2 = itemstack2.getBaseRepairCost();
+ }
+
+- if (i2 != i || i2 == 0) {
+- baseRepairCost = calculateIncreasedRepairCost(baseRepairCost);
++ if (b1 != i || b1 == 0) {
++ k2 = calculateIncreasedRepairCost(k2);
+ }
+
+- itemStack.setRepairCost(baseRepairCost);
+- EnchantmentHelper.setEnchantments(enchantments, itemStack);
++ itemstack1.setRepairCost(k2);
++ EnchantmentHelper.setEnchantments(map, itemstack1);
+ }
+
+- 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();
+ }
+ }
+@@ -280,15 +313,17 @@
+ }
+
+ public boolean setItemName(String itemName) {
+- String string = validateName(itemName);
+- if (string != null && !string.equals(this.itemName)) {
+- this.itemName = string;
++ String s1 = validateName(itemName);
++
++ if (s1 != null && !s1.equals(this.itemName)) {
++ this.itemName = s1;
+ if (this.getSlot(2).hasItem()) {
+- ItemStack item = this.getSlot(2).getItem();
+- if (Util.isBlank(string)) {
+- item.resetHoverName();
++ ItemStack itemstack = this.getSlot(2).getItem();
++
++ if (Util.isBlank(s1)) {
++ itemstack.resetHoverName();
+ } else {
+- item.setHoverName(Component.literal(string));
++ itemstack.setHoverName(Component.literal(s1));
+ }
+ }
+
+@@ -301,11 +336,26 @@
+
+ @Nullable
+ private static String validateName(String itemName) {
+- String string = SharedConstants.filterText(itemName);
+- return string.length() <= 50 ? string : null;
++ String s1 = SharedConstants.filterText(itemName);
++
++ return s1.length() <= 50 ? s1 : null;
+ }
+
+ 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
+ }