Energy sword no longer breaks blocks in creative

This commit is contained in:
DBotThePony 2022-09-05 00:35:32 +07:00
parent 4babe703c7
commit f2b0ad4fec
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -11,6 +11,7 @@ import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.ai.attributes.Attribute
import net.minecraft.world.entity.ai.attributes.AttributeModifier
import net.minecraft.world.entity.ai.attributes.Attributes
import net.minecraft.world.entity.player.Player
import net.minecraft.world.item.Item
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Rarity
@ -63,6 +64,10 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE).tab(Ov
}
}
override fun canAttackBlock(p_41441_: BlockState, p_41442_: Level, p_41443_: BlockPos, p_41444_: Player): Boolean {
return !p_41444_.isCreative
}
override fun hurtEnemy(itemStack: ItemStack, victim: LivingEntity, attacker: LivingEntity): Boolean {
itemStack.getCapability(MatteryCapability.ENERGY).orNull()?.let {
if (!it.extractEnergyInnerExact(ENERGY_PER_SWING, false).isZero) {