Skip to content

Commit

Permalink
Implemented fire spreading (df-mc#68)
Browse files Browse the repository at this point in the history
* Add BreakBlockWithoutParticles method

* Implemented fire

* Added flint and steel sound + Handle fire extinguishing

* Fixed falling block entity AABB

* Implemented soul sand & soul fire

* Lava can now spread fire

* Extinguishing a fire now plays the proper sound

* Fire spread is now affected by world difficulty

* Implemented block collisions & fire damage

* Added missing OnFire state

* Lava now lights players on fire

* Reset fire tick on respawn

* Fixed bad copy paste

* Implemented fire resistance potions & effect

* Implemented crimson & warped wood variants

* Commit missing changes

* Fixed unreachable panics

* Made fire blocks replaceable

* Fixed unbreakable fence gates

* Fixed falling block entities

* Implemented random blocks

* Removed code that was not supposed to be committed

* Fixed extra space in comment

* Fixed sea lanterns dropping self

* Added Polished Basalt, Smooth Stone, & Soul Soil

* Grammar

* Added blue ice, gilded blackstone, basalt generators

* Apples drop only from dark oak/oak

* Optimized basalt generation

* whoops

* Implemented shroomlight

* Implemented FlammabilityInfo struct

* Rename EntityColliding + don't export neighbourFlammable

* Added method woodTypeFlammable

* Added LavaFlammable field to FlammabilityInfo

* Cleanup fire spread logic

* Rename neighbourFlammable -> neighboursFlammable

* Cleanup entity.Flammable interface

* Fixed missing LavaFlammable check

* Nether doors & trapdoors are not lava flammable

* Display entity on fire state

* Fixed fire spread for lava

* Cleaned up wood flammability checks

* OnFireDuration/SetOnFire now return/accept time.Duration

* Move FireDamage/LavaDamage methods to block_internal

* Fixed neighbour updates speeding up fire spread

* Cleanup + Fire extinguishes with water underneath
  • Loading branch information
DaPigGuy authored Sep 2, 2020
1 parent 4807b50 commit 6e3edde
Show file tree
Hide file tree
Showing 55 changed files with 1,253 additions and 101 deletions.
23 changes: 23 additions & 0 deletions dragonfly/block/barrier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package block

// Barrier is a transparent solid block used to create invisible boundaries.
type Barrier struct {
noNBT
transparent
solid
}

// EncodeItem ...
func (Barrier) EncodeItem() (id int32, meta int16) {
return -161, 0
}

// EncodeBlock ...
func (Barrier) EncodeBlock() (name string, properties map[string]interface{}) {
return "minecraft:barrier", nil
}

// Hash ...
func (Barrier) Hash() uint64 {
return hashBarrier
}
61 changes: 61 additions & 0 deletions dragonfly/block/basalt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package block

import (
"github.com/df-mc/dragonfly/dragonfly/item"
"github.com/df-mc/dragonfly/dragonfly/world"
"github.com/go-gl/mathgl/mgl64"
)

// Basalt is a type of igneous rock found in the Nether.
type Basalt struct {
noNBT
solid

// Polished specifies if the basalt is its polished variant.
Polished bool
// Axis is the axis which the basalt faces.
Axis world.Axis
}

// UseOnBlock ...
func (b Basalt) UseOnBlock(pos world.BlockPos, face world.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) {
pos, face, used = firstReplaceable(w, pos, face, b)
if !used {
return
}
b.Axis = face.Axis()

place(w, pos, b, user, ctx)
return placed(ctx)
}

// BreakInfo ...
func (b Basalt) BreakInfo() BreakInfo {
return BreakInfo{
Hardness: 1.25,
Harvestable: pickaxeHarvestable,
Effective: pickaxeEffective,
Drops: simpleDrops(item.NewStack(b, 1)),
}
}

// EncodeItem ...
func (b Basalt) EncodeItem() (id int32, meta int16) {
if b.Polished {
return -235, 0
}
return -234, 0
}

// EncodeBlock ...
func (b Basalt) EncodeBlock() (name string, properties map[string]interface{}) {
if b.Polished {
return "minecraft:polished_basalt", map[string]interface{}{"pillar_axis": b.Axis.String()}
}
return "minecraft:basalt", map[string]interface{}{"pillar_axis": b.Axis.String()}
}

// Hash ...
func (b Basalt) Hash() uint64 {
return hashBasalt | (uint64(boolByte(b.Polished)) << 32) | (uint64(b.Axis) << 33)
}
26 changes: 24 additions & 2 deletions dragonfly/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,31 @@ func (g gravityAffected) fall(b world.Block, pos world.BlockPos, w *world.World)
_, air := w.Block(pos.Side(world.FaceDown)).(Air)
_, liquid := w.Liquid(pos.Side(world.FaceDown))
if air || liquid {
w.BreakBlock(pos)
w.BreakBlockWithoutParticles(pos)

e := entity.NewFallingBlock(b, pos.Vec3())
e := entity.NewFallingBlock(b, pos.Vec3Middle())
w.AddEntity(e)
}
}

// Flammable is an interface for blocks that can catch on fire.
type Flammable interface {
// FlammabilityInfo returns information about a blocks behavior involving fire.
FlammabilityInfo() FlammabilityInfo
}

// FlammabilityInfo contains values related to block behaviors involving fire.
type FlammabilityInfo struct {
// Encouragement is the chance a block will catch on fire during attempted fire spread.
Encouragement,
// Flammability is the chance a block will burn away during a fire block tick.
Flammability int
// LavaFlammable returns whether it can catch on fire from lava.
LavaFlammable bool
}

// EntityCollider is an interface for blocks with special behaviors on entity collision.
type EntityCollider interface {
// EntityCollide is called on entity collision.
EntityCollide(e world.Entity)
}
39 changes: 39 additions & 0 deletions dragonfly/block/blue_ice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package block

// TODO: Slipperiness

// BlueIce is a solid block similar to packed ice.
type BlueIce struct {
noNBT
solid
}

// LightEmissionLevel ...
func (BlueIce) LightEmissionLevel() uint8 {
return 4
}

// BreakInfo ...
func (b BlueIce) BreakInfo() BreakInfo {
return BreakInfo{
Hardness: 2.8,
Harvestable: alwaysHarvestable,
Effective: pickaxeEffective,
Drops: simpleDrops(),
}
}

// EncodeItem ...
func (BlueIce) EncodeItem() (id int32, meta int16) {
return -11, 0
}

// EncodeBlock ...
func (BlueIce) EncodeBlock() (name string, properties map[string]interface{}) {
return "minecraft:blue_ice", nil
}

// Hash ...
func (BlueIce) Hash() uint64 {
return hashBlueIce
}
5 changes: 5 additions & 0 deletions dragonfly/block/break_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ var shovelEffective = func(t tool.Tool) bool {
return t.ToolType() == tool.TypeShovel
}

// hoeEffective is a convenience function for blocks that are effectively mined with a hoe.
var hoeEffective = func(t tool.Tool) bool {
return t.ToolType() == tool.TypeHoe
}

// nothingEffective is a convenience function for blocks that cannot be mined efficiently with any tool.
var nothingEffective = func(tool.Tool) bool {
return false
Expand Down
11 changes: 10 additions & 1 deletion dragonfly/block/carpet.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ type Carpet struct {
Colour colour.Colour
}

// FlammabilityInfo ...
func (c Carpet) FlammabilityInfo() FlammabilityInfo {
return FlammabilityInfo{
Encouragement: 30,
Flammability: 60,
LavaFlammable: true,
}
}

// CanDisplace ...
func (Carpet) CanDisplace(b world.Liquid) bool {
_, water := b.(Water)
Expand Down Expand Up @@ -61,7 +70,7 @@ func (Carpet) HasLiquidDrops() bool {
// NeighbourUpdateTick ...
func (Carpet) NeighbourUpdateTick(pos, _ world.BlockPos, w *world.World) {
if _, ok := w.Block(pos.Add(world.BlockPos{0, -1})).(Air); ok {
w.BreakBlock(pos)
w.BreakBlockWithoutParticles(pos)
}
}

Expand Down
5 changes: 5 additions & 0 deletions dragonfly/block/chest.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ type Chest struct {
viewers *[]ContainerViewer
}

// FlammabilityInfo ...
func (c Chest) FlammabilityInfo() FlammabilityInfo {
return FlammabilityInfo{LavaFlammable: true}
}

// NewChest creates a new initialised chest. The inventory is properly initialised.
func NewChest() Chest {
m := new(sync.RWMutex)
Expand Down
8 changes: 8 additions & 0 deletions dragonfly/block/coal_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ type CoalBlock struct {
solid
}

// FlammabilityInfo ...
func (c CoalBlock) FlammabilityInfo() FlammabilityInfo {
return FlammabilityInfo{
Encouragement: 5,
Flammability: 5,
}
}

// BreakInfo ...
func (c CoalBlock) BreakInfo() BreakInfo {
return BreakInfo{
Expand Down
2 changes: 1 addition & 1 deletion dragonfly/block/cocoa_bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c CocoaBean) HasLiquidDrops() bool {
// NeighbourUpdateTick ...
func (c CocoaBean) NeighbourUpdateTick(pos, _ world.BlockPos, w *world.World) {
if log, ok := w.Block(pos.Side(c.Facing.Face())).(Log); !ok || log.Wood != wood.Jungle() || log.Stripped {
w.BreakBlock(pos)
w.BreakBlockWithoutParticles(pos)
}
}

Expand Down
2 changes: 1 addition & 1 deletion dragonfly/block/crop.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type crop struct {
// NeighbourUpdateTick ...
func (c crop) NeighbourUpdateTick(pos, _ world.BlockPos, w *world.World) {
if _, ok := w.Block(pos.Side(world.FaceDown)).(Farmland); !ok {
w.BreakBlock(pos)
w.BreakBlockWithoutParticles(pos)
}
}

Expand Down
44 changes: 44 additions & 0 deletions dragonfly/block/crying_obsidian.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package block

import (
"github.com/df-mc/dragonfly/dragonfly/item"
"github.com/df-mc/dragonfly/dragonfly/item/tool"
)

// CryingObsidian is a luminous variant of obsidian that can be used to craft a respawn anchor and produces purple particles when placed.
type CryingObsidian struct {
noNBT
solid
}

// LightEmissionLevel ...
func (CryingObsidian) LightEmissionLevel() uint8 {
return 10
}

// BreakInfo ...
func (c CryingObsidian) BreakInfo() BreakInfo {
return BreakInfo{
Hardness: 50,
Harvestable: func(t tool.Tool) bool {
return t.ToolType() == tool.TypePickaxe && t.HarvestLevel() == tool.TierDiamond.HarvestLevel
},
Effective: pickaxeEffective,
Drops: simpleDrops(item.NewStack(c, 1)),
}
}

// EncodeItem ...
func (CryingObsidian) EncodeItem() (id int32, meta int16) {
return -289, 0
}

// EncodeBlock ...
func (CryingObsidian) EncodeBlock() (name string, properties map[string]interface{}) {
return "minecraft:crying_obsidian", nil
}

// Hash ...
func (CryingObsidian) Hash() uint64 {
return hashCryingObsidian
}
Loading

0 comments on commit 6e3edde

Please sign in to comment.