parent
06874cf569
commit
2833d1fdb9
@ -60,7 +60,7 @@ private fun batteryLevel(it: IMatteryEnergyStorage, tooltips: MutableList<Compon
|
|||||||
if (it.maxInput != null) {
|
if (it.maxInput != null) {
|
||||||
tooltips.add(TranslatableComponent("otm.item.power.throughput_mono", it.maxInput!!.formatPower()).withStyle(ChatFormatting.GRAY))
|
tooltips.add(TranslatableComponent("otm.item.power.throughput_mono", it.maxInput!!.formatPower()).withStyle(ChatFormatting.GRAY))
|
||||||
} else {
|
} 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) {
|
if (it.maxOutput != null) {
|
||||||
tooltips.add(TranslatableComponent("otm.item.power.throughput_mono", it.maxOutput!!.formatPower()).withStyle(ChatFormatting.GRAY))
|
tooltips.add(TranslatableComponent("otm.item.power.throughput_mono", it.maxOutput!!.formatPower()).withStyle(ChatFormatting.GRAY))
|
||||||
} else {
|
} 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) {
|
} else if (maxInput != null) {
|
||||||
tooltips.add(TranslatableComponent("otm.item.power.throughput",
|
tooltips.add(TranslatableComponent("otm.item.power.throughput",
|
||||||
maxInput.formatPower(),
|
maxInput.formatPower(),
|
||||||
TranslatableComponent("item.power.infinity").withStyle(ChatFormatting.GRAY)
|
TranslatableComponent("otm.item.power.infinity").withStyle(ChatFormatting.GRAY)
|
||||||
).withStyle(ChatFormatting.GRAY))
|
).withStyle(ChatFormatting.GRAY))
|
||||||
} else if (maxOutput != null) {
|
} else if (maxOutput != null) {
|
||||||
tooltips.add(TranslatableComponent("otm.item.power.throughput",
|
tooltips.add(TranslatableComponent("otm.item.power.throughput",
|
||||||
TranslatableComponent("item.power.infinity").withStyle(ChatFormatting.GRAY),
|
TranslatableComponent("otm.item.power.infinity").withStyle(ChatFormatting.GRAY),
|
||||||
maxOutput.formatPower(),
|
maxOutput.formatPower(),
|
||||||
).withStyle(ChatFormatting.GRAY))
|
).withStyle(ChatFormatting.GRAY))
|
||||||
} else {
|
} else {
|
||||||
tooltips.add(TranslatableComponent("otm.item.power.throughput",
|
tooltips.add(TranslatableComponent("otm.item.power.throughput",
|
||||||
TranslatableComponent("item.power.infinity").withStyle(ChatFormatting.GRAY),
|
TranslatableComponent("otm.item.power.infinity").withStyle(ChatFormatting.GRAY),
|
||||||
TranslatableComponent("item.power.infinity").withStyle(ChatFormatting.GRAY),
|
TranslatableComponent("otm.item.power.infinity").withStyle(ChatFormatting.GRAY),
|
||||||
).withStyle(ChatFormatting.GRAY))
|
).withStyle(ChatFormatting.GRAY))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,23 @@ import net.minecraft.world.level.Level
|
|||||||
import net.minecraft.world.level.block.Blocks
|
import net.minecraft.world.level.block.Blocks
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import net.minecraft.world.level.material.Material
|
import net.minecraft.world.level.material.Material
|
||||||
|
import net.minecraftforge.common.ToolAction
|
||||||
|
import net.minecraftforge.common.ToolActions
|
||||||
import net.minecraftforge.common.capabilities.ICapabilityProvider
|
import net.minecraftforge.common.capabilities.ICapabilityProvider
|
||||||
import ru.dbotthepony.mc.otm.*
|
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||||
import ru.dbotthepony.mc.otm.capability.*
|
import ru.dbotthepony.mc.otm.capability.EnergyConsumerItem
|
||||||
import ru.dbotthepony.mc.otm.core.*
|
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
|
import ru.dbotthepony.mc.otm.registry.EMPDamageSource
|
||||||
|
|
||||||
class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE).tab(OverdriveThatMatters.INSTANCE.CREATIVE_TAB)) {
|
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 {
|
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) {
|
if (!it.extractEnergyInnerExact(ENERGY_PER_SWING, false).isZero) {
|
||||||
victim.matteryPlayer?.let {
|
victim.matteryPlayer?.let {
|
||||||
it.androidEnergy.extractEnergyInner(ENERGY_ZAP, false)
|
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_)
|
super.appendHoverText(itemStack, p_41422_, p_41423_, p_41424_)
|
||||||
|
|
||||||
itemStack.getCapability(MatteryCapability.ENERGY).ifPresentK {
|
ItemEnergyStorageImpl.appendHoverText(itemStack, p_41423_)
|
||||||
p_41423_.add(
|
|
||||||
TranslatableComponent(
|
|
||||||
"otm.item.power.normal.storage",
|
|
||||||
it.batteryLevel.formatPower(),
|
|
||||||
it.maxBatteryLevel.formatPower()
|
|
||||||
).withStyle(ChatFormatting.GRAY)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
p_41423_.add(DESCRIPTION)
|
p_41423_.add(DESCRIPTION)
|
||||||
p_41423_.add(DESCRIPTION2)
|
p_41423_.add(DESCRIPTION2)
|
||||||
@ -122,7 +131,7 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE).tab(Ov
|
|||||||
p_41419_: BlockPos,
|
p_41419_: BlockPos,
|
||||||
p_41420_: LivingEntity
|
p_41420_: LivingEntity
|
||||||
): Boolean {
|
): 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
|
val energy = itemStack.matteryEnergy
|
||||||
|
|
||||||
when (blockState.material) {
|
when (blockState.material) {
|
||||||
@ -159,6 +168,14 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE).tab(Ov
|
|||||||
return dischargedAttributes
|
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 {
|
companion object {
|
||||||
private val MAX_ENERGY = ImpreciseFraction(500_000)
|
private val MAX_ENERGY = ImpreciseFraction(500_000)
|
||||||
private val ENERGY_ZAP = ImpreciseFraction(4_000)
|
private val ENERGY_ZAP = ImpreciseFraction(4_000)
|
||||||
|
Loading…
Reference in New Issue
Block a user