mirror of
https://github.com/chylex/Hardcore-Ender-Expansion-2.git
synced 2025-03-16 11:15:42 +01:00
Refactor damage handling, implement fallback damage, tweak fire damage to set fire even if protected
This commit is contained in:
parent
d901f1b2f4
commit
280d4ecaf3
src/main/java/chylex/hee/game
@ -7,15 +7,15 @@ import chylex.hee.game.block.properties.BlockBuilder
|
||||
import chylex.hee.game.block.properties.Property
|
||||
import chylex.hee.game.entity.CustomCreatureType
|
||||
import chylex.hee.game.entity.living.IImmuneToCorruptedEnergy
|
||||
import chylex.hee.game.mechanics.damage.CombinedDamage
|
||||
import chylex.hee.game.mechanics.damage.Damage
|
||||
import chylex.hee.game.mechanics.damage.Damage.Companion.TITLE_MAGIC
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer.Companion.TITLE_MAGIC
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.ARMOR_PROTECTION
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.DIFFICULTY_SCALING
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.ENCHANTMENT_PROTECTION
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.MAGIC_TYPE
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.NUDITY_DANGER
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.RAPID_DAMAGE
|
||||
import chylex.hee.game.mechanics.damage.special.CombinedDamage
|
||||
import chylex.hee.game.particle.ParticleCorruptedEnergy
|
||||
import chylex.hee.game.particle.spawner.ParticleSpawnerCustom
|
||||
import chylex.hee.game.particle.spawner.properties.IOffset.InBox
|
||||
|
@ -2,6 +2,7 @@ package chylex.hee.game.block
|
||||
import chylex.hee.client.render.block.IBlockLayerCutout
|
||||
import chylex.hee.game.block.properties.BlockBuilder
|
||||
import chylex.hee.game.mechanics.damage.Damage
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer.Companion.TITLE_IN_FIRE
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.ALL_PROTECTIONS
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.FIRE_TYPE
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.PEACEFUL_EXCLUSION
|
||||
@ -119,7 +120,7 @@ class BlockEternalFire(builder: BlockBuilder) : BlockFire(builder.p), IBlockLaye
|
||||
}
|
||||
|
||||
override fun onEntityCollision(state: BlockState, world: World, pos: BlockPos, entity: Entity){
|
||||
DAMAGE_CONTACT.dealTo(1F, entity, Damage.TITLE_IN_FIRE)
|
||||
DAMAGE_CONTACT.dealTo(1F, entity, TITLE_IN_FIRE)
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -2,6 +2,7 @@ package chylex.hee.game.block
|
||||
import chylex.hee.game.block.properties.BlockBuilder
|
||||
import chylex.hee.game.inventory.doDamage
|
||||
import chylex.hee.game.mechanics.damage.Damage
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer.Companion.TITLE_IN_FIRE
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.FIRE_TYPE
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.PEACEFUL_EXCLUSION
|
||||
import chylex.hee.game.particle.spawner.ParticleSpawnerVanilla
|
||||
@ -68,7 +69,7 @@ class BlockIgneousRockOre(builder: BlockBuilder) : BlockSimple(builder){
|
||||
val heldItem = player.getHeldItem(MAIN_HAND)
|
||||
|
||||
if ((getToolHarvestLevel(heldItem) ?: 0) < super.getHarvestLevel(state) || EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItem(MAIN_HAND)) == 0){
|
||||
DAMAGE_MINING.dealTo(2F, player, Damage.TITLE_IN_FIRE)
|
||||
DAMAGE_MINING.dealTo(2F, player, TITLE_IN_FIRE)
|
||||
}
|
||||
|
||||
return super.removedByPlayer(state, world, pos, player, willHarvest, fluid)
|
||||
|
@ -4,7 +4,7 @@ import chylex.hee.game.entity.Teleporter.FxRange.Extended
|
||||
import chylex.hee.game.entity.Teleporter.FxRange.Normal
|
||||
import chylex.hee.game.entity.Teleporter.FxRange.Silent
|
||||
import chylex.hee.game.mechanics.damage.Damage
|
||||
import chylex.hee.game.mechanics.damage.Damage.Companion.TITLE_FALL
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer.Companion.TITLE_FALL
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.MAGIC_TYPE
|
||||
import chylex.hee.game.mechanics.instability.Instability
|
||||
import chylex.hee.game.particle.ParticleTeleport
|
||||
|
@ -4,7 +4,7 @@ import chylex.hee.game.entity.item.EntityFallingBlockHeavy.PlacementResult.RELOC
|
||||
import chylex.hee.game.entity.item.EntityFallingBlockHeavy.PlacementResult.SUCCESS
|
||||
import chylex.hee.game.entity.selectVulnerableEntities
|
||||
import chylex.hee.game.mechanics.damage.Damage
|
||||
import chylex.hee.game.mechanics.damage.Damage.Companion.TITLE_FALLING_BLOCK
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer.Companion.TITLE_FALLING_BLOCK
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.ARMOR_PROTECTION
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.ENCHANTMENT_PROTECTION
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.PEACEFUL_EXCLUSION
|
||||
|
@ -2,6 +2,7 @@ package chylex.hee.game.item
|
||||
import chylex.hee.game.entity.Teleporter
|
||||
import chylex.hee.game.entity.posVec
|
||||
import chylex.hee.game.mechanics.damage.Damage
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer.Companion.TITLE_MAGIC
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.MAGIC_TYPE
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.PEACEFUL_EXCLUSION
|
||||
import chylex.hee.game.potion.makeEffect
|
||||
@ -107,7 +108,7 @@ class ItemChorusBerry(properties: Properties) : Item(properties){
|
||||
}
|
||||
|
||||
if (!teleportEntity(entity, hungerOvercharge, rand)){
|
||||
DAMAGE_TELEPORT_FAIL.dealTo(1F, entity, Damage.TITLE_MAGIC)
|
||||
DAMAGE_TELEPORT_FAIL.dealTo(1F, entity, TITLE_MAGIC)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import chylex.hee.game.entity.heeTagOrNull
|
||||
import chylex.hee.game.inventory.heeTag
|
||||
import chylex.hee.game.inventory.heeTagOrNull
|
||||
import chylex.hee.game.mechanics.damage.Damage
|
||||
import chylex.hee.game.mechanics.damage.Damage.Companion.TITLE_STARVE
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer.Companion.TITLE_STARVE
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.MAGIC_TYPE
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.NON_LETHAL
|
||||
import chylex.hee.game.potion.makeEffect
|
||||
|
@ -1,11 +1,8 @@
|
||||
package chylex.hee.game.mechanics.damage
|
||||
import chylex.hee.system.migration.EntityLivingBase
|
||||
import chylex.hee.system.migration.EntityPlayer
|
||||
import chylex.hee.system.migration.EntityThrowable
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer.Companion.CANCEL_DAMAGE
|
||||
import net.minecraft.entity.Entity
|
||||
import net.minecraft.entity.SharedMonsterAttributes.ATTACK_DAMAGE
|
||||
|
||||
class Damage(private vararg val processors: IDamageProcessor){
|
||||
class Damage(private vararg val processors: IDamageProcessor) : IDamageDealer{
|
||||
private val properties = DamageProperties().apply {
|
||||
val writer = Writer()
|
||||
processors.forEach { it.setup(writer) }
|
||||
@ -23,43 +20,15 @@ class Damage(private vararg val processors: IDamageProcessor){
|
||||
return true
|
||||
}
|
||||
|
||||
fun dealTo(amount: Float, target: Entity, title: String = TITLE_GENERIC) =
|
||||
override fun dealTo(amount: Float, target: Entity, title: String) =
|
||||
dealToInternal(amount, target, null, null, title)
|
||||
|
||||
fun dealToFrom(target: Entity, source: EntityLivingBase, title: String = determineTitleDirect(source)) =
|
||||
dealToInternal(source.getAttribute(ATTACK_DAMAGE).value.toFloat(), target, source, source, title)
|
||||
|
||||
fun dealToFrom(amount: Float, target: Entity, source: Entity, title: String = determineTitleDirect(source)) =
|
||||
override fun dealToFrom(amount: Float, target: Entity, source: Entity, title: String) =
|
||||
dealToInternal(amount, target, source, source, title)
|
||||
|
||||
fun dealToIndirectly(amount: Float, target: Entity, directSource: Entity, remoteSource: Entity?, title: String = determineTitleIndirect(directSource, remoteSource)) =
|
||||
override fun dealToIndirectly(amount: Float, target: Entity, directSource: Entity, remoteSource: Entity?, title: String) =
|
||||
dealToInternal(amount, target, directSource, remoteSource, title)
|
||||
|
||||
companion object{
|
||||
const val CANCEL_DAMAGE = 0F
|
||||
|
||||
const val TITLE_GENERIC = "generic"
|
||||
const val TITLE_PLAYER = "player"
|
||||
const val TITLE_MOB = "mob"
|
||||
const val TITLE_THROWN = "thrown"
|
||||
|
||||
const val TITLE_MAGIC = "magic"
|
||||
const val TITLE_FALL = "fall"
|
||||
const val TITLE_STARVE = "starve"
|
||||
const val TITLE_WITHER = "wither"
|
||||
const val TITLE_IN_FIRE = "inFire"
|
||||
const val TITLE_FALLING_BLOCK = "fallingBlock"
|
||||
|
||||
fun determineTitleDirect(source: Entity?) = when(source){
|
||||
is EntityPlayer -> TITLE_PLAYER
|
||||
null -> TITLE_GENERIC
|
||||
else -> TITLE_MOB
|
||||
}
|
||||
|
||||
fun determineTitleIndirect(directSource: Entity, remoteSource: Entity?) = when(directSource){
|
||||
is EntityThrowable -> TITLE_THROWN
|
||||
else -> determineTitleDirect(remoteSource)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,44 @@
|
||||
package chylex.hee.game.mechanics.damage
|
||||
import chylex.hee.system.migration.EntityLivingBase
|
||||
import chylex.hee.system.migration.EntityPlayer
|
||||
import chylex.hee.system.migration.EntityThrowable
|
||||
import net.minecraft.entity.Entity
|
||||
import net.minecraft.entity.SharedMonsterAttributes.ATTACK_DAMAGE
|
||||
|
||||
interface IDamageDealer{
|
||||
fun dealTo(amount: Float, target: Entity, title: String = TITLE_GENERIC): Boolean
|
||||
fun dealToFrom(amount: Float, target: Entity, source: Entity, title: String = determineTitleDirect(source)): Boolean
|
||||
fun dealToIndirectly(amount: Float, target: Entity, directSource: Entity, remoteSource: Entity?, title: String = determineTitleIndirect(directSource, remoteSource)): Boolean
|
||||
|
||||
@JvmDefault
|
||||
fun dealToFrom(target: Entity, source: EntityLivingBase, title: String = determineTitleDirect(source)): Boolean{
|
||||
return dealToFrom(source.getAttribute(ATTACK_DAMAGE).value.toFloat(), target, source, title)
|
||||
}
|
||||
|
||||
companion object{
|
||||
const val CANCEL_DAMAGE = 0F
|
||||
|
||||
const val TITLE_GENERIC = "generic"
|
||||
const val TITLE_PLAYER = "player"
|
||||
const val TITLE_MOB = "mob"
|
||||
const val TITLE_THROWN = "thrown"
|
||||
|
||||
const val TITLE_MAGIC = "magic"
|
||||
const val TITLE_FALL = "fall"
|
||||
const val TITLE_STARVE = "starve"
|
||||
const val TITLE_WITHER = "wither"
|
||||
const val TITLE_IN_FIRE = "inFire"
|
||||
const val TITLE_FALLING_BLOCK = "fallingBlock"
|
||||
|
||||
fun determineTitleDirect(source: Entity?) = when(source){
|
||||
is EntityPlayer -> TITLE_PLAYER
|
||||
null -> TITLE_GENERIC
|
||||
else -> TITLE_MOB
|
||||
}
|
||||
|
||||
fun determineTitleIndirect(directSource: Entity, remoteSource: Entity?) = when(directSource){
|
||||
is EntityThrowable -> TITLE_THROWN
|
||||
else -> determineTitleDirect(remoteSource)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package chylex.hee.game.mechanics.damage
|
||||
import chylex.hee.game.entity.setFireTicks
|
||||
import chylex.hee.game.mechanics.damage.Damage.Companion.CANCEL_DAMAGE
|
||||
import chylex.hee.game.mechanics.damage.DamageProperties.Reader
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer.Companion.CANCEL_DAMAGE
|
||||
import chylex.hee.system.migration.EntityLivingBase
|
||||
import chylex.hee.system.migration.EntityPlayer
|
||||
import chylex.hee.system.migration.ItemArmor
|
||||
@ -32,12 +33,16 @@ interface IDamageProcessor{
|
||||
|
||||
@JvmStatic
|
||||
fun FIRE_TYPE(setOnFireTicks: Int = 0) = object : IDamageProcessor{
|
||||
override fun setup(properties: DamageProperties.Writer) = properties.addType(DamageType.FIRE)
|
||||
override fun setup(properties: DamageProperties.Writer){
|
||||
properties.addType(DamageType.FIRE)
|
||||
}
|
||||
|
||||
override fun afterDamage(target: Entity, properties: DamageProperties.Reader){
|
||||
override fun modifyDamage(amount: Float, target: Entity, properties: Reader): Float{
|
||||
if (setOnFireTicks > 0){
|
||||
target.setFireTicks(setOnFireTicks)
|
||||
}
|
||||
|
||||
return super.modifyDamage(amount, target, properties)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
package chylex.hee.game.mechanics.damage
|
||||
import chylex.hee.game.mechanics.damage.Damage.Companion.TITLE_GENERIC
|
||||
package chylex.hee.game.mechanics.damage.special
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer.Companion.TITLE_GENERIC
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer.Companion.determineTitleDirect
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer.Companion.determineTitleIndirect
|
||||
import chylex.hee.system.migration.EntityLivingBase
|
||||
import net.minecraft.entity.Entity
|
||||
|
||||
class CombinedDamage(private vararg val definitions: Pair<Damage, Float>){
|
||||
class CombinedDamage(private vararg val definitions: Pair<IDamageDealer, Float>){
|
||||
private fun shouldPreventDamage(target: Entity): Boolean{
|
||||
if (target is EntityLivingBase && target.hurtResistantTime > (target.maxHurtResistantTime / 2F)){
|
||||
val lastDamage = target.lastDamage
|
||||
@ -16,7 +19,7 @@ class CombinedDamage(private vararg val definitions: Pair<Damage, Float>){
|
||||
return false
|
||||
}
|
||||
|
||||
private inline fun dealToInternal(target: Entity, damageCall: (Pair<Damage, Float>) -> Boolean): Boolean{
|
||||
private inline fun dealToInternal(target: Entity, damageCall: (Pair<IDamageDealer, Float>) -> Boolean): Boolean{
|
||||
if (shouldPreventDamage(target)){
|
||||
return false
|
||||
}
|
||||
@ -39,9 +42,9 @@ class CombinedDamage(private vararg val definitions: Pair<Damage, Float>){
|
||||
fun dealTo(target: Entity, title: String = TITLE_GENERIC) =
|
||||
dealToInternal(target){ (damage, amount) -> damage.dealTo(amount, target, title) }
|
||||
|
||||
fun dealToFrom(target: Entity, source: Entity, title: String = Damage.determineTitleDirect(source)) =
|
||||
fun dealToFrom(target: Entity, source: Entity, title: String = determineTitleDirect(source)) =
|
||||
dealToInternal(target){ (damage, amount) -> damage.dealToFrom(amount, target, source, title) }
|
||||
|
||||
fun dealToIndirectly(target: Entity, triggeringSource: Entity, remoteSource: Entity, title: String = Damage.determineTitleIndirect(triggeringSource, remoteSource)) =
|
||||
fun dealToIndirectly(target: Entity, triggeringSource: Entity, remoteSource: Entity, title: String = determineTitleIndirect(triggeringSource, remoteSource)) =
|
||||
dealToInternal(target){ (damage, amount) -> damage.dealToIndirectly(amount, target, triggeringSource, remoteSource, title) }
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package chylex.hee.game.mechanics.damage.special
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer
|
||||
import net.minecraft.entity.Entity
|
||||
|
||||
class FallbackDamage(private vararg val definitions: Pair<IDamageDealer, Double>) : IDamageDealer {
|
||||
private inline fun dealToInternal(amount: Float, damageCall: (IDamageDealer, Float) -> Boolean): Boolean{
|
||||
for(definition in definitions){
|
||||
if (damageCall(definition.first, (amount * definition.second).toFloat())){
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
override fun dealTo(amount: Float, target: Entity, title: String) =
|
||||
dealToInternal(amount){ damage, adjustedAmount -> damage.dealTo(adjustedAmount, target, title) }
|
||||
|
||||
override fun dealToFrom(amount: Float, target: Entity, source: Entity, title: String) =
|
||||
dealToInternal(amount){ damage, adjustedAmount -> damage.dealToFrom(adjustedAmount, target, source, title) }
|
||||
|
||||
override fun dealToIndirectly(amount: Float, target: Entity, directSource: Entity, remoteSource: Entity?, title: String) =
|
||||
dealToInternal(amount){ damage, adjustedAmount -> damage.dealToIndirectly(adjustedAmount, target, directSource, remoteSource, title) }
|
||||
}
|
@ -5,7 +5,7 @@ import chylex.hee.game.block.BlockAbstractPortal
|
||||
import chylex.hee.game.entity.heeTag
|
||||
import chylex.hee.game.entity.posVec
|
||||
import chylex.hee.game.mechanics.damage.Damage
|
||||
import chylex.hee.game.mechanics.damage.Damage.Companion.TITLE_WITHER
|
||||
import chylex.hee.game.mechanics.damage.IDamageDealer.Companion.TITLE_WITHER
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.DEAL_CREATIVE
|
||||
import chylex.hee.game.mechanics.damage.IDamageProcessor.Companion.IGNORE_INVINCIBILITY
|
||||
import chylex.hee.game.particle.ParticleFadingSpot
|
||||
|
Loading…
Reference in New Issue
Block a user