Make explosive hammer less annoying in creative

This commit is contained in:
DBotThePony 2025-02-17 20:05:49 +07:00
parent 7be3607da8
commit 76c0540d57
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -63,7 +63,7 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1)
}
fun canPrime(player: Player): Boolean {
return player.inventory.clearOrCountMatchingItems(GUNPOWDER_PREDICATE, 0, player.inventoryMenu.craftSlots) > 0 &&
return player.hasInfiniteMaterials() || player.inventory.clearOrCountMatchingItems(GUNPOWDER_PREDICATE, 0, player.inventoryMenu.craftSlots) > 0 &&
player.inventory.clearOrCountMatchingItems(IRON_NUGGET_PREDICATE, 0, player.inventoryMenu.craftSlots) > 0
}
@ -142,7 +142,7 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1)
}
fun attackAt(itemStack: ItemStack, attacker: LivingEntity, pos: Vec3, aim: Vec3, hand: InteractionHand) {
if (!isPrimed(itemStack) || attacker.level().isClientSide || attacker is Player && attacker.getAttackStrengthScale(0.4f) < 0.98f)
if (!isPrimed(itemStack) || attacker.level().isClientSide || attacker is Player && !attacker.isCreative && attacker.getAttackStrengthScale(0.4f) < 0.98f)
return
val (ex, ey, ez) = pos
@ -221,7 +221,7 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1)
it.connection.send(ClientboundExplodePacket(ex, ey, ez, 1f, exp.toBlow, exp.hitPlayers[it], Explosion.BlockInteraction.DESTROY, ParticleTypes.EXPLOSION, ParticleTypes.EXPLOSION_EMITTER, SoundEvents.GENERIC_EXPLODE))
}
if (attacker !is Player || !attacker.isCreative) {
if (!attacker.hasInfiniteMaterials()) {
unprime(itemStack)
val copy = itemStack.copy()
@ -303,8 +303,10 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1)
override fun finishUsingItem(stack: ItemStack, level: Level, entity: LivingEntity): ItemStack {
if (entity is Player && canPrime(entity)) {
if (level is ServerLevel) {
entity.inventory.clearOrCountMatchingItems(GUNPOWDER_PREDICATE, 1, entity.inventoryMenu.craftSlots)
entity.inventory.clearOrCountMatchingItems(IRON_NUGGET_PREDICATE, 1, entity.inventoryMenu.craftSlots)
if (!entity.hasInfiniteMaterials()) {
entity.inventory.clearOrCountMatchingItems(GUNPOWDER_PREDICATE, 1, entity.inventoryMenu.craftSlots)
entity.inventory.clearOrCountMatchingItems(IRON_NUGGET_PREDICATE, 1, entity.inventoryMenu.craftSlots)
}
prime(stack)
}