Move explosive hammer config to appropriate place

This commit is contained in:
DBotThePony 2023-04-26 17:29:37 +07:00
parent 37a91c525e
commit 3e36725f9e
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 85 additions and 84 deletions

View File

@ -98,76 +98,4 @@ object ItemsConfig : AbstractConfig("items") {
val FLUID_CAPSULE_CAPACITY: Int by builder.defineInRange("FLUID_CAPSULE_CAPACITY", 1000, 1, Int.MAX_VALUE) val FLUID_CAPSULE_CAPACITY: Int by builder.defineInRange("FLUID_CAPSULE_CAPACITY", 1000, 1, Int.MAX_VALUE)
val FLUID_TANK_CAPACITY: Int by builder.defineInRange("FLUID_TANK_CAPACITY", 32_000, 1, Int.MAX_VALUE) val FLUID_TANK_CAPACITY: Int by builder.defineInRange("FLUID_TANK_CAPACITY", 32_000, 1, Int.MAX_VALUE)
object ExplosiveHammer {
val MAX_TRAVEL: Double by builder
.comment("Max distance, in blocks, the nail can travel", "This also dictates potential max damage nail can deal (controlled by TRAVEL_DAMAGE_MULT)")
.comment("The nail penetrate through blocks and entities, losing power in process")
.comment("The nail can not travel into unloaded chunks and will stop immediately if it does so")
.comment("The nail travels its entire path instantaneously")
.defineInRange("MAX_TRAVEL", 48.0, 0.0, Double.MAX_VALUE)
val TRAVEL_EXPLOSION_RESIST_MULT: Double by builder
.comment("Multiplier of explosion resistance of blocks on nail path")
.comment("If explosion resistance multiplied by this is bigger than nail current force (base of MAX_TRAVEL)")
.comment("then nail movement halts, otherwise nail force is reduced by explosion resistance multiplied by this")
.comment("and block is broken (if DAMAGE_BLOCKS is true, otherwise it only acts as stopping power)")
.comment("---")
.comment("Values over 1 will make blocks more resistant to be penetrated through (and broken)")
.comment("Values below 1 will make blocks less resistant to be penetrated though (and broken)")
.comment("Value of 0 means no matter how strong block resistance is, it will be broken by nail", "(this includes bedrock!!!)")
.comment("---")
.defineInRange("TRAVEL_EXPLOSION_RESIST_MULT", 1.75, 0.0, Double.MAX_VALUE)
val TRAVEL_DAMAGE_MULT: Double by builder
.comment("Multiplier of current nail force (base of MAX_TRAVEL) for damage values")
.comment("That is, any being on path of nail will get damaged by nail power multiplied by this")
.defineInRange("TRAVEL_DAMAGE_MULT", 0.6, 0.0, Double.MAX_VALUE)
val TRAVEL_MAX_HEALTH_MULT: Double by builder
.comment("Multiplier of being's max health in nail path subtracted from nail force when penetrating through")
.defineInRange("TRAVEL_MAX_HEALTH_MULT", 0.4, 0.0, Double.MAX_VALUE)
val DAMAGE_BLOCKS: Boolean by builder
.comment("Should hammer (**not** explosion) damage blocks", "Blocks damaged this way will always be dropped")
.define("DAMAGE_BLOCKS", true)
val EXPLOSION_DAMAGE_BLOCKS: Boolean by builder
.comment("Should hammer **explosion** damage blocks")
.define("EXPLOSION_DAMAGE_BLOCKS", false)
val FLY_OFF_CHANCE: Double by builder
.comment("Chance that hammer will fly off hands of attacker upon impact")
.defineInRange("FLY_OFF_CHANCE", 0.6, 0.0, 1.0)
val SELF_HARM_CHANCE: Double by builder
.comment("When hammer DOES NOT fly off hands, what is chance of it damaging the user?", "(this does not account for damage because of hitting things close)", "(idiot)")
.defineInRange("SELF_HARM_CHANCE", 0.4, 0.0, 1.0)
val SELF_HARM_MIN_DAMAGE: Double by builder
.comment("When hammer DOES NOT fly off hands, what is minimal damage it deals to the user (in half of hearts)?")
.defineInRange("SELF_HARM_MIN_DAMAGE", 2.0, 0.0, Double.MAX_VALUE)
val SELF_HARM_MAX_DAMAGE: Double by builder
.comment("When hammer DOES NOT fly off hands, what is maximal damage it deals to the user (in half of hearts)?")
.defineInRange("SELF_HARM_MAX_DAMAGE", 10.0, 0.0, Double.MAX_VALUE)
val FLY_OFF_DAMAGE_CHANCE: Double by builder
.comment("When hammer flies off hands, what is chance of it damaging the user?")
.defineInRange("FLY_OFF_DAMAGE_CHANCE", 0.8, 0.0, 1.0)
val FLY_OFF_MIN_DAMAGE: Double by builder
.comment("When hammer flies off hands, what is minimal damage it deals to the user (in half of hearts)?")
.defineInRange("FLY_OFF_MIN_DAMAGE", 4.0, 0.0, Double.MAX_VALUE)
val FLY_OFF_MAX_DAMAGE: Double by builder
.comment("When hammer flies off hands, what is maximal damage it deals to the user (in half of hearts)?")
.defineInRange("FLY_OFF_MAX_DAMAGE", 25.0, 0.0, Double.MAX_VALUE)
}
init {
builder.push("ExplosiveHammer")
ExplosiveHammer
builder.pop()
}
} }

View File

@ -8,4 +8,76 @@ object ToolsConfig : AbstractConfig("tools") {
init { init {
EnergySwordItem.registerConfig(builder) EnergySwordItem.registerConfig(builder)
} }
object ExplosiveHammer {
val MAX_TRAVEL: Double by builder
.comment("Max distance, in blocks, the nail can travel", "This also dictates potential max damage nail can deal (controlled by TRAVEL_DAMAGE_MULT)")
.comment("The nail penetrate through blocks and entities, losing power in process")
.comment("The nail can not travel into unloaded chunks and will stop immediately if it does so")
.comment("The nail travels its entire path instantaneously")
.defineInRange("MAX_TRAVEL", 48.0, 0.0, Double.MAX_VALUE)
val TRAVEL_EXPLOSION_RESIST_MULT: Double by builder
.comment("Multiplier of explosion resistance of blocks on nail path")
.comment("If explosion resistance multiplied by this is bigger than nail current force (base of MAX_TRAVEL)")
.comment("then nail movement halts, otherwise nail force is reduced by explosion resistance multiplied by this")
.comment("and block is broken (if DAMAGE_BLOCKS is true, otherwise it only acts as stopping power)")
.comment("---")
.comment("Values over 1 will make blocks more resistant to be penetrated through (and broken)")
.comment("Values below 1 will make blocks less resistant to be penetrated though (and broken)")
.comment("Value of 0 means no matter how strong block resistance is, it will be broken by nail", "(this includes bedrock!!!)")
.comment("---")
.defineInRange("TRAVEL_EXPLOSION_RESIST_MULT", 1.75, 0.0, Double.MAX_VALUE)
val TRAVEL_DAMAGE_MULT: Double by builder
.comment("Multiplier of current nail force (base of MAX_TRAVEL) for damage values")
.comment("That is, any being on path of nail will get damaged by nail power multiplied by this")
.defineInRange("TRAVEL_DAMAGE_MULT", 0.6, 0.0, Double.MAX_VALUE)
val TRAVEL_MAX_HEALTH_MULT: Double by builder
.comment("Multiplier of being's max health in nail path subtracted from nail force when penetrating through")
.defineInRange("TRAVEL_MAX_HEALTH_MULT", 0.4, 0.0, Double.MAX_VALUE)
val DAMAGE_BLOCKS: Boolean by builder
.comment("Should hammer (**not** explosion) damage blocks", "Blocks damaged this way will always be dropped")
.define("DAMAGE_BLOCKS", true)
val EXPLOSION_DAMAGE_BLOCKS: Boolean by builder
.comment("Should hammer **explosion** damage blocks")
.define("EXPLOSION_DAMAGE_BLOCKS", false)
val FLY_OFF_CHANCE: Double by builder
.comment("Chance that hammer will fly off hands of attacker upon impact")
.defineInRange("FLY_OFF_CHANCE", 0.6, 0.0, 1.0)
val SELF_HARM_CHANCE: Double by builder
.comment("When hammer DOES NOT fly off hands, what is chance of it damaging the user?", "(this does not account for damage because of hitting things close)", "(idiot)")
.defineInRange("SELF_HARM_CHANCE", 0.4, 0.0, 1.0)
val SELF_HARM_MIN_DAMAGE: Double by builder
.comment("When hammer DOES NOT fly off hands, what is minimal damage it deals to the user (in half of hearts)?")
.defineInRange("SELF_HARM_MIN_DAMAGE", 2.0, 0.0, Double.MAX_VALUE)
val SELF_HARM_MAX_DAMAGE: Double by builder
.comment("When hammer DOES NOT fly off hands, what is maximal damage it deals to the user (in half of hearts)?")
.defineInRange("SELF_HARM_MAX_DAMAGE", 10.0, 0.0, Double.MAX_VALUE)
val FLY_OFF_DAMAGE_CHANCE: Double by builder
.comment("When hammer flies off hands, what is chance of it damaging the user?")
.defineInRange("FLY_OFF_DAMAGE_CHANCE", 0.8, 0.0, 1.0)
val FLY_OFF_MIN_DAMAGE: Double by builder
.comment("When hammer flies off hands, what is minimal damage it deals to the user (in half of hearts)?")
.defineInRange("FLY_OFF_MIN_DAMAGE", 4.0, 0.0, Double.MAX_VALUE)
val FLY_OFF_MAX_DAMAGE: Double by builder
.comment("When hammer flies off hands, what is maximal damage it deals to the user (in half of hearts)?")
.defineInRange("FLY_OFF_MAX_DAMAGE", 25.0, 0.0, Double.MAX_VALUE)
}
init {
builder.push("ExplosiveHammer")
ExplosiveHammer
builder.pop()
}
} }

View File

@ -24,6 +24,7 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent
import net.minecraftforge.event.level.BlockEvent import net.minecraftforge.event.level.BlockEvent
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity
import ru.dbotthepony.mc.otm.config.ItemsConfig import ru.dbotthepony.mc.otm.config.ItemsConfig
import ru.dbotthepony.mc.otm.config.ToolsConfig
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.damageType import ru.dbotthepony.mc.otm.core.damageType
import ru.dbotthepony.mc.otm.core.getExplosionResistance import ru.dbotthepony.mc.otm.core.getExplosionResistance
@ -70,18 +71,18 @@ class ExplosiveHammerItem(durability: Int = 64) : Item(Properties().stacksTo(1).
val (ex, ey, ez) = pos val (ex, ey, ez) = pos
// взрыв в месте удара молотком // взрыв в месте удара молотком
val exp = Explosion(attacker.level, attacker, ex, ey, ez, 1f, false, if (ItemsConfig.ExplosiveHammer.EXPLOSION_DAMAGE_BLOCKS) Explosion.BlockInteraction.DESTROY_WITH_DECAY else Explosion.BlockInteraction.KEEP) val exp = Explosion(attacker.level, attacker, ex, ey, ez, 1f, false, if (ToolsConfig.ExplosiveHammer.EXPLOSION_DAMAGE_BLOCKS) Explosion.BlockInteraction.DESTROY_WITH_DECAY else Explosion.BlockInteraction.KEEP)
exp.explode() exp.explode()
exp.finalizeExplosion(true) exp.finalizeExplosion(true)
if (!ItemsConfig.ExplosiveHammer.EXPLOSION_DAMAGE_BLOCKS) if (!ToolsConfig.ExplosiveHammer.EXPLOSION_DAMAGE_BLOCKS)
exp.clearToBlow() exp.clearToBlow()
val level = attacker.level as ServerLevel val level = attacker.level as ServerLevel
val hitEntities = ObjectArraySet<LivingEntity>() val hitEntities = ObjectArraySet<LivingEntity>()
hitEntities.add(attacker) hitEntities.add(attacker)
var canTravel = ItemsConfig.ExplosiveHammer.MAX_TRAVEL var canTravel = ToolsConfig.ExplosiveHammer.MAX_TRAVEL
var rayPos = pos var rayPos = pos
var lastBlockPos: BlockPos? = null var lastBlockPos: BlockPos? = null
@ -97,12 +98,12 @@ class ExplosiveHammerItem(durability: Int = 64) : Item(Properties().stacksTo(1).
val block = level.getBlockState(blockPos) val block = level.getBlockState(blockPos)
if (!block.isAir) { if (!block.isAir) {
val resist = block.getExplosionResistance(level, blockPos) * ItemsConfig.ExplosiveHammer.TRAVEL_EXPLOSION_RESIST_MULT val resist = block.getExplosionResistance(level, blockPos) * ToolsConfig.ExplosiveHammer.TRAVEL_EXPLOSION_RESIST_MULT
if (resist >= 0.0) { if (resist >= 0.0) {
if (resist <= canTravel) { if (resist <= canTravel) {
canTravel -= resist canTravel -= resist
val cond = ItemsConfig.ExplosiveHammer.DAMAGE_BLOCKS && val cond = ToolsConfig.ExplosiveHammer.DAMAGE_BLOCKS &&
(attacker !is Player || level.mayInteract(attacker, blockPos) && !MinecraftForge.EVENT_BUS.post(BlockEvent.BreakEvent(level, blockPos, block, attacker))) (attacker !is Player || level.mayInteract(attacker, blockPos) && !MinecraftForge.EVENT_BUS.post(BlockEvent.BreakEvent(level, blockPos, block, attacker)))
if (cond) { if (cond) {
@ -122,8 +123,8 @@ class ExplosiveHammerItem(durability: Int = 64) : Item(Properties().stacksTo(1).
val damageSource = MatteryDamageSource(level.registryAccess().damageType(MDamageTypes.HAMMER_NAIL), attacker, itemStack) val damageSource = MatteryDamageSource(level.registryAccess().damageType(MDamageTypes.HAMMER_NAIL), attacker, itemStack)
for (it in entities) { for (it in entities) {
val damage = canTravel * ItemsConfig.ExplosiveHammer.TRAVEL_DAMAGE_MULT val damage = canTravel * ToolsConfig.ExplosiveHammer.TRAVEL_DAMAGE_MULT
canTravel -= it.maxHealth * ItemsConfig.ExplosiveHammer.TRAVEL_MAX_HEALTH_MULT canTravel -= it.maxHealth * ToolsConfig.ExplosiveHammer.TRAVEL_MAX_HEALTH_MULT
it.hurt(damageSource, damage.toFloat()) it.hurt(damageSource, damage.toFloat())
@ -152,7 +153,7 @@ class ExplosiveHammerItem(durability: Int = 64) : Item(Properties().stacksTo(1).
it.broadcastBreakEvent(hand) it.broadcastBreakEvent(hand)
} }
if (!itemStack.isEmpty && attacker.random.nextDouble() <= ItemsConfig.ExplosiveHammer.FLY_OFF_CHANCE) { if (!itemStack.isEmpty && attacker.random.nextDouble() <= ToolsConfig.ExplosiveHammer.FLY_OFF_CHANCE) {
attacker.setItemInHand(hand, ItemStack.EMPTY) attacker.setItemInHand(hand, ItemStack.EMPTY)
val (x, y, z) = attacker.position val (x, y, z) = attacker.position
@ -168,14 +169,14 @@ class ExplosiveHammerItem(durability: Int = 64) : Item(Properties().stacksTo(1).
attacker.level.addFreshEntity(entity) attacker.level.addFreshEntity(entity)
if (attacker.random.nextDouble() <= ItemsConfig.ExplosiveHammer.FLY_OFF_DAMAGE_CHANCE) { if (attacker.random.nextDouble() <= ToolsConfig.ExplosiveHammer.FLY_OFF_DAMAGE_CHANCE) {
attacker.invulnerableTime = 0 attacker.invulnerableTime = 0
val dmg = ItemsConfig.ExplosiveHammer.FLY_OFF_MIN_DAMAGE + attacker.random.nextDouble() * (ItemsConfig.ExplosiveHammer.FLY_OFF_MAX_DAMAGE - ItemsConfig.ExplosiveHammer.FLY_OFF_MIN_DAMAGE) val dmg = ToolsConfig.ExplosiveHammer.FLY_OFF_MIN_DAMAGE + attacker.random.nextDouble() * (ToolsConfig.ExplosiveHammer.FLY_OFF_MAX_DAMAGE - ToolsConfig.ExplosiveHammer.FLY_OFF_MIN_DAMAGE)
attacker.hurt(MatteryDamageSource(level.registryAccess().damageType(MDamageTypes.EXPLOSIVE_HAMMER), inflictor = copy), dmg.toFloat()) attacker.hurt(MatteryDamageSource(level.registryAccess().damageType(MDamageTypes.EXPLOSIVE_HAMMER), inflictor = copy), dmg.toFloat())
} }
} else if (attacker.random.nextDouble() <= ItemsConfig.ExplosiveHammer.SELF_HARM_CHANCE) { } else if (attacker.random.nextDouble() <= ToolsConfig.ExplosiveHammer.SELF_HARM_CHANCE) {
attacker.invulnerableTime = 0 attacker.invulnerableTime = 0
val dmg = ItemsConfig.ExplosiveHammer.SELF_HARM_MIN_DAMAGE + attacker.random.nextDouble() * (ItemsConfig.ExplosiveHammer.SELF_HARM_MAX_DAMAGE - ItemsConfig.ExplosiveHammer.SELF_HARM_MIN_DAMAGE) val dmg = ToolsConfig.ExplosiveHammer.SELF_HARM_MIN_DAMAGE + attacker.random.nextDouble() * (ToolsConfig.ExplosiveHammer.SELF_HARM_MAX_DAMAGE - ToolsConfig.ExplosiveHammer.SELF_HARM_MIN_DAMAGE)
attacker.hurt(MatteryDamageSource(level.registryAccess().damageType(MDamageTypes.EXPLOSIVE_HAMMER), inflictor = copy), dmg.toFloat()) attacker.hurt(MatteryDamageSource(level.registryAccess().damageType(MDamageTypes.EXPLOSIVE_HAMMER), inflictor = copy), dmg.toFloat())
} }
} }