2021-03-16 09:00:00 +11:00
|
|
|
--- a/net/minecraft/world/inventory/ContainerAnvil.java
|
|
|
|
+++ b/net/minecraft/world/inventory/ContainerAnvil.java
|
2024-04-24 01:15:00 +10:00
|
|
|
@@ -21,6 +21,10 @@
|
2023-06-08 01:30:00 +10:00
|
|
|
import net.minecraft.world.level.block.state.IBlockData;
|
2022-03-01 02:00:00 +11:00
|
|
|
import org.slf4j.Logger;
|
2014-11-26 08:32:16 +11:00
|
|
|
|
2016-11-17 12:41:03 +11:00
|
|
|
+// CraftBukkit start
|
2016-03-01 08:32:46 +11:00
|
|
|
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
|
|
|
+// CraftBukkit end
|
2014-11-26 08:32:16 +11:00
|
|
|
+
|
2020-06-25 10:00:00 +10:00
|
|
|
public class ContainerAnvil extends ContainerAnvilAbstract {
|
2014-11-26 08:32:16 +11:00
|
|
|
|
2023-03-15 03:30:00 +11:00
|
|
|
public static final int INPUT_SLOT = 0;
|
2024-04-24 01:15:00 +10:00
|
|
|
@@ -44,6 +48,11 @@
|
2023-03-15 03:30:00 +11:00
|
|
|
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;
|
2014-11-26 08:32:16 +11:00
|
|
|
+ // CraftBukkit start
|
2022-04-09 09:42:11 +10:00
|
|
|
+ public static final int DEFAULT_DENIED_COST = -1;
|
2018-10-05 21:48:54 -04:00
|
|
|
+ public int maximumRepairCost = 40;
|
2016-11-17 12:41:03 +11:00
|
|
|
+ private CraftInventoryView bukkitEntity;
|
2015-02-26 22:41:06 +00:00
|
|
|
+ // CraftBukkit end
|
2014-11-26 08:32:16 +11:00
|
|
|
|
2019-04-23 12:00:00 +10:00
|
|
|
public ContainerAnvil(int i, PlayerInventory playerinventory) {
|
2021-06-11 15:00:00 +10:00
|
|
|
this(i, playerinventory, ContainerAccess.NULL);
|
2024-04-24 01:15:00 +10:00
|
|
|
@@ -71,7 +80,7 @@
|
2022-04-09 09:42:11 +10:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean mayPickup(EntityHuman entityhuman, boolean flag) {
|
2024-04-24 01:15:00 +10:00
|
|
|
- return (entityhuman.hasInfiniteMaterials() || entityhuman.experienceLevel >= this.cost.get()) && this.cost.get() > 0;
|
|
|
|
+ return (entityhuman.hasInfiniteMaterials() || entityhuman.experienceLevel >= this.cost.get()) && this.cost.get() > ContainerAnvil.DEFAULT_DENIED_COST && flag; // CraftBukkit - allow cost 0 like a free item
|
2022-04-09 09:42:11 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-04-24 01:15:00 +10:00
|
|
|
@@ -94,7 +103,7 @@
|
2022-04-09 09:42:11 +10:00
|
|
|
this.inputSlots.setItem(1, ItemStack.EMPTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
- this.cost.set(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);
|
|
|
|
|
2023-06-08 01:30:00 +10:00
|
|
|
@@ -141,8 +150,8 @@
|
2021-11-22 09:00:00 +11:00
|
|
|
if (itemstack1.isDamageableItem() && itemstack1.getItem().isValidRepairItem(itemstack, itemstack2)) {
|
|
|
|
k = Math.min(itemstack1.getDamageValue(), itemstack1.getMaxDamage() / 4);
|
2016-03-01 08:32:46 +11:00
|
|
|
if (k <= 0) {
|
2021-06-11 15:00:00 +10:00
|
|
|
- this.resultSlots.setItem(0, ItemStack.EMPTY);
|
2022-04-09 09:42:11 +10:00
|
|
|
- this.cost.set(0);
|
2021-06-11 15:00:00 +10:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit
|
2022-04-09 09:42:11 +10:00
|
|
|
+ this.cost.set(DEFAULT_DENIED_COST); // CraftBukkit - use a variable for set a cost for denied item
|
2016-03-01 08:32:46 +11:00
|
|
|
return;
|
|
|
|
}
|
2022-04-09 09:42:11 +10:00
|
|
|
|
2023-06-08 01:30:00 +10:00
|
|
|
@@ -156,8 +165,8 @@
|
2021-06-11 15:00:00 +10:00
|
|
|
this.repairItemCountCost = i1;
|
2016-03-01 08:32:46 +11:00
|
|
|
} else {
|
2021-11-22 09:00:00 +11:00
|
|
|
if (!flag && (!itemstack1.is(itemstack2.getItem()) || !itemstack1.isDamageableItem())) {
|
2021-06-11 15:00:00 +10:00
|
|
|
- this.resultSlots.setItem(0, ItemStack.EMPTY);
|
2022-04-09 09:42:11 +10:00
|
|
|
- this.cost.set(0);
|
2021-06-11 15:00:00 +10:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit
|
2022-04-09 09:42:11 +10:00
|
|
|
+ this.cost.set(DEFAULT_DENIED_COST); // CraftBukkit - use a variable for set a cost for denied item
|
2017-03-25 09:51:02 +11:00
|
|
|
return;
|
|
|
|
}
|
2022-04-09 09:42:11 +10:00
|
|
|
|
2024-04-24 01:15:00 +10:00
|
|
|
@@ -231,8 +240,8 @@
|
2017-03-25 09:51:02 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flag2 && !flag1) {
|
2021-06-11 15:00:00 +10:00
|
|
|
- this.resultSlots.setItem(0, ItemStack.EMPTY);
|
2022-04-09 09:42:11 +10:00
|
|
|
- this.cost.set(0);
|
2021-06-11 15:00:00 +10:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit
|
2022-04-09 09:42:11 +10:00
|
|
|
+ this.cost.set(DEFAULT_DENIED_COST); // CraftBukkit - use a variable for set a cost for denied item
|
2016-03-01 08:32:46 +11:00
|
|
|
return;
|
|
|
|
}
|
2022-04-09 09:42:11 +10:00
|
|
|
}
|
2024-04-24 01:15:00 +10:00
|
|
|
@@ -257,11 +266,11 @@
|
2021-06-11 15:00:00 +10:00
|
|
|
itemstack1 = ItemStack.EMPTY;
|
2018-10-05 21:48:54 -04:00
|
|
|
}
|
|
|
|
|
2024-04-24 01:15:00 +10:00
|
|
|
- if (b0 == i && b0 > 0 && this.cost.get() >= 40) {
|
2021-06-11 15:00:00 +10:00
|
|
|
- this.cost.set(39);
|
2024-04-24 01:15:00 +10:00
|
|
|
+ if (b0 == i && b0 > 0 && this.cost.get() >= maximumRepairCost) { // CraftBukkit
|
2021-06-11 15:00:00 +10:00
|
|
|
+ this.cost.set(maximumRepairCost - 1); // CraftBukkit
|
2018-10-05 21:48:54 -04:00
|
|
|
}
|
|
|
|
|
2021-06-11 15:00:00 +10:00
|
|
|
- if (this.cost.get() >= 40 && !this.player.getAbilities().instabuild) {
|
|
|
|
+ if (this.cost.get() >= maximumRepairCost && !this.player.getAbilities().instabuild) { // CraftBukkit
|
|
|
|
itemstack1 = ItemStack.EMPTY;
|
2018-10-05 21:48:54 -04:00
|
|
|
}
|
|
|
|
|
2024-04-24 01:15:00 +10:00
|
|
|
@@ -279,11 +288,12 @@
|
|
|
|
EnchantmentManager.setEnchantments(itemstack1, itemenchantments_a.toImmutable());
|
2016-03-01 08:32:46 +11:00
|
|
|
}
|
|
|
|
|
2021-06-11 15:00:00 +10:00
|
|
|
- this.resultSlots.setItem(0, itemstack1);
|
2016-03-01 08:32:46 +11:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1); // CraftBukkit
|
2021-11-22 09:00:00 +11:00
|
|
|
+ sendAllDataToRemote(); // CraftBukkit - SPIGOT-6686: Always send completed inventory to stay in sync with client
|
|
|
|
this.broadcastChanges();
|
2024-04-24 01:15:00 +10:00
|
|
|
} else {
|
|
|
|
- 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
|
2016-03-01 08:32:46 +11:00
|
|
|
}
|
|
|
|
}
|
2024-04-24 01:15:00 +10:00
|
|
|
|
|
|
|
@@ -323,4 +333,18 @@
|
2021-11-22 09:00:00 +11:00
|
|
|
public int getCost() {
|
2021-06-11 15:00:00 +10:00
|
|
|
return this.cost.get();
|
2014-11-26 08:32:16 +11:00
|
|
|
}
|
2016-11-17 12:41:03 +11:00
|
|
|
+
|
2014-11-26 08:32:16 +11:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ @Override
|
|
|
|
+ public CraftInventoryView getBukkitView() {
|
|
|
|
+ if (bukkitEntity != null) {
|
|
|
|
+ return bukkitEntity;
|
|
|
|
+ }
|
|
|
|
+
|
2016-03-01 08:32:46 +11:00
|
|
|
+ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryAnvil(
|
2021-06-11 15:00:00 +10:00
|
|
|
+ access.getLocation(), this.inputSlots, this.resultSlots, this);
|
2018-12-13 11:00:00 +11:00
|
|
|
+ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this);
|
2014-11-26 08:32:16 +11:00
|
|
|
+ return bukkitEntity;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2016-11-17 12:41:03 +11:00
|
|
|
}
|