testserver/patches/server/0700-Reset-villager-invento...

55 lines
2.6 KiB
Diff
Raw Normal View History

2021-06-11 12:02:28 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <blake.galbreath@gmail.com>
Date: Tue, 1 Jun 2021 22:05:08 -0500
Subject: [PATCH] Reset villager inventory on cancelled pickup event
diff --git a/src/main/java/net/minecraft/world/SimpleContainer.java b/src/main/java/net/minecraft/world/SimpleContainer.java
2021-06-15 03:50:26 +00:00
index 502e29644504aabe3834351d3b479e21bd8f4be7..4e47ea7359ae56efeb2b74161dc9e7387589415b 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/SimpleContainer.java
+++ b/src/main/java/net/minecraft/world/SimpleContainer.java
@@ -34,6 +34,16 @@ public class SimpleContainer implements Container, StackedContentsCompatible {
return this.items;
}
+ // Paper start
+ public void setContents(List<ItemStack> items) {
+ this.items.clear();
+ for(int i = 0; i < items.size(); i++) {
+ this.items.set(i, items.get(i));
+ }
+ this.setChanged();
+ }
+ // Paper end
+
public void onOpen(CraftHumanEntity who) {
2021-06-15 03:50:26 +00:00
this.transaction.add(who);
2021-06-11 12:02:28 +00:00
}
diff --git a/src/main/java/net/minecraft/world/entity/npc/Villager.java b/src/main/java/net/minecraft/world/entity/npc/Villager.java
2021-06-15 05:38:36 +00:00
index 18b35c8d2160d24c31483edef13cc5e8d93ed09b..27530389690ec329bd92a722e4faf87e367bce91 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
2021-06-15 03:50:26 +00:00
@@ -888,15 +888,19 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
2021-06-11 12:02:28 +00:00
}
// CraftBukkit start
- ItemStack remaining = new SimpleContainer(inventorysubcontainer).addItem(itemstack);
- if (CraftEventFactory.callEntityPickupItemEvent(this, item, remaining.getCount(), false).isCancelled()) {
+ // Paper start
+ List<ItemStack> contentsSnapshot = new java.util.ArrayList<>(inventorysubcontainer.getContents());
+ ItemStack itemstack1 = inventorysubcontainer.addItem(itemstack);
+ if (CraftEventFactory.callEntityPickupItemEvent(this, item, itemstack1.getCount(), false).isCancelled()) {
+ inventorysubcontainer.setContents(contentsSnapshot);
+ // Paper end
return;
}
// CraftBukkit end
this.onItemPickup(item);
this.take(item, itemstack.getCount());
- ItemStack itemstack1 = inventorysubcontainer.addItem(itemstack);
+ // ItemStack itemstack1 = inventorysubcontainer.a(itemstack); // Paper - moved up
if (itemstack1.isEmpty()) {
2021-06-15 03:50:26 +00:00
item.discard();