13
0
geforkt von Mirrors/Paper

Fix composter throwing UOE with new game event

Dieser Commit ist enthalten in:
Jake Potrebic 2023-03-14 18:27:20 -07:00
Ursprung 69697c6a22
Commit 286598313a
2 geänderte Dateien mit 26 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -9,11 +9,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
@@ -0,0 +0,0 @@ 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);
BlockState iblockdata1 = ComposterBlock.addItem(player, state, world, pos, itemstack, rand);
+ if (iblockdata1 == null) {
+ return InteractionResult.PASS;
+ }
@ -38,19 +36,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- 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 (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();
+ }
+
+ if (!event.callEvent()) {
+ return null;
+ }
+
+ if (!event.willRaiseLevel()) {
+ if (!willRaiseLevel) {
+ // Paper end
return iblockdata;
} else {

Datei anzeigen

@ -201,3 +201,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
world.levelEvent(1500, pos, state != iblockdata1 ? 1 : 0);
player.awardStat(Stats.ITEM_USED.get(itemstack.getItem()));
diff --git a/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java b/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
@@ -0,0 +0,0 @@ public class DummyGeneratorAccess implements WorldGenLevel {
@Override
public void gameEvent(GameEvent event, Vec3 emitterPos, GameEvent.Context emitter) {
- throw new UnsupportedOperationException("Not supported yet.");
+ // Used by ComposterBlock
}
@Override