Paper/nms-patches/ContainerAnvil.patch

122 lines
5.0 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/ContainerAnvil.java
+++ b/net/minecraft/server/ContainerAnvil.java
2016-11-17 02:41:03 +01:00
@@ -6,6 +6,10 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2016-11-17 02:41:03 +01:00
+// CraftBukkit start
2016-02-29 22:32:46 +01:00
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerAnvil extends Container {
2019-04-23 04:00:00 +02:00
private static final Logger c = LogManager.getLogger();
@@ -16,6 +20,12 @@
private int h;
2017-05-14 04:00:00 +02:00
public String renameText;
2018-12-13 01:00:00 +01:00
private final EntityHuman player;
+ // CraftBukkit start
+ public int maximumRepairCost = 40;
+ private int lastLevelCost;
2016-11-17 02:41:03 +01:00
+ private CraftInventoryView bukkitEntity;
2018-12-13 01:00:00 +01:00
+ private PlayerInventory playerInventory;
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
public ContainerAnvil(int i, PlayerInventory playerinventory) {
this(i, playerinventory, ContainerAccess.a);
@@ -23,6 +33,7 @@
public ContainerAnvil(int i, PlayerInventory playerinventory, final ContainerAccess containeraccess) {
super(Containers.ANVIL, i);
2018-12-13 01:00:00 +01:00
+ this.playerInventory = playerinventory; // CraftBukkit
2019-04-23 04:00:00 +02:00
this.resultInventory = new InventoryCraftResult();
this.repairInventory = new InventorySubcontainer(2) {
@Override
@@ -123,7 +134,7 @@
2016-02-29 22:32:46 +01:00
byte b1 = 0;
2016-11-17 02:41:03 +01:00
if (itemstack.isEmpty()) {
2018-12-13 01:00:00 +01:00
- this.resultInventory.setItem(0, ItemStack.a);
2016-11-17 02:41:03 +01:00
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
2019-04-23 04:00:00 +02:00
this.levelCost.a(0);
2016-02-29 22:32:46 +01:00
} else {
ItemStack itemstack1 = itemstack.cloneItemStack();
2019-04-23 04:00:00 +02:00
@@ -141,7 +152,7 @@
2018-07-15 02:00:00 +02:00
if (itemstack1.e() && itemstack1.getItem().a(itemstack, itemstack2)) {
k = Math.min(itemstack1.getDamage(), itemstack1.h() / 4);
2016-02-29 22:32:46 +01:00
if (k <= 0) {
2018-12-13 01:00:00 +01:00
- this.resultInventory.setItem(0, ItemStack.a);
2016-11-17 02:41:03 +01:00
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
2019-04-23 04:00:00 +02:00
this.levelCost.a(0);
2016-02-29 22:32:46 +01:00
return;
}
2019-04-23 04:00:00 +02:00
@@ -156,7 +167,7 @@
this.h = i1;
2016-02-29 22:32:46 +01:00
} else {
2018-07-15 02:00:00 +02:00
if (!flag && (itemstack1.getItem() != itemstack2.getItem() || !itemstack1.e())) {
2018-12-13 01:00:00 +01:00
- this.resultInventory.setItem(0, ItemStack.a);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
2019-04-23 04:00:00 +02:00
this.levelCost.a(0);
return;
}
2019-04-23 04:00:00 +02:00
@@ -246,7 +257,7 @@
}
if (flag2 && !flag1) {
2018-12-13 01:00:00 +01:00
- this.resultInventory.setItem(0, ItemStack.a);
2016-11-17 02:41:03 +01:00
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
2019-04-23 04:00:00 +02:00
this.levelCost.a(0);
2016-02-29 22:32:46 +01:00
return;
}
2019-04-23 04:00:00 +02:00
@@ -270,11 +281,11 @@
itemstack1 = ItemStack.a;
}
2019-04-23 04:00:00 +02:00
- if (b1 == i && b1 > 0 && this.levelCost.b() >= 40) {
- this.levelCost.a(39);
+ if (b1 == i && b1 > 0 && this.levelCost.b() >= maximumRepairCost) { // CraftBukkit
+ this.levelCost.a(maximumRepairCost - 1); // CraftBukkit
}
2019-04-23 04:00:00 +02:00
- if (this.levelCost.b() >= 40 && !this.player.abilities.canInstantlyBuild) {
+ if (this.levelCost.b() >= maximumRepairCost && !this.player.abilities.canInstantlyBuild) { // CraftBukkit
itemstack1 = ItemStack.a;
}
2019-04-23 04:00:00 +02:00
@@ -293,7 +304,7 @@
2016-02-29 22:32:46 +01:00
EnchantmentManager.a(map, itemstack1);
}
2018-12-13 01:00:00 +01:00
- this.resultInventory.setItem(0, itemstack1);
2016-02-29 22:32:46 +01:00
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1); // CraftBukkit
2019-04-23 04:00:00 +02:00
this.c();
2016-02-29 22:32:46 +01:00
}
}
2019-04-23 04:00:00 +02:00
@@ -312,6 +323,7 @@
2019-04-23 04:00:00 +02:00
@Override
2017-09-18 12:00:00 +02:00
public boolean canUse(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
2019-04-23 04:00:00 +02:00
return (Boolean) this.containerAccess.a((world, blockposition) -> {
return !world.getType(blockposition).a(TagsBlock.ANVIL) ? false : entityhuman.e((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) <= 64.0D;
}, true);
@@ -370,4 +382,18 @@
2019-04-23 04:00:00 +02:00
this.e();
}
2016-11-17 02:41:03 +01:00
+
+ // CraftBukkit start
+ @Override
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+
2016-02-29 22:32:46 +01:00
+ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryAnvil(
2019-04-23 04:00:00 +02:00
+ containerAccess.getLocation(), this.repairInventory, this.resultInventory, this);
2018-12-13 01:00:00 +01:00
+ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
2016-11-17 02:41:03 +01:00
}