aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/unapplied/server/0955-Add-CompostItemEvent-and-EntityCompostItemEvent.patch
blob: 32a904e5df9f4c392b4c0d8b73e3b581cd904fb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Noah van der Aa <ndvdaa@gmail.com>
Date: Sun, 8 Aug 2021 19:56:02 +0200
Subject: [PATCH] Add CompostItemEvent and EntityCompostItemEvent


diff --git a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
index 50fd52905d8f69c693cb1b406b681a6af02787e2..6fab2b69a0af298bd00b309efcd6aa8399e23d1f 100644
--- a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
@@ -320,7 +320,21 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
         int i = (Integer) iblockdata.getValue(ComposterBlock.LEVEL);
         float f = ComposterBlock.COMPOSTABLES.getFloat(itemstack.getItem());
 
-        if ((i != 0 || f <= 0.0F) && rand >= (double) f) {
+        // Paper start
+        boolean willRaiseLevel = !((i != 0 || f <= 0.0F) && rand >= (double) f);
+        final io.papermc.paper.event.block.CompostItemEvent event;
+        if (entity == null) {
+            event = new io.papermc.paper.event.block.CompostItemEvent(org.bukkit.craftbukkit.block.CraftBlock.at(generatoraccess, blockposition), itemstack.getBukkitStack(), willRaiseLevel);
+        } else {
+            event = new io.papermc.paper.event.entity.EntityCompostItemEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(generatoraccess, blockposition), itemstack.getBukkitStack(), willRaiseLevel);
+        }
+        if (!event.callEvent()) { // check for cancellation of entity event (non entity event can't be cancelled cause of hoppers)
+            return null;
+        }
+        willRaiseLevel = event.willRaiseLevel();
+
+        if (!willRaiseLevel) {
+            // Paper end
             return iblockdata;
         } else {
             int j = i + 1;
@@ -470,6 +484,11 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
                 this.changed = true;
                 BlockState iblockdata = ComposterBlock.addItem((Entity) null, this.state, this.level, this.pos, itemstack);
 
+                // Paper start
+                if (iblockdata == null) {
+                    return;
+                }
+                // Paper end
                 this.level.levelEvent(1500, this.pos, iblockdata != this.state ? 1 : 0);
                 this.removeItemNoUpdate(0);
             }