Archiviert
13
0

Fix composter throwing UOE with new game event

Dieser Commit ist enthalten in:
Jake Potrebic 2023-03-14 18:27:20 -07:00
Ursprung ffab9f2bc1
Commit 2c485d1485
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: ECE0B3C133C016C5
2 geänderte Dateien mit 30 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -201,3 +201,16 @@ index 53f4a000079f4c056500d03eca71991ae14483a9..e81bda56c58df6c3109382c17e86f4cc
world.levelEvent(1500, pos, state != iblockdata1 ? 1 : 0); world.levelEvent(1500, pos, state != iblockdata1 ? 1 : 0);
player.awardStat(Stats.ITEM_USED.get(itemstack.getItem())); 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 b303eb2989be28dadf183d12a4bd706e43d1fa98..59cd4f331d9051369bc7c47678be7cd10ec41443 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
@@ -121,7 +121,7 @@ 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

Datei anzeigen

@ -5,15 +5,13 @@ 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 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 index e81bda56c58df6c3109382c17e86f4cc0f16cf81..ae90e86327957bb784e2d81694ee7eea288bb455 100644
--- a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java --- a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
+++ b/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 { @@ -236,6 +236,9 @@ 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); return InteractionResult.sidedSuccess(world.isClientSide);
} }
- BlockState iblockdata1 = ComposterBlock.addItem(player, state, world, pos, itemstack, rand); BlockState iblockdata1 = ComposterBlock.addItem(player, state, world, pos, itemstack, rand);
+ BlockState iblockdata1 = ComposterBlock.addItem(player, state, world, pos, itemstack);
+ if (iblockdata1 == null) { + if (iblockdata1 == null) {
+ return InteractionResult.PASS; + return InteractionResult.PASS;
+ } + }
@ -32,30 +30,31 @@ index e81bda56c58df6c3109382c17e86f4cc0f16cf81..fc3f08db8e3747e6e9d6f448c91e5114
// CraftBukkit end // CraftBukkit end
stack.shrink(1); stack.shrink(1);
@@ -315,7 +323,21 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder { @@ -315,7 +323,22 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
int i = (Integer) iblockdata.getValue(ComposterBlock.LEVEL); int i = (Integer) iblockdata.getValue(ComposterBlock.LEVEL);
float f = ComposterBlock.COMPOSTABLES.getFloat(itemstack.getItem()); float f = ComposterBlock.COMPOSTABLES.getFloat(itemstack.getItem());
- if ((i != 0 || f <= 0.0F) && rand >= (double) f) { - if ((i != 0 || f <= 0.0F) && rand >= (double) f) {
+ // Paper start + // Paper start
+ io.papermc.paper.event.block.CompostItemEvent event;
+ boolean willRaiseLevel = !((i != 0 || f <= 0.0F) && rand >= (double) f); + boolean willRaiseLevel = !((i != 0 || f <= 0.0F) && rand >= (double) f);
+ if (entity == null) { + if (generatoraccess == DummyGeneratorAccess.INSTANCE || entity == null) { // call event on test run or when entity is null (via hopper)
+ event = new io.papermc.paper.event.block.CompostItemEvent(org.bukkit.craftbukkit.block.CraftBlock.at(generatoraccess, blockposition), itemstack.getBukkitStack(), willRaiseLevel); + final io.papermc.paper.event.block.CompostItemEvent event;
+ } else { + if (entity == null) {
+ event = new io.papermc.paper.event.entity.EntityCompostItemEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(generatoraccess, blockposition), itemstack.getBukkitStack(), willRaiseLevel); + 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 (!willRaiseLevel) {
+ if (!event.callEvent()) {
+ return null;
+ }
+
+ if (!event.willRaiseLevel()) {
+ // Paper end + // Paper end
return iblockdata; return iblockdata;
} else { } else {
int j = i + 1; int j = i + 1;
@@ -460,6 +482,11 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder { @@ -460,6 +483,11 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
this.changed = true; this.changed = true;
BlockState iblockdata = ComposterBlock.addItem((Entity) null, this.state, this.level, this.pos, itemstack); BlockState iblockdata = ComposterBlock.addItem((Entity) null, this.state, this.level, this.pos, itemstack);