Fix possible StackOverflowError and NPE for some dispenses

For saddles, carpets, horse armor, and chests for horse-likes
a BlockDispenseEvent handler that always mutated the item without
changing the type would result in a SO error because when it went
to find the replacement dispense behavior (since the item "changed")
it didn't properly handle if the replacement was the same instance
of dispense behavior.

Additionally equippable mob heads, wither skulls, and carved pumpkins
are subject to the same possible error.

Furthermore since 1.21.2, the DISPENSER_REGISTRY map doesn't have a default
return value anymore and some dispense behaviors like equippable and
regular items will not have a defined behavior in that map and might throw
a NPE in that case.
This commit is contained in:
Jake Potrebic
2022-10-29 17:02:42 -07:00
parent 368ca9c145
commit 6c400a907b
10 changed files with 75 additions and 26 deletions

View File

@@ -35,3 +35,16 @@
tileentitydispenser.setItem(i, idispensebehavior.dispense(sourceblock, itemstack));
}
@@ -111,6 +116,12 @@
}
}
+ // Paper start - Fix NPE with equippable and items without behavior
+ public static DispenseItemBehavior getDispenseBehavior(BlockSource pointer, ItemStack stack) {
+ return ((DispenserBlock) pointer.state().getBlock()).getDispenseMethod(pointer.level(), stack);
+ }
+ // Paper end - Fix NPE with equippable and items without behavior
+
protected DispenseItemBehavior getDispenseMethod(Level world, ItemStack stack) {
if (!stack.isItemEnabled(world.enabledFeatures())) {
return DispenserBlock.DEFAULT_BEHAVIOR;