3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-22 06:20:06 +01:00
Paper/patches/server-unmapped/0659-Added-PlayerStonecutterRecipeSelectEvent.patch
2021-06-11 14:02:28 +02:00

110 Zeilen
5.8 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/world/inventory/Container.java b/src/main/java/net/minecraft/world/inventory/Container.java
index bdd00608a72dd81003731ff5fbe774dfdc5220e5..b58ec4abff2840556eb06e08b241a2eaa85c2c7f 100644
--- a/src/main/java/net/minecraft/world/inventory/Container.java
+++ b/src/main/java/net/minecraft/world/inventory/Container.java
@@ -118,7 +118,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/world/inventory/ContainerProperty.java b/src/main/java/net/minecraft/world/inventory/ContainerProperty.java
index 67c3b7ddb0b0f10c82577cbea7506c9d80d41368..b9c82e68a811c2ef6bf2d5ce3ae9f858bcb263d5 100644
--- a/src/main/java/net/minecraft/world/inventory/ContainerProperty.java
+++ b/src/main/java/net/minecraft/world/inventory/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/world/inventory/ContainerStonecutter.java b/src/main/java/net/minecraft/world/inventory/ContainerStonecutter.java
index 1589d9ca201d386d11d9fd57fa8ba6848bae215c..dc667dd5d8514ae4c8a2087cb913f44320ebfc48 100644
--- a/src/main/java/net/minecraft/world/inventory/ContainerStonecutter.java
+++ b/src/main/java/net/minecraft/world/inventory/ContainerStonecutter.java
@@ -22,13 +22,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;
@@ -58,7 +59,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 = () -> {
@@ -136,13 +137,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();
}