Update powered sword, make it sweep attack

#54
This commit is contained in:
DBotThePony 2022-09-26 11:34:22 +07:00
parent 06874cf569
commit 2833d1fdb9
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 37 additions and 20 deletions

View File

@ -60,7 +60,7 @@ private fun batteryLevel(it: IMatteryEnergyStorage, tooltips: MutableList<Compon
if (it.maxInput != null) {
tooltips.add(TranslatableComponent("otm.item.power.throughput_mono", it.maxInput!!.formatPower()).withStyle(ChatFormatting.GRAY))
} else {
tooltips.add(TranslatableComponent("otm.item.power.throughput_mono", TranslatableComponent("item.power.infinity").withStyle(ChatFormatting.GRAY)).withStyle(ChatFormatting.GRAY))
tooltips.add(TranslatableComponent("otm.item.power.throughput_mono", TranslatableComponent("otm.item.power.infinity").withStyle(ChatFormatting.GRAY)).withStyle(ChatFormatting.GRAY))
}
}
@ -68,7 +68,7 @@ private fun batteryLevel(it: IMatteryEnergyStorage, tooltips: MutableList<Compon
if (it.maxOutput != null) {
tooltips.add(TranslatableComponent("otm.item.power.throughput_mono", it.maxOutput!!.formatPower()).withStyle(ChatFormatting.GRAY))
} else {
tooltips.add(TranslatableComponent("otm.item.power.throughput_mono", TranslatableComponent("item.power.infinity").withStyle(ChatFormatting.GRAY)).withStyle(ChatFormatting.GRAY))
tooltips.add(TranslatableComponent("otm.item.power.throughput_mono", TranslatableComponent("otm.item.power.infinity").withStyle(ChatFormatting.GRAY)).withStyle(ChatFormatting.GRAY))
}
}
@ -81,17 +81,17 @@ private fun batteryLevel(it: IMatteryEnergyStorage, tooltips: MutableList<Compon
} else if (maxInput != null) {
tooltips.add(TranslatableComponent("otm.item.power.throughput",
maxInput.formatPower(),
TranslatableComponent("item.power.infinity").withStyle(ChatFormatting.GRAY)
TranslatableComponent("otm.item.power.infinity").withStyle(ChatFormatting.GRAY)
).withStyle(ChatFormatting.GRAY))
} else if (maxOutput != null) {
tooltips.add(TranslatableComponent("otm.item.power.throughput",
TranslatableComponent("item.power.infinity").withStyle(ChatFormatting.GRAY),
TranslatableComponent("otm.item.power.infinity").withStyle(ChatFormatting.GRAY),
maxOutput.formatPower(),
).withStyle(ChatFormatting.GRAY))
} else {
tooltips.add(TranslatableComponent("otm.item.power.throughput",
TranslatableComponent("item.power.infinity").withStyle(ChatFormatting.GRAY),
TranslatableComponent("item.power.infinity").withStyle(ChatFormatting.GRAY),
TranslatableComponent("otm.item.power.infinity").withStyle(ChatFormatting.GRAY),
TranslatableComponent("otm.item.power.infinity").withStyle(ChatFormatting.GRAY),
).withStyle(ChatFormatting.GRAY))
}
}

View File

@ -20,10 +20,23 @@ import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Blocks
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.material.Material
import net.minecraftforge.common.ToolAction
import net.minecraftforge.common.ToolActions
import net.minecraftforge.common.capabilities.ICapabilityProvider
import ru.dbotthepony.mc.otm.*
import ru.dbotthepony.mc.otm.capability.*
import ru.dbotthepony.mc.otm.core.*
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.capability.EnergyConsumerItem
import ru.dbotthepony.mc.otm.capability.ItemEnergyStorageImpl
import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.extractEnergyInnerExact
import ru.dbotthepony.mc.otm.capability.getBarColor
import ru.dbotthepony.mc.otm.capability.getBarWidth
import ru.dbotthepony.mc.otm.capability.matteryEnergy
import ru.dbotthepony.mc.otm.capability.matteryPlayer
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.formatPower
import ru.dbotthepony.mc.otm.core.ifPresentK
import ru.dbotthepony.mc.otm.core.orNull
import ru.dbotthepony.mc.otm.registry.EMPDamageSource
class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB)) {
@ -69,7 +82,11 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE).tab(Ov
}
override fun hurtEnemy(itemStack: ItemStack, victim: LivingEntity, attacker: LivingEntity): Boolean {
itemStack.getCapability(MatteryCapability.ENERGY).orNull()?.let {
if (attacker is Player && attacker.isCreative) {
return true
}
itemStack.getCapability(MatteryCapability.ENERGY).ifPresentK {
if (!it.extractEnergyInnerExact(ENERGY_PER_SWING, false).isZero) {
victim.matteryPlayer?.let {
it.androidEnergy.extractEnergyInner(ENERGY_ZAP, false)
@ -101,15 +118,7 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE).tab(Ov
) {
super.appendHoverText(itemStack, p_41422_, p_41423_, p_41424_)
itemStack.getCapability(MatteryCapability.ENERGY).ifPresentK {
p_41423_.add(
TranslatableComponent(
"otm.item.power.normal.storage",
it.batteryLevel.formatPower(),
it.maxBatteryLevel.formatPower()
).withStyle(ChatFormatting.GRAY)
)
}
ItemEnergyStorageImpl.appendHoverText(itemStack, p_41423_)
p_41423_.add(DESCRIPTION)
p_41423_.add(DESCRIPTION2)
@ -122,7 +131,7 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE).tab(Ov
p_41419_: BlockPos,
p_41420_: LivingEntity
): Boolean {
if (blockState.getDestroySpeed(p_41417_, p_41419_) != 0f) {
if (blockState.getDestroySpeed(p_41417_, p_41419_) != 0f && (p_41420_ !is Player || !p_41420_.isCreative)) {
val energy = itemStack.matteryEnergy
when (blockState.material) {
@ -159,6 +168,14 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE).tab(Ov
return dischargedAttributes
}
override fun canPerformAction(stack: ItemStack, toolAction: ToolAction): Boolean {
if (stack.matteryEnergy?.extractEnergyInnerExact(ENERGY_PER_SWING, true)?.isPositive == true) {
return ToolActions.DEFAULT_SWORD_ACTIONS.contains(toolAction)
}
return false
}
companion object {
private val MAX_ENERGY = ImpreciseFraction(500_000)
private val ENERGY_ZAP = ImpreciseFraction(4_000)