Skip to content

implement totem ignoring for damage source #1066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/block/cactus.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ type DamageSource struct {
func (DamageSource) ReducedByResistance() bool { return true }
func (DamageSource) ReducedByArmour() bool { return true }
func (DamageSource) Fire() bool { return false }
func (DamageSource) IgnoreTotem() bool { return false }
1 change: 1 addition & 0 deletions server/block/fire.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,4 @@ func (FireDamageSource) Fire() bool { return true }
func (FireDamageSource) AffectedByEnchantment(e item.EnchantmentType) bool {
return e == enchantment.FireProtection
}
func (FireDamageSource) IgnoreTotem() bool { return false }
1 change: 1 addition & 0 deletions server/block/lava.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,4 @@ type LavaDamageSource struct{}
func (LavaDamageSource) ReducedByResistance() bool { return true }
func (LavaDamageSource) ReducedByArmour() bool { return true }
func (LavaDamageSource) Fire() bool { return true }
func (LavaDamageSource) IgnoreTotem() bool { return false }
9 changes: 9 additions & 0 deletions server/entity/damage.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,42 @@ func (FallDamageSource) Fire() bool { return false }
func (FallDamageSource) AffectedByEnchantment(e item.EnchantmentType) bool {
return e == enchantment.FeatherFalling
}
func (FallDamageSource) IgnoreTotem() bool { return false }
func (GlideDamageSource) ReducedByArmour() bool { return false }
func (GlideDamageSource) ReducedByResistance() bool { return true }
func (GlideDamageSource) Fire() bool { return false }
func (GlideDamageSource) IgnoreTotem() bool { return false }
func (LightningDamageSource) ReducedByArmour() bool { return true }
func (LightningDamageSource) ReducedByResistance() bool { return true }
func (LightningDamageSource) Fire() bool { return false }
func (LightningDamageSource) IgnoreTotem() bool { return false }
func (AttackDamageSource) ReducedByArmour() bool { return true }
func (AttackDamageSource) ReducedByResistance() bool { return true }
func (AttackDamageSource) Fire() bool { return false }
func (AttackDamageSource) IgnoreTotem() bool { return false }
func (VoidDamageSource) ReducedByResistance() bool { return false }
func (VoidDamageSource) ReducedByArmour() bool { return false }
func (VoidDamageSource) Fire() bool { return false }
func (VoidDamageSource) IgnoreTotem() bool { return true }
func (SuffocationDamageSource) ReducedByResistance() bool { return false }
func (SuffocationDamageSource) ReducedByArmour() bool { return false }
func (SuffocationDamageSource) Fire() bool { return false }
func (SuffocationDamageSource) IgnoreTotem() bool { return false }
func (DrowningDamageSource) ReducedByResistance() bool { return false }
func (DrowningDamageSource) ReducedByArmour() bool { return false }
func (DrowningDamageSource) Fire() bool { return false }
func (DrowningDamageSource) IgnoreTotem() bool { return false }
func (ProjectileDamageSource) ReducedByResistance() bool { return true }
func (ProjectileDamageSource) ReducedByArmour() bool { return true }
func (ProjectileDamageSource) Fire() bool { return false }
func (ProjectileDamageSource) AffectedByEnchantment(e item.EnchantmentType) bool {
return e == enchantment.ProjectileProtection
}
func (ProjectileDamageSource) IgnoreTotem() bool { return false }
func (ExplosionDamageSource) ReducedByResistance() bool { return true }
func (ExplosionDamageSource) ReducedByArmour() bool { return true }
func (ExplosionDamageSource) Fire() bool { return false }
func (ExplosionDamageSource) AffectedByEnchantment(e item.EnchantmentType) bool {
return e == enchantment.BlastProtection
}
func (ExplosionDamageSource) IgnoreTotem() bool { return false }
1 change: 1 addition & 0 deletions server/entity/effect/instant_damage.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ type InstantDamageSource struct{}
func (InstantDamageSource) ReducedByArmour() bool { return false }
func (InstantDamageSource) ReducedByResistance() bool { return true }
func (InstantDamageSource) Fire() bool { return false }
func (InstantDamageSource) IgnoreTotem() bool { return false }
1 change: 1 addition & 0 deletions server/entity/effect/poison.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ type PoisonDamageSource struct {
func (PoisonDamageSource) ReducedByResistance() bool { return true }
func (PoisonDamageSource) ReducedByArmour() bool { return false }
func (PoisonDamageSource) Fire() bool { return false }
func (PoisonDamageSource) IgnoreTotem() bool { return false }
1 change: 1 addition & 0 deletions server/entity/effect/wither.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ type WitherDamageSource struct{}
func (WitherDamageSource) ReducedByResistance() bool { return true }
func (WitherDamageSource) ReducedByArmour() bool { return false }
func (WitherDamageSource) Fire() bool { return false }
func (WitherDamageSource) IgnoreTotem() bool { return false }
1 change: 1 addition & 0 deletions server/item/enchantment/thorns.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ type ThornsDamageSource struct {
func (ThornsDamageSource) ReducedByResistance() bool { return true }
func (ThornsDamageSource) ReducedByArmour() bool { return false }
func (ThornsDamageSource) Fire() bool { return false }
func (ThornsDamageSource) IgnoreTotem() bool { return false }
1 change: 1 addition & 0 deletions server/player/hunger.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,4 @@ type StarvationDamageSource struct{}
func (StarvationDamageSource) ReducedByArmour() bool { return false }
func (StarvationDamageSource) ReducedByResistance() bool { return false }
func (StarvationDamageSource) Fire() bool { return false }
func (StarvationDamageSource) IgnoreTotem() bool { return false }
2 changes: 1 addition & 1 deletion server/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ func (p *Player) Hurt(dmg float64, src world.DamageSource) (float64, bool) {
damageLeft = max(0, damageLeft-a)
}

if p.Health()-damageLeft <= mgl64.Epsilon {
if p.Health()-damageLeft <= mgl64.Epsilon && !src.IgnoreTotem() {
hand, offHand := p.HeldItems()
if _, ok := offHand.Item().(item.Totem); ok {
p.applyTotemEffects()
Expand Down
2 changes: 2 additions & 0 deletions server/world/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ type DamageSource interface {
// Fire specifies if the Source is fire related and should be ignored when
// an Entity has the fire resistance effect.
Fire() bool
// IgnoreTotem specifies whether the totem will be ignored if the damage is lethal.
IgnoreTotem() bool
}

// HealingSource represents a source of healing for an Entity. This source may
Expand Down