b31089a929
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: d264e972 #591: Add option for a consumer before spawning an item 1c537fce #590: Add spawn and transform reasons for piglin zombification. CraftBukkit Changes: ee5006d1 #810: Add option for a consumer before spawning an item f6a39d3c #809: Add spawn and transform reasons for piglin zombification. 0c24068a Organise imports Spigot Changes: bff52619 Organise imports
110 Zeilen
5.7 KiB
Diff
110 Zeilen
5.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Fri, 27 Nov 2020 17:14:27 -0800
|
|
Subject: [PATCH] Added PlayerStonecutterRecipeSelectEvent
|
|
|
|
Co-Authored-By: MiniDigger <admin@minidigger.me>
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Container.java b/src/main/java/net/minecraft/server/Container.java
|
|
index 3de58cd344c37451873aa8a12b5d9e65f390ec8f..a5c92b2b7fe42b81e7feebf8969a08bd7d08e0e6 100644
|
|
--- a/src/main/java/net/minecraft/server/Container.java
|
|
+++ b/src/main/java/net/minecraft/server/Container.java
|
|
@@ -101,7 +101,7 @@ public abstract class Container {
|
|
return slot;
|
|
}
|
|
|
|
- protected ContainerProperty a(ContainerProperty containerproperty) {
|
|
+ protected ContainerProperty addDataSlot(ContainerProperty containerproperty) { return a(containerproperty); } protected ContainerProperty a(ContainerProperty containerproperty) { // Paper - OBFHELPER
|
|
this.d.add(containerproperty);
|
|
return containerproperty;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/ContainerProperty.java b/src/main/java/net/minecraft/server/ContainerProperty.java
|
|
index e26b8569340fb0240439ff85d481bd3de19c0ae3..7523c77a914d7e78b4ef08c1ef329d2ef38d3091 100644
|
|
--- a/src/main/java/net/minecraft/server/ContainerProperty.java
|
|
+++ b/src/main/java/net/minecraft/server/ContainerProperty.java
|
|
@@ -20,7 +20,7 @@ public abstract class ContainerProperty {
|
|
};
|
|
}
|
|
|
|
- public static ContainerProperty a(final int[] aint, final int i) {
|
|
+ public static ContainerProperty shared(final int[] aint, final int i) { return a(aint, i); } public static ContainerProperty a(final int[] aint, final int i) { // Paper - OBFHELPER
|
|
return new ContainerProperty() {
|
|
@Override
|
|
public int get() {
|
|
@@ -54,7 +54,7 @@ public abstract class ContainerProperty {
|
|
|
|
public abstract void set(int i);
|
|
|
|
- public boolean c() {
|
|
+ public boolean checkAndClearUpdateFlag() { return c(); } public boolean c() { // Paper - OBFHELPER
|
|
int i = this.get();
|
|
boolean flag = i != this.a;
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ContainerStonecutter.java b/src/main/java/net/minecraft/server/ContainerStonecutter.java
|
|
index 232a46021edcaa90d29dfa5e8b6857f4ab4a8eac..d64c154615f1ff424f5a627f02e3a8fb6136ea8c 100644
|
|
--- a/src/main/java/net/minecraft/server/ContainerStonecutter.java
|
|
+++ b/src/main/java/net/minecraft/server/ContainerStonecutter.java
|
|
@@ -9,13 +9,14 @@ import org.bukkit.craftbukkit.inventory.CraftInventoryStonecutter;
|
|
import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
|
import org.bukkit.entity.Player;
|
|
// CraftBukkit end
|
|
+import io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent; // Paper
|
|
|
|
public class ContainerStonecutter extends Container {
|
|
|
|
private final ContainerAccess containerAccess;
|
|
private final ContainerProperty containerProperty;
|
|
private final World world;
|
|
- private List<RecipeStonecutting> i;
|
|
+ private List<RecipeStonecutting> i; public final List<RecipeStonecutting> getRecipes() { return this.i; } // Paper - OBFHELPER
|
|
private ItemStack j;
|
|
private long k;
|
|
final Slot c;
|
|
@@ -45,7 +46,7 @@ public class ContainerStonecutter extends Container {
|
|
|
|
public ContainerStonecutter(int i, PlayerInventory playerinventory, final ContainerAccess containeraccess) {
|
|
super(Containers.STONECUTTER, i);
|
|
- this.containerProperty = ContainerProperty.a();
|
|
+ this.containerProperty = addDataSlot(ContainerProperty.shared(new int[1], 0)); // Paper - allow replication
|
|
this.i = Lists.newArrayList();
|
|
this.j = ItemStack.b;
|
|
this.l = () -> {
|
|
@@ -123,13 +124,36 @@ public class ContainerStonecutter extends Container {
|
|
@Override
|
|
public boolean a(EntityHuman entityhuman, int i) {
|
|
if (this.d(i)) {
|
|
- this.containerProperty.set(i);
|
|
+ // Paper start
|
|
+ int recipeIndex = i;
|
|
+ this.containerProperty.set(recipeIndex);
|
|
+ this.containerProperty.checkAndClearUpdateFlag(); // mark as changed
|
|
+ if (this.isValidRecipeIndex(i)) {
|
|
+ PlayerStonecutterRecipeSelectEvent event = new PlayerStonecutterRecipeSelectEvent((Player) entityhuman.getBukkitEntity(), (org.bukkit.inventory.StonecutterInventory) getBukkitView().getTopInventory(), (org.bukkit.inventory.StonecuttingRecipe) this.getRecipes().get(i).toBukkitRecipe());
|
|
+ if (!event.callEvent()) {
|
|
+ ((Player) entityhuman.getBukkitEntity()).updateInventory();
|
|
+ return false;
|
|
+ }
|
|
+ int newRecipeIndex;
|
|
+ if (!this.getRecipes().get(recipeIndex).getKey().equals(org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(event.getStonecuttingRecipe().getKey()))) { // If the recipe did NOT stay the same
|
|
+ for (newRecipeIndex = 0; newRecipeIndex < this.getRecipes().size(); newRecipeIndex++) {
|
|
+ if (this.getRecipes().get(newRecipeIndex).getKey().equals(org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(event.getStonecuttingRecipe().getKey()))) {
|
|
+ recipeIndex = newRecipeIndex;
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ ((Player) entityhuman.getBukkitEntity()).updateInventory();
|
|
+ this.containerProperty.set(recipeIndex); // set new index, so that listeners can read it
|
|
+ // Paper end
|
|
this.i();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
+ private boolean isValidRecipeIndex(int index) { return this.d(index); } // Paper - OBFHELPER
|
|
private boolean d(int i) {
|
|
return i >= 0 && i < this.i.size();
|
|
}
|