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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
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 564822911c25238900b361d564c5db3103900fb3..f6268231e39f50bb6adedd85e3c18d746ae3792d 100644
--- a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
@@ -227,7 +227,10 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
if (state != dummyBlockState && org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(player, pos, dummyBlockState).isCancelled()) { // if block state will change and event cancelled
return InteractionResult.sidedSuccess(world.isClientSide);
}
- BlockState iblockdata1 = ComposterBlock.addItem(state, world, pos, itemstack, rand);
+ BlockState iblockdata1 = ComposterBlock.addItem(state, world, pos, itemstack, player);
+ if (iblockdata1 == null) {
+ return InteractionResult.PASS;
+ }
// Paper end
world.levelEvent(1500, pos, state != iblockdata1 ? 1 : 0);
@@ -252,11 +255,16 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
if (i < 7 && ComposterBlock.COMPOSTABLES.containsKey(itemstack.getItem())) {
// CraftBukkit start
double rand = worldserver.getRandom().nextDouble();
- BlockState iblockdata1 = ComposterBlock.addItem(iblockdata, DummyGeneratorAccess.INSTANCE, blockposition, itemstack, rand);
+ BlockState iblockdata1 = ComposterBlock.addItem(iblockdata, DummyGeneratorAccess.INSTANCE, blockposition, itemstack, rand, entity); // Paper
if (iblockdata == iblockdata1 || org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata1).isCancelled()) {
return iblockdata;
}
- iblockdata1 = ComposterBlock.addItem(iblockdata, (LevelAccessor) worldserver, blockposition, itemstack, rand);
+ // Paper start
+ iblockdata1 = ComposterBlock.addItem(iblockdata, (LevelAccessor) worldserver, blockposition, itemstack, rand, entity);
+ if (iblockdata1 == null) {
+ return iblockdata;
+ }
+ // Paper end
// CraftBukkit end
itemstack.shrink(1);
@@ -303,13 +311,39 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
// CraftBukkit start
return ComposterBlock.addItem(state, world, pos, item, world.getRandom().nextDouble());
}
+ // Paper start
+ static BlockState addItem(BlockState state, LevelAccessor world, BlockPos pos, ItemStack item, @Nullable Entity entity) {
+ return ComposterBlock.addItem(state, world, pos, item, world.getRandom().nextDouble(), entity);
+ }
+ // Paper end
static BlockState addItem(BlockState iblockdata, LevelAccessor generatoraccess, BlockPos blockposition, ItemStack itemstack, double rand) {
+ // Paper start
+ return ComposterBlock.addItem(iblockdata, generatoraccess, blockposition, itemstack, rand, null);
+ }
+
+ @Nullable
+ static BlockState addItem(BlockState iblockdata, LevelAccessor generatoraccess, BlockPos blockposition, ItemStack itemstack, double rand, @Nullable Entity entity) {
+ // Paper end
// CraftBukkit end
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
+ io.papermc.paper.event.block.CompostItemEvent event;
+ boolean willRaiseLevel = !((i != 0 || f <= 0.0F) && rand >= (double) f);
+ 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()) {
+ return null;
+ }
+
+ if (!event.willRaiseLevel()) {
+ // Paper end
return iblockdata;
} else {
int j = i + 1;
@@ -453,6 +487,11 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
this.changed = true;
BlockState iblockdata = ComposterBlock.addItem(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);
}
|