Make explosive hammer less annoying in creative
This commit is contained in:
parent
7be3607da8
commit
76c0540d57
@ -63,7 +63,7 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun canPrime(player: Player): Boolean {
|
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
|
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) {
|
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
|
return
|
||||||
|
|
||||||
val (ex, ey, ez) = pos
|
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))
|
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)
|
unprime(itemStack)
|
||||||
|
|
||||||
val copy = itemStack.copy()
|
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 {
|
override fun finishUsingItem(stack: ItemStack, level: Level, entity: LivingEntity): ItemStack {
|
||||||
if (entity is Player && canPrime(entity)) {
|
if (entity is Player && canPrime(entity)) {
|
||||||
if (level is ServerLevel) {
|
if (level is ServerLevel) {
|
||||||
|
if (!entity.hasInfiniteMaterials()) {
|
||||||
entity.inventory.clearOrCountMatchingItems(GUNPOWDER_PREDICATE, 1, entity.inventoryMenu.craftSlots)
|
entity.inventory.clearOrCountMatchingItems(GUNPOWDER_PREDICATE, 1, entity.inventoryMenu.craftSlots)
|
||||||
entity.inventory.clearOrCountMatchingItems(IRON_NUGGET_PREDICATE, 1, entity.inventoryMenu.craftSlots)
|
entity.inventory.clearOrCountMatchingItems(IRON_NUGGET_PREDICATE, 1, entity.inventoryMenu.craftSlots)
|
||||||
|
}
|
||||||
|
|
||||||
prime(stack)
|
prime(stack)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user