PaperMC/paper-server/nms-patches/net/minecraft/world/inventory/ContainerSmithing.patch

61 lines
2.5 KiB
Diff
Raw Normal View History

2021-03-15 23:00:00 +01:00
--- a/net/minecraft/world/inventory/ContainerSmithing.java
+++ b/net/minecraft/world/inventory/ContainerSmithing.java
@@ -12,6 +12,8 @@
2021-03-15 23:00:00 +01:00
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.IBlockData;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView; // CraftBukkit
+
public class ContainerSmithing extends ContainerAnvilAbstract {
public static final int TEMPLATE_SLOT = 0;
@@ -27,6 +29,9 @@
@Nullable
private SmithingRecipe selectedRecipe;
private final List<SmithingRecipe> recipes;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity;
+ // CraftBukkit end
public ContainerSmithing(int i, PlayerInventory playerinventory) {
this(i, playerinventory, ContainerAccess.NULL);
@@ -96,7 +101,7 @@
List<SmithingRecipe> list = this.level.getRecipeManager().getRecipesFor(Recipes.SMITHING, this.inputSlots, this.level);
if (list.isEmpty()) {
- this.resultSlots.setItem(0, ItemStack.EMPTY);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit
} else {
SmithingRecipe smithingrecipe = (SmithingRecipe) list.get(0);
ItemStack itemstack = smithingrecipe.assemble(this.inputSlots, this.level.registryAccess());
@@ -104,7 +109,9 @@
if (itemstack.isItemEnabled(this.level.enabledFeatures())) {
this.selectedRecipe = smithingrecipe;
this.resultSlots.setRecipeUsed(smithingrecipe);
- this.resultSlots.setItem(0, itemstack);
+ // CraftBukkit start
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), itemstack);
+ // CraftBukkit end
}
}
@@ -132,4 +139,18 @@
return findSlotMatchingIngredient(smithingrecipe, itemstack);
}).anyMatch(Optional::isPresent);
}
+
+ // CraftBukkit start
+ @Override
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventorySmithingNew(
+ access.getLocation(), this.inputSlots, this.resultSlots);
+ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}