2023-03-05 18:59:48 +01:00
|
|
|
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
|
2023-03-15 02:27:20 +01:00
|
|
|
index e81bda56c58df6c3109382c17e86f4cc0f16cf81..ae90e86327957bb784e2d81694ee7eea288bb455 100644
|
2023-03-05 18:59:48 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
|
2023-03-15 02:27:20 +01:00
|
|
|
@@ -236,6 +236,9 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
2023-03-05 18:59:48 +01:00
|
|
|
return InteractionResult.sidedSuccess(world.isClientSide);
|
|
|
|
}
|
2023-03-15 02:27:20 +01:00
|
|
|
BlockState iblockdata1 = ComposterBlock.addItem(player, state, world, pos, itemstack, rand);
|
2023-03-05 18:59:48 +01:00
|
|
|
+ if (iblockdata1 == null) {
|
|
|
|
+ return InteractionResult.PASS;
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
world.levelEvent(1500, pos, state != iblockdata1 ? 1 : 0);
|
2023-03-14 22:29:14 +01:00
|
|
|
@@ -265,6 +268,11 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
|
|
|
return state;
|
2023-03-05 18:59:48 +01:00
|
|
|
}
|
2023-03-14 22:29:14 +01:00
|
|
|
iblockdata1 = ComposterBlock.addItem(user, state, world, pos, stack, rand);
|
2023-03-05 18:59:48 +01:00
|
|
|
+ // Paper start
|
|
|
|
+ if (iblockdata1 == null) {
|
2023-03-14 22:29:14 +01:00
|
|
|
+ return state;
|
2023-03-05 18:59:48 +01:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2023-03-14 22:29:14 +01:00
|
|
|
stack.shrink(1);
|
2023-03-15 02:27:20 +01:00
|
|
|
@@ -315,7 +323,22 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
2023-03-05 18:59:48 +01:00
|
|
|
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);
|
2023-03-15 02:27:20 +01:00
|
|
|
+ if (generatoraccess == DummyGeneratorAccess.INSTANCE || entity == null) { // call event on test run or when entity is null (via hopper)
|
|
|
|
+ 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()) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ willRaiseLevel = event.willRaiseLevel();
|
2023-03-05 18:59:48 +01:00
|
|
|
+ }
|
2023-03-15 02:27:20 +01:00
|
|
|
+ if (!willRaiseLevel) {
|
2023-03-05 18:59:48 +01:00
|
|
|
+ // Paper end
|
|
|
|
return iblockdata;
|
|
|
|
} else {
|
|
|
|
int j = i + 1;
|
2023-03-15 02:27:20 +01:00
|
|
|
@@ -460,6 +483,11 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
2023-03-05 18:59:48 +01:00
|
|
|
this.changed = true;
|
2023-03-14 22:29:14 +01:00
|
|
|
BlockState iblockdata = ComposterBlock.addItem((Entity) null, this.state, this.level, this.pos, itemstack);
|
2023-03-05 18:59:48 +01:00
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ if (iblockdata == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
this.level.levelEvent(1500, this.pos, iblockdata != this.state ? 1 : 0);
|
|
|
|
this.removeItemNoUpdate(0);
|
|
|
|
}
|