If a crossbow breaks during loading, fire it immediately
Seemed wrong to leave a crossbow as broken and loaded
@@ -266,10 +266,15 @@ public class ModifiableCrossbowItem extends ModifiableLauncherItem {
// find ammo and store it on the bow
ItemStack ammo = BowAmmoModifierHook.findAmmo(tool, bow, player, getSupportedHeldProjectiles());
if (!ammo.isEmpty()) {
+ level.playSound(null, living.getX(), living.getY(), living.getZ(), SoundEvents.CROSSBOW_LOADING_END, SoundSource.PLAYERS, 1.0F, 1.0F / (level.getRandom().nextFloat() * 0.5F + 1.0F) + 0.2F);
if (!level.isClientSide) {
- persistentData.put(KEY_CROSSBOW_AMMO, ammo.save(new CompoundTag()));
+ CompoundTag ammoNBT = ammo.save(new CompoundTag());
+ persistentData.put(KEY_CROSSBOW_AMMO, ammoNBT);
+ // if the crossbow broke during loading, fire immediately
+ if (tool.isBroken()) {
+ fireCrossbow(tool, player, player.getUsedItemHand(), ammoNBT);
+ }
}
- level.playSound(null, living.getX(), living.getY(), living.getZ(), SoundEvents.CROSSBOW_LOADING_END, SoundSource.PLAYERS, 1.0F, 1.0F / (level.getRandom().nextFloat() * 0.5F + 1.0F) + 0.2F);
}
}
