Skip to content

Commit

Permalink
block: Added blast resistances for each block.
Browse files Browse the repository at this point in the history
  • Loading branch information
JustTalDevelops committed Jul 15, 2022
1 parent 4a3db7d commit fd081cf
Show file tree
Hide file tree
Showing 58 changed files with 169 additions and 144 deletions.
2 changes: 1 addition & 1 deletion server/block/ancient_debris.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type AncientDebris struct {
func (a AncientDebris) BreakInfo() BreakInfo {
return newBreakInfo(30, func(t item.Tool) bool {
return t.ToolType() == item.TypePickaxe && t.HarvestLevel() >= item.ToolTierDiamond.HarvestLevel
}, pickaxeEffective, oneOf(a))
}, pickaxeEffective, oneOf(a)).withBlastResistance(3600)
}

// EncodeItem ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/anvil.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (a Anvil) Model() world.BlockModel {

// BreakInfo ...
func (a Anvil) BreakInfo() BreakInfo {
return newBreakInfo(5, pickaxeHarvestable, pickaxeEffective, oneOf(a))
return newBreakInfo(5, pickaxeHarvestable, pickaxeEffective, oneOf(a)).withBlastResistance(6000)
}

// Activate ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/basalt.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (b Basalt) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.

// BreakInfo ...
func (b Basalt) BreakInfo() BreakInfo {
return newBreakInfo(1.25, pickaxeHarvestable, pickaxeEffective, oneOf(b))
return newBreakInfo(1.25, pickaxeHarvestable, pickaxeEffective, oneOf(b)).withBlastResistance(21)
}

// EncodeItem ...
Expand Down
5 changes: 0 additions & 5 deletions server/block/bedrock.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ type Bedrock struct {
InfiniteBurning bool
}

// BreakInfo ...
func (b Bedrock) BreakInfo() BreakInfo {
return newBreakInfo(-1, neverHarvestable, nothingEffective, simpleDrops()).withBlastResistance(0.6)
}

// EncodeItem ...
func (Bedrock) EncodeItem() (name string, meta int16) {
return "minecraft:bedrock", 0
Expand Down
37 changes: 2 additions & 35 deletions server/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package block
import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/entity/damage"
"github.com/df-mc/dragonfly/server/entity/effect"
"github.com/df-mc/dragonfly/server/entity/healing"
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/world"
"github.com/df-mc/dragonfly/server/world/sound"
Expand Down Expand Up @@ -245,17 +243,9 @@ func newFlammabilityInfo(encouragement, flammability int, lavaFlammable bool) Fl
}
}

// livingEntity ...
type livingEntity interface {
world.Entity
// Health returns the health of the entity.
Health() float64
// MaxHealth returns the maximum health of the entity.
MaxHealth() float64
// SetMaxHealth changes the maximum health of the entity to the value passed.
SetMaxHealth(v float64)
// Dead checks if the entity is considered dead. True is returned if the health of the entity is equal to or
// lower than 0.
Dead() bool
// AttackImmune checks if the entity is currently immune to entity attacks. Entities typically turn
// immune for half a second after being attacked.
AttackImmune() bool
Expand All @@ -265,33 +255,10 @@ type livingEntity interface {
// Hurt returns the final amount of damage dealt to the Living entity and returns whether the Living entity
// was vulnerable to the damage at all.
Hurt(damage float64, src damage.Source) (n float64, vulnerable bool)
// Heal heals the entity for a given amount of health. The source passed represents the cause of the
// healing, for example healing.SourceFood if the entity healed by having a full food bar. If the health
// added to the original health exceeds the entity's max health, Heal may not add the full amount.
Heal(health float64, src healing.Source)
// KnockBack knocks the entity back with a given force and height. A source is passed which indicates the
// source of the velocity, typically the position of an attacking entity. The source is used to calculate
// the direction which the entity should be knocked back in.
KnockBack(src mgl64.Vec3, force, height float64)
// AddEffect adds an entity.Effect to the entity. If the effect is instant, it is applied to the entity
// immediately. If not, the effect is applied to the entity every time the Tick method is called.
// AddEffect will overwrite any effects present if the level of the effect is higher than the existing one, or
// if the effects' levels are equal and the new effect has a longer duration.
AddEffect(e effect.Effect)
// RemoveEffect removes any effect that might currently be active on the entity.
RemoveEffect(e effect.Type)
// Effects returns any effect currently applied to the entity. The returned effects are guaranteed not to have
// expired when returned.
Effects() []effect.Effect
// Speed returns the current speed of the living entity. The default value is different for each entity.
Speed() float64
// SetSpeed sets the speed of an entity to a new value.
SetSpeed(float64)
}

// flammableEntity ...
type flammableEntity interface {
// FireProof is whether the entity is currently fireproof.
FireProof() bool
// OnFireDuration returns duration of fire in ticks.
OnFireDuration() time.Duration
// SetOnFire sets the entity on fire for the specified duration.
Expand Down
15 changes: 9 additions & 6 deletions server/block/break_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,20 @@ type BreakInfo struct {
Drops func(t item.Tool, enchantments []item.Enchantment) []item.Stack
// XPDrops is the range of XP a block can drop when broken.
XPDrops XPDropRange
// BlastResistance ...
// BlastResistance is the blast resistance of the block, which influences the block's ability to withstand an
// explosive blast.
BlastResistance float64
}

// newBreakInfo creates a BreakInfo struct with the properties passed. The XPDrops field is 0 by default.
// newBreakInfo creates a BreakInfo struct with the properties passed. The XPDrops field is 0 by default. The blast
// resistance gets set to the hardness by default, as it usually is the same.
func newBreakInfo(hardness float64, harvestable func(item.Tool) bool, effective func(item.Tool) bool, drops func(item.Tool, []item.Enchantment) []item.Stack) BreakInfo {
return BreakInfo{
Hardness: hardness,
Harvestable: harvestable,
Effective: effective,
Drops: drops,
Hardness: hardness,
BlastResistance: hardness * 5, // Blast resistance is usually always just hardness multiplied by 5.
Harvestable: harvestable,
Effective: effective,
Drops: drops,
}
}

Expand Down
2 changes: 1 addition & 1 deletion server/block/bricks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Bricks struct {

// BreakInfo ...
func (b Bricks) BreakInfo() BreakInfo {
return newBreakInfo(2, pickaxeHarvestable, pickaxeEffective, oneOf(b))
return newBreakInfo(2, pickaxeHarvestable, pickaxeEffective, oneOf(b)).withBlastResistance(30)
}

// EncodeItem ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c Chain) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.W

// BreakInfo ...
func (c Chain) BreakInfo() BreakInfo {
return newBreakInfo(5, pickaxeHarvestable, pickaxeEffective, oneOf(c))
return newBreakInfo(5, pickaxeHarvestable, pickaxeEffective, oneOf(c)).withBlastResistance(15)
}

// EncodeItem ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/coal.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (c Coal) FlammabilityInfo() FlammabilityInfo {

// BreakInfo ...
func (c Coal) BreakInfo() BreakInfo {
return newBreakInfo(5, pickaxeHarvestable, pickaxeEffective, oneOf(c))
return newBreakInfo(5, pickaxeHarvestable, pickaxeEffective, oneOf(c)).withBlastResistance(30)
}

// EncodeItem ...
Expand Down
6 changes: 5 additions & 1 deletion server/block/coal_ore.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ type CoalOre struct {

// BreakInfo ...
func (c CoalOre) BreakInfo() BreakInfo {
return newBreakInfo(c.Type.Hardness(), pickaxeHarvestable, pickaxeEffective, silkTouchOneOf(item.Coal{}, c)).withXPDropRange(0, 2)
i := newBreakInfo(c.Type.Hardness(), pickaxeHarvestable, pickaxeEffective, silkTouchOneOf(item.Coal{}, c)).withXPDropRange(0, 2)
if c.Type == DeepslateOre() {
i = i.withBlastResistance(9)
}
return i
}

// EncodeItem ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/cobblestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Cobblestone struct {

// BreakInfo ...
func (c Cobblestone) BreakInfo() BreakInfo {
return newBreakInfo(2, pickaxeHarvestable, pickaxeEffective, oneOf(c))
return newBreakInfo(2, pickaxeHarvestable, pickaxeEffective, oneOf(c)).withBlastResistance(30)
}

// RepairsStoneTools ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/cobblestone_stairs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s CobblestoneStairs) Model() world.BlockModel {

// BreakInfo ...
func (s CobblestoneStairs) BreakInfo() BreakInfo {
return newBreakInfo(2, pickaxeHarvestable, pickaxeEffective, oneOf(s))
return newBreakInfo(2, pickaxeHarvestable, pickaxeEffective, oneOf(s)).withBlastResistance(30)
}

// EncodeItem ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/cocoa_bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c CocoaBean) BreakInfo() BreakInfo {
return []item.Stack{item.NewStack(c, rand.Intn(2)+2)}
}
return []item.Stack{item.NewStack(c, 1)}
})
}).withBlastResistance(15)
}

// EncodeItem ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/copper_ore.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type CopperOre struct {
func (c CopperOre) BreakInfo() BreakInfo {
return newBreakInfo(c.Type.Hardness(), func(t item.Tool) bool {
return t.ToolType() == item.TypePickaxe && t.HarvestLevel() >= item.ToolTierStone.HarvestLevel
}, pickaxeEffective, silkTouchDrop(item.NewStack(item.RawCopper{}, rand.Intn(4)+2), item.NewStack(c, 1)))
}, pickaxeEffective, silkTouchDrop(item.NewStack(item.RawCopper{}, rand.Intn(4)+2), item.NewStack(c, 1))).withBlastResistance(9)
}

// EncodeItem ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/coral_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c CoralBlock) ScheduledTick(pos cube.Pos, w *world.World, _ *rand.Rand) {

// BreakInfo ...
func (c CoralBlock) BreakInfo() BreakInfo {
return newBreakInfo(7, pickaxeHarvestable, pickaxeEffective, silkTouchOneOf(CoralBlock{Type: c.Type, Dead: true}, c))
return newBreakInfo(7, pickaxeHarvestable, pickaxeEffective, silkTouchOneOf(CoralBlock{Type: c.Type, Dead: true}, c)).withBlastResistance(4.5)
}

// EncodeBlock ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/diamond.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Diamond struct {
func (d Diamond) BreakInfo() BreakInfo {
return newBreakInfo(5, func(t item.Tool) bool {
return t.ToolType() == item.TypePickaxe && t.HarvestLevel() >= item.ToolTierIron.HarvestLevel
}, pickaxeEffective, oneOf(d))
}, pickaxeEffective, oneOf(d)).withBlastResistance(30)
}

// PowersBeacon ...
Expand Down
6 changes: 5 additions & 1 deletion server/block/diamond_ore.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ type DiamondOre struct {

// BreakInfo ...
func (d DiamondOre) BreakInfo() BreakInfo {
return newBreakInfo(d.Type.Hardness(), func(t item.Tool) bool {
i := newBreakInfo(d.Type.Hardness(), func(t item.Tool) bool {
return t.ToolType() == item.TypePickaxe && t.HarvestLevel() >= item.ToolTierIron.HarvestLevel
}, pickaxeEffective, silkTouchOneOf(item.Diamond{}, d)).withXPDropRange(3, 7)
if d.Type == DeepslateOre() {
i = i.withBlastResistance(9)
}
return i
}

// EncodeItem ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/dirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (d Dirt) SoilFor(block world.Block) bool {

// BreakInfo ...
func (d Dirt) BreakInfo() BreakInfo {
return newBreakInfo(0.5, alwaysHarvestable, shovelEffective, oneOf(d)).withBlastResistance(0.5)
return newBreakInfo(0.5, alwaysHarvestable, shovelEffective, oneOf(d))
}

// Till ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/dripstone.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Dripstone struct {

// BreakInfo ...
func (d Dripstone) BreakInfo() BreakInfo {
return newBreakInfo(1.5, pickaxeHarvestable, pickaxeEffective, oneOf(d))
return newBreakInfo(1.5, pickaxeHarvestable, pickaxeEffective, oneOf(d)).withBlastResistance(5)
}

// EncodeItem ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/emerald.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (e Emerald) Instrument() sound.Instrument {
func (e Emerald) BreakInfo() BreakInfo {
return newBreakInfo(5, func(t item.Tool) bool {
return t.ToolType() == item.TypePickaxe && t.HarvestLevel() >= item.ToolTierIron.HarvestLevel
}, pickaxeEffective, oneOf(e))
}, pickaxeEffective, oneOf(e)).withBlastResistance(30)
}

// PowersBeacon ...
Expand Down
6 changes: 5 additions & 1 deletion server/block/emerald_ore.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ type EmeraldOre struct {

// BreakInfo ...
func (e EmeraldOre) BreakInfo() BreakInfo {
return newBreakInfo(e.Type.Hardness(), func(t item.Tool) bool {
i := newBreakInfo(e.Type.Hardness(), func(t item.Tool) bool {
return t.ToolType() == item.TypePickaxe && t.HarvestLevel() >= item.ToolTierIron.HarvestLevel
}, pickaxeEffective, silkTouchOneOf(item.Emerald{}, e)).withXPDropRange(3, 7)
if e.Type == DeepslateOre() {
i = i.withBlastResistance(15)
}
return i
}

// EncodeItem ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/end_brick_stairs.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s EndBrickStairs) Model() world.BlockModel {

// BreakInfo ...
func (s EndBrickStairs) BreakInfo() BreakInfo {
return newBreakInfo(3, pickaxeHarvestable, pickaxeEffective, oneOf(s))
return newBreakInfo(3, pickaxeHarvestable, pickaxeEffective, oneOf(s)).withBlastResistance(30)
}

// EncodeItem ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/end_stone.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type EndStone struct {

// BreakInfo ...
func (e EndStone) BreakInfo() BreakInfo {
return newBreakInfo(3, pickaxeHarvestable, pickaxeEffective, oneOf(e))
return newBreakInfo(3, pickaxeHarvestable, pickaxeEffective, oneOf(e)).withBlastResistance(45)
}

// EncodeItem ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/ender_chest.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewEnderChest() EnderChest {

// BreakInfo ...
func (c EnderChest) BreakInfo() BreakInfo {
return newBreakInfo(22.5, pickaxeHarvestable, pickaxeEffective, silkTouchDrop(item.NewStack(Obsidian{}, 8), item.NewStack(NewEnderChest(), 1)))
return newBreakInfo(22.5, pickaxeHarvestable, pickaxeEffective, silkTouchDrop(item.NewStack(Obsidian{}, 8), item.NewStack(NewEnderChest(), 1))).withBlastResistance(3000)
}

// LightEmissionLevel ...
Expand Down

0 comments on commit fd081cf

Please sign in to comment.