PaperMC/patches/server/0959-Add-CompostItemEvent-and-EntityCompostItemEvent.patch
2023-03-14 22:29:14 +01:00

82 lines
4.6 KiB
Diff

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/entity/ai/behavior/WorkAtComposter.java b/src/main/java/net/minecraft/world/entity/ai/behavior/WorkAtComposter.java
index 05c1e8c9f013547d4fcdbbd299329166a8ece1b0..aff235c019ae5c6ed5227127d5424b34af5f36dd 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/WorkAtComposter.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/WorkAtComposter.java
@@ -58,7 +58,7 @@ public class WorkAtComposter extends WorkAtPoi {
i -= p;
for(int q = 0; q < p; ++q) {
- blockState = ComposterBlock.insertItem(entity, blockState, world, itemStack, blockPos);
+ blockState = ComposterBlock.insertItem(entity, blockState, world, itemStack, blockPos, entity); // Paper
if (blockState.getValue(ComposterBlock.LEVEL) == 7) {
this.spawnComposterFillEffects(world, composterState, blockPos, blockState);
return;
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 e81bda56c58df6c3109382c17e86f4cc0f16cf81..fc3f08db8e3747e6e9d6f448c91e51144d480585 100644
--- a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
@@ -235,7 +235,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(player, state, world, pos, itemstack, rand);
+ BlockState iblockdata1 = ComposterBlock.addItem(player, state, world, pos, itemstack);
+ if (iblockdata1 == null) {
+ return InteractionResult.PASS;
+ }
// Paper end
world.levelEvent(1500, pos, state != iblockdata1 ? 1 : 0);
@@ -265,6 +268,11 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
return state;
}
iblockdata1 = ComposterBlock.addItem(user, state, world, pos, stack, rand);
+ // Paper start
+ if (iblockdata1 == null) {
+ return state;
+ }
+ // Paper end
// CraftBukkit end
stack.shrink(1);
@@ -315,7 +323,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
+ 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;
@@ -460,6 +482,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);
}