mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Add Grindstone API
This commit is contained in:
84
patches/api/0043-Grindstone-API.patch
Normal file
84
patches/api/0043-Grindstone-API.patch
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: BillyGalbreath <blake.galbreath@gmail.com>
|
||||||
|
Date: Mon, 27 Dec 2021 08:10:50 -0600
|
||||||
|
Subject: [PATCH] Grindstone API
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/org/purpurmc/purpur/event/inventory/GrindstoneTakeResultEvent.java b/src/main/java/org/purpurmc/purpur/event/inventory/GrindstoneTakeResultEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000000000000000000000000000000000000..eebb5d124456b8209d1b8e8cc4cb772dd3714f04
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/org/purpurmc/purpur/event/inventory/GrindstoneTakeResultEvent.java
|
||||||
|
@@ -0,0 +1,72 @@
|
||||||
|
+package org.purpurmc.purpur.event.inventory;
|
||||||
|
+
|
||||||
|
+import org.bukkit.entity.HumanEntity;
|
||||||
|
+import org.bukkit.entity.Player;
|
||||||
|
+import org.bukkit.event.HandlerList;
|
||||||
|
+import org.bukkit.event.inventory.InventoryEvent;
|
||||||
|
+import org.bukkit.inventory.GrindstoneInventory;
|
||||||
|
+import org.bukkit.inventory.InventoryView;
|
||||||
|
+import org.bukkit.inventory.ItemStack;
|
||||||
|
+import org.jetbrains.annotations.NotNull;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * Called when a player takes the result item out of a Grindstone
|
||||||
|
+ */
|
||||||
|
+public class GrindstoneTakeResultEvent extends InventoryEvent {
|
||||||
|
+ private static final HandlerList handlers = new HandlerList();
|
||||||
|
+ private final Player player;
|
||||||
|
+ private final ItemStack result;
|
||||||
|
+ private int experienceAmount;
|
||||||
|
+
|
||||||
|
+ public GrindstoneTakeResultEvent(@NotNull HumanEntity player, @NotNull InventoryView view, @NotNull ItemStack result, int experienceAmount) {
|
||||||
|
+ super(view);
|
||||||
|
+ this.player = (Player) player;
|
||||||
|
+ this.result = result;
|
||||||
|
+ this.experienceAmount = experienceAmount;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ public Player getPlayer() {
|
||||||
|
+ return player;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ public ItemStack getResult() {
|
||||||
|
+ return result;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ @Override
|
||||||
|
+ public GrindstoneInventory getInventory() {
|
||||||
|
+ return (GrindstoneInventory) super.getInventory();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Get the amount of experience this transaction will give
|
||||||
|
+ *
|
||||||
|
+ * @return Amount of experience to give
|
||||||
|
+ */
|
||||||
|
+ public int getExperienceAmount() {
|
||||||
|
+ return this.experienceAmount;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Set the amount of experience this transaction will give
|
||||||
|
+ *
|
||||||
|
+ * @param experienceAmount Amount of experience to give
|
||||||
|
+ */
|
||||||
|
+ public void setExperienceAmount(int experienceAmount) {
|
||||||
|
+ this.experienceAmount = experienceAmount;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ @Override
|
||||||
|
+ public HandlerList getHandlers() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ public static HandlerList getHandlerList() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
21
patches/server/0246-Grindstone-API.patch
Normal file
21
patches/server/0246-Grindstone-API.patch
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: BillyGalbreath <blake.galbreath@gmail.com>
|
||||||
|
Date: Mon, 27 Dec 2021 08:11:00 -0600
|
||||||
|
Subject: [PATCH] Grindstone API
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/net/minecraft/world/inventory/GrindstoneMenu.java b/src/main/java/net/minecraft/world/inventory/GrindstoneMenu.java
|
||||||
|
index 66d1b438227e004d7ffb6e7c5d0cd3e6da3d2a49..a884b00d3ebd5cd89bd870b84afea136bdc79a10 100644
|
||||||
|
--- a/src/main/java/net/minecraft/world/inventory/GrindstoneMenu.java
|
||||||
|
+++ b/src/main/java/net/minecraft/world/inventory/GrindstoneMenu.java
|
||||||
|
@@ -96,8 +96,9 @@ public class GrindstoneMenu extends AbstractContainerMenu {
|
||||||
|
@Override
|
||||||
|
public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {
|
||||||
|
context.execute((world, blockposition) -> {
|
||||||
|
+ org.purpurmc.purpur.event.inventory.GrindstoneTakeResultEvent grindstoneTakeResultEvent = new org.purpurmc.purpur.event.inventory.GrindstoneTakeResultEvent(player.getBukkitEntity(), getBukkitView(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(stack), this.getExperienceAmount(world)); grindstoneTakeResultEvent.callEvent(); // Purpur
|
||||||
|
if (world instanceof ServerLevel) {
|
||||||
|
- ExperienceOrb.award((ServerLevel) world, Vec3.atCenterOf(blockposition), this.getExperienceAmount(world), org.bukkit.entity.ExperienceOrb.SpawnReason.GRINDSTONE, player); // Paper
|
||||||
|
+ ExperienceOrb.award((ServerLevel) world, Vec3.atCenterOf(blockposition), grindstoneTakeResultEvent.getExperienceAmount(), org.bukkit.entity.ExperienceOrb.SpawnReason.GRINDSTONE, player); // Paper // Purpur
|
||||||
|
}
|
||||||
|
|
||||||
|
world.levelEvent(1042, blockposition, 0);
|
||||||
Reference in New Issue
Block a user