From ba97df6a93bf3e72c896498f26a39e335720230a Mon Sep 17 00:00:00 2001 From: FDUTCH Date: Thu, 30 May 2024 04:13:36 +0200 Subject: [PATCH 1/4] liqud flow --- server/block/cube/face.go | 9 +++++ server/entity/experience_orb_behaviour.go | 14 ++++--- server/entity/item_behaviour.go | 14 ++++--- server/entity/movement.go | 46 ++++++++++++++++++++++- server/entity/passive.go | 15 +++++--- server/entity/tnt.go | 14 ++++--- 6 files changed, 88 insertions(+), 24 deletions(-) diff --git a/server/block/cube/face.go b/server/block/cube/face.go index 12049e597..669cd3ee2 100644 --- a/server/block/cube/face.go +++ b/server/block/cube/face.go @@ -105,6 +105,15 @@ func (f Face) String() string { panic("invalid face") } +// Positive returns whether the face is the positive of its axis. For example, FaceEast is positive, FaceWest is not. +func (f Face) Positive() bool { + switch f { + case FaceUp, FaceSouth, FaceEast: + return true + } + return false +} + // Faces returns a list of all faces, starting with down, then up, then north to west. func Faces() []Face { return faces[:] diff --git a/server/entity/experience_orb_behaviour.go b/server/entity/experience_orb_behaviour.go index 8b74d94ca..ba559bcf0 100644 --- a/server/entity/experience_orb_behaviour.go +++ b/server/entity/experience_orb_behaviour.go @@ -1,11 +1,12 @@ package entity import ( + "math" + "time" + "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/world" "github.com/go-gl/mathgl/mgl64" - "math" - "time" ) // ExperienceOrbBehaviourConfig holds optional parameters for the creation of @@ -33,10 +34,11 @@ func (conf ExperienceOrbBehaviourConfig) New() *ExperienceOrbBehaviour { } b := &ExperienceOrbBehaviour{conf: conf, lastSearch: time.Now()} b.passive = PassiveBehaviourConfig{ - Gravity: conf.Gravity, - Drag: conf.Drag, - ExistenceDuration: conf.ExistenceDuration, - Tick: b.tick, + Gravity: conf.Gravity, + Drag: conf.Drag, + UnderwaterMovement: 0.02, + ExistenceDuration: conf.ExistenceDuration, + Tick: b.tick, }.New() return b } diff --git a/server/entity/item_behaviour.go b/server/entity/item_behaviour.go index 61de607d1..e57442ba6 100644 --- a/server/entity/item_behaviour.go +++ b/server/entity/item_behaviour.go @@ -1,12 +1,13 @@ package entity import ( + "math" + "time" + "github.com/df-mc/dragonfly/server/internal/nbtconv" "github.com/df-mc/dragonfly/server/item" "github.com/df-mc/dragonfly/server/world" "github.com/go-gl/mathgl/mgl64" - "math" - "time" ) // ItemBehaviourConfig holds optional parameters for an ItemBehaviour. @@ -40,10 +41,11 @@ func (conf ItemBehaviourConfig) New(i item.Stack) *ItemBehaviour { b := &ItemBehaviour{conf: conf, i: i, pickupDelay: conf.PickupDelay} b.passive = PassiveBehaviourConfig{ - Gravity: conf.Gravity, - Drag: conf.Drag, - ExistenceDuration: conf.ExistenceDuration, - Tick: b.tick, + Gravity: conf.Gravity, + Drag: conf.Drag, + UnderwaterMovement: 0.02, + ExistenceDuration: conf.ExistenceDuration, + Tick: b.tick, }.New() return b } diff --git a/server/entity/movement.go b/server/entity/movement.go index 5b69679e9..c5ce1108e 100644 --- a/server/entity/movement.go +++ b/server/entity/movement.go @@ -1,10 +1,11 @@ package entity import ( + "math" + "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/world" "github.com/go-gl/mathgl/mgl64" - "math" ) // MovementComputer is used to compute movement of an entity. When constructed, the Gravity of the entity @@ -13,6 +14,9 @@ type MovementComputer struct { Gravity, Drag float64 DragBeforeGravity bool + // UnderwaterMovement is 0.02 for most entities if 0 entity will not be affected by waterflow + UnderwaterMovement float64 + onGround bool } @@ -111,6 +115,11 @@ func (c *MovementComputer) applyHorizontalForces(w *world.World, pos, vel mgl64. friction *= 0.6 } } + + if c.UnderwaterMovement > 0 { + vel = vel.Add(liquidVel(w, cube.PosFromVec3(pos), c.UnderwaterMovement)) + } + vel[0] *= friction vel[2] *= friction return vel @@ -193,3 +202,38 @@ func blockBBoxsAround(e world.Entity, box cube.BBox) []cube.BBox { } return blockBBoxs } + +// liquidVel returns a velocity offset by liquid flow for position +func liquidVel(w *world.World, pos cube.Pos, mul float64) mgl64.Vec3 { + var x int8 + var z int8 + if liq, ok := w.Liquid(pos); ok { + depth := liq.LiquidDepth() + for _, face := range cube.HorizontalFaces() { + bl, ok := w.Liquid(pos.Side(face)) + if ok { + if bl.LiquidDepth() == depth { + continue + } + var smaller bool = depth > bl.LiquidDepth() + val := booleanToByte(smaller == face.Positive()) + switch face.Axis() { + case cube.X: + x += val + case cube.Z: + z += val + default: + panic("should never happen") + } + } + } + } + return mgl64.Vec3{mul * float64(x), 0, mul * float64(z)} +} + +func booleanToByte(val bool) int8 { + if val { + return 1 + } + return -1 +} diff --git a/server/entity/passive.go b/server/entity/passive.go index a03fbecf4..e0b0e705a 100644 --- a/server/entity/passive.go +++ b/server/entity/passive.go @@ -1,10 +1,11 @@ package entity import ( - "github.com/df-mc/dragonfly/server/block" - "github.com/go-gl/mathgl/mgl64" "math" "time" + + "github.com/df-mc/dragonfly/server/block" + "github.com/go-gl/mathgl/mgl64" ) // PassiveBehaviourConfig holds optional parameters for a PassiveBehaviour. @@ -14,6 +15,9 @@ type PassiveBehaviourConfig struct { // Drag is used to reduce all axes of the velocity every tick. Velocity is // multiplied with (1-Drag) every tick. Drag float64 + + // UnderwaterMovement is 0.02 for most entities if 0 entity will not be affected by waterflow + UnderwaterMovement float64 // ExistenceDuration is the duration that an entity with this behaviour // should last. Once this time expires, the entity is closed. If // ExistenceDuration is 0, the entity will never expire automatically. @@ -32,9 +36,10 @@ func (conf PassiveBehaviourConfig) New() *PassiveBehaviour { conf.ExistenceDuration = math.MaxInt64 } return &PassiveBehaviour{conf: conf, fuse: conf.ExistenceDuration, mc: &MovementComputer{ - Gravity: conf.Gravity, - Drag: conf.Drag, - DragBeforeGravity: true, + Gravity: conf.Gravity, + Drag: conf.Drag, + DragBeforeGravity: true, + UnderwaterMovement: conf.UnderwaterMovement, }} } diff --git a/server/entity/tnt.go b/server/entity/tnt.go index d2d7d1c32..b21dd8765 100644 --- a/server/entity/tnt.go +++ b/server/entity/tnt.go @@ -1,14 +1,15 @@ package entity import ( + "math" + "math/rand" + "time" + "github.com/df-mc/dragonfly/server/block" "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/internal/nbtconv" "github.com/df-mc/dragonfly/server/world" "github.com/go-gl/mathgl/mgl64" - "math" - "math/rand" - "time" ) // NewTNT creates a new primed TNT entity. @@ -23,9 +24,10 @@ func NewTNT(pos mgl64.Vec3, fuse time.Duration, igniter world.Entity) *Ent { } var tntConf = PassiveBehaviourConfig{ - Gravity: 0.04, - Drag: 0.02, - Expire: explodeTNT, + Gravity: 0.04, + Drag: 0.02, + UnderwaterMovement: 0.02, + Expire: explodeTNT, } // explodeTNT creates an explosion at the position of e. From 03f70737883d23af2bd8b037e81da912d0f084da Mon Sep 17 00:00:00 2001 From: FDUTCH Date: Thu, 6 Jun 2024 04:55:58 +0200 Subject: [PATCH 2/4] scheduled blocks update fix --- server/world/conf.go | 7 ++++--- server/world/mcdb/db.go | 12 +++++++++--- server/world/settings.go | 6 ++++-- server/world/tick.go | 11 +++++++---- server/world/world.go | 11 +++++------ 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/server/world/conf.go b/server/world/conf.go index c164952e0..6eaefc8f7 100644 --- a/server/world/conf.go +++ b/server/world/conf.go @@ -1,11 +1,12 @@ package world import ( + "math/rand" + "time" + "github.com/df-mc/atomic" "github.com/df-mc/dragonfly/server/block/cube" "github.com/sirupsen/logrus" - "math/rand" - "time" ) // Config may be used to create a new World. It holds a variety of fields that influence the World. @@ -78,7 +79,7 @@ func (conf Config) New() *World { closing: make(chan struct{}), handler: *atomic.NewValue[Handler](NopHandler{}), r: rand.New(conf.RandSource), - advance: s.ref.Inc() == 1, + advance: s.WorldCounter.Inc() == 1, conf: conf, ra: conf.Dim.Range(), set: s, diff --git a/server/world/mcdb/db.go b/server/world/mcdb/db.go index 035a73eb1..f31816b08 100644 --- a/server/world/mcdb/db.go +++ b/server/world/mcdb/db.go @@ -5,6 +5,10 @@ import ( "encoding/binary" "errors" "fmt" + "os" + "path/filepath" + "time" + "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/world" "github.com/df-mc/dragonfly/server/world/chunk" @@ -13,9 +17,6 @@ import ( "github.com/google/uuid" "github.com/sandertv/gophertunnel/minecraft/nbt" "golang.org/x/exp/maps" - "os" - "path/filepath" - "time" ) // DB implements a world provider for the Minecraft world format, which @@ -45,6 +46,7 @@ func (db *DB) Settings() *world.Settings { // SaveSettings saves the world.Settings passed to the level.dat. func (db *DB) SaveSettings(s *world.Settings) { db.ldat.PutSettings(s) + db.set = s } // playerData holds the fields that indicate where player data is stored for a player with a specific UUID. @@ -411,6 +413,10 @@ func (db *DB) NewColumnIterator(r *IteratorRange) *ColumnIterator { func (db *DB) Close() error { db.ldat.LastPlayed = time.Now().Unix() + if db.set.WorldCounter.Load() != 0 { + return nil + } + var ldat leveldat.LevelDat if err := ldat.Marshal(*db.ldat); err != nil { return fmt.Errorf("close: %w", err) diff --git a/server/world/settings.go b/server/world/settings.go index e8ea8f4d0..f8176ed96 100644 --- a/server/world/settings.go +++ b/server/world/settings.go @@ -1,17 +1,19 @@ package world import ( + "sync" + "github.com/df-mc/atomic" "github.com/df-mc/dragonfly/server/block/cube" - "sync" ) // Settings holds the settings of a World. These are typically saved to a level.dat file. It is safe to pass the same // Settings to multiple worlds created using New, in which case the Settings are synchronised between the worlds. type Settings struct { sync.Mutex - ref atomic.Int32 + // WorldCounter... + WorldCounter atomic.Int32 // Name is the display name of the World. Name string // Spawn is the spawn position of the World. New players that join the world will be spawned here. diff --git a/server/world/tick.go b/server/world/tick.go index b2b163aae..039becab6 100644 --- a/server/world/tick.go +++ b/server/world/tick.go @@ -1,12 +1,13 @@ package world import ( - "github.com/df-mc/dragonfly/server/block/cube" - "github.com/df-mc/dragonfly/server/internal/sliceutil" - "golang.org/x/exp/maps" "math/rand" "slices" "time" + + "github.com/df-mc/dragonfly/server/block/cube" + "github.com/df-mc/dragonfly/server/internal/sliceutil" + "golang.org/x/exp/maps" ) // ticker implements World ticking methods. World embeds this struct, so any exported methods on ticker are exported @@ -41,8 +42,10 @@ func (t ticker) tick() { t.w.set.Unlock() return } + + t.w.set.CurrentTick++ + if t.w.advance { - t.w.set.CurrentTick++ if t.w.set.TimeCycle { t.w.set.Time++ } diff --git a/server/world/world.go b/server/world/world.go index fed71a25d..1f1c3b7ae 100644 --- a/server/world/world.go +++ b/server/world/world.go @@ -2,11 +2,14 @@ package world import ( "errors" - "github.com/df-mc/goleveldb/leveldb" "math/rand" "sync" "time" + "github.com/df-mc/goleveldb/leveldb" + + "slices" + "github.com/df-mc/atomic" "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/event" @@ -15,7 +18,6 @@ import ( "github.com/go-gl/mathgl/mgl64" "github.com/google/uuid" "golang.org/x/exp/maps" - "slices" ) // World implements a Minecraft world. It manages all aspects of what players can see, such as blocks, @@ -1044,10 +1046,7 @@ func (w *World) close() { w.saveChunk(pos, c) } - w.set.ref.Dec() - if !w.advance { - return - } + w.set.WorldCounter.Dec() if !w.conf.ReadOnly { w.conf.Log.Debugf("Updating level.dat values...") From 9b44c9ae2554e3d96d90b6e5d5ee67b8ac1743b0 Mon Sep 17 00:00:00 2001 From: FDUTCH Date: Thu, 1 Aug 2024 01:28:00 +0200 Subject: [PATCH 3/4] Revert "scheduled blocks update fix" This reverts commit 03f70737883d23af2bd8b037e81da912d0f084da. --- server/world/conf.go | 7 +++---- server/world/mcdb/db.go | 12 +++--------- server/world/settings.go | 6 ++---- server/world/tick.go | 11 ++++------- server/world/world.go | 11 ++++++----- 5 files changed, 18 insertions(+), 29 deletions(-) diff --git a/server/world/conf.go b/server/world/conf.go index 6eaefc8f7..c164952e0 100644 --- a/server/world/conf.go +++ b/server/world/conf.go @@ -1,12 +1,11 @@ package world import ( - "math/rand" - "time" - "github.com/df-mc/atomic" "github.com/df-mc/dragonfly/server/block/cube" "github.com/sirupsen/logrus" + "math/rand" + "time" ) // Config may be used to create a new World. It holds a variety of fields that influence the World. @@ -79,7 +78,7 @@ func (conf Config) New() *World { closing: make(chan struct{}), handler: *atomic.NewValue[Handler](NopHandler{}), r: rand.New(conf.RandSource), - advance: s.WorldCounter.Inc() == 1, + advance: s.ref.Inc() == 1, conf: conf, ra: conf.Dim.Range(), set: s, diff --git a/server/world/mcdb/db.go b/server/world/mcdb/db.go index f31816b08..035a73eb1 100644 --- a/server/world/mcdb/db.go +++ b/server/world/mcdb/db.go @@ -5,10 +5,6 @@ import ( "encoding/binary" "errors" "fmt" - "os" - "path/filepath" - "time" - "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/world" "github.com/df-mc/dragonfly/server/world/chunk" @@ -17,6 +13,9 @@ import ( "github.com/google/uuid" "github.com/sandertv/gophertunnel/minecraft/nbt" "golang.org/x/exp/maps" + "os" + "path/filepath" + "time" ) // DB implements a world provider for the Minecraft world format, which @@ -46,7 +45,6 @@ func (db *DB) Settings() *world.Settings { // SaveSettings saves the world.Settings passed to the level.dat. func (db *DB) SaveSettings(s *world.Settings) { db.ldat.PutSettings(s) - db.set = s } // playerData holds the fields that indicate where player data is stored for a player with a specific UUID. @@ -413,10 +411,6 @@ func (db *DB) NewColumnIterator(r *IteratorRange) *ColumnIterator { func (db *DB) Close() error { db.ldat.LastPlayed = time.Now().Unix() - if db.set.WorldCounter.Load() != 0 { - return nil - } - var ldat leveldat.LevelDat if err := ldat.Marshal(*db.ldat); err != nil { return fmt.Errorf("close: %w", err) diff --git a/server/world/settings.go b/server/world/settings.go index f8176ed96..e8ea8f4d0 100644 --- a/server/world/settings.go +++ b/server/world/settings.go @@ -1,19 +1,17 @@ package world import ( - "sync" - "github.com/df-mc/atomic" "github.com/df-mc/dragonfly/server/block/cube" + "sync" ) // Settings holds the settings of a World. These are typically saved to a level.dat file. It is safe to pass the same // Settings to multiple worlds created using New, in which case the Settings are synchronised between the worlds. type Settings struct { sync.Mutex + ref atomic.Int32 - // WorldCounter... - WorldCounter atomic.Int32 // Name is the display name of the World. Name string // Spawn is the spawn position of the World. New players that join the world will be spawned here. diff --git a/server/world/tick.go b/server/world/tick.go index 039becab6..b2b163aae 100644 --- a/server/world/tick.go +++ b/server/world/tick.go @@ -1,13 +1,12 @@ package world import ( - "math/rand" - "slices" - "time" - "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/internal/sliceutil" "golang.org/x/exp/maps" + "math/rand" + "slices" + "time" ) // ticker implements World ticking methods. World embeds this struct, so any exported methods on ticker are exported @@ -42,10 +41,8 @@ func (t ticker) tick() { t.w.set.Unlock() return } - - t.w.set.CurrentTick++ - if t.w.advance { + t.w.set.CurrentTick++ if t.w.set.TimeCycle { t.w.set.Time++ } diff --git a/server/world/world.go b/server/world/world.go index c6b7f6fce..e925e5ed3 100644 --- a/server/world/world.go +++ b/server/world/world.go @@ -2,14 +2,11 @@ package world import ( "errors" + "github.com/df-mc/goleveldb/leveldb" "math/rand" "sync" "time" - "github.com/df-mc/goleveldb/leveldb" - - "slices" - "github.com/df-mc/atomic" "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/event" @@ -18,6 +15,7 @@ import ( "github.com/go-gl/mathgl/mgl64" "github.com/google/uuid" "golang.org/x/exp/maps" + "slices" ) // World implements a Minecraft world. It manages all aspects of what players can see, such as blocks, @@ -1048,7 +1046,10 @@ func (w *World) close() { w.saveChunk(pos, c) } - w.set.WorldCounter.Dec() + w.set.ref.Dec() + if !w.advance { + return + } if !w.conf.ReadOnly { w.conf.Log.Debugf("Updating level.dat values...") From 6be2cf9b4afc5291138328ee886f324d066a5fa1 Mon Sep 17 00:00:00 2001 From: FDUTCH Date: Thu, 1 Aug 2024 01:28:12 +0200 Subject: [PATCH 4/4] Revert "liqud flow" This reverts commit ba97df6a93bf3e72c896498f26a39e335720230a. --- server/block/cube/face.go | 9 ----- server/entity/experience_orb_behaviour.go | 14 +++---- server/entity/item_behaviour.go | 14 +++---- server/entity/movement.go | 46 +---------------------- server/entity/passive.go | 15 +++----- server/entity/tnt.go | 14 +++---- 6 files changed, 24 insertions(+), 88 deletions(-) diff --git a/server/block/cube/face.go b/server/block/cube/face.go index 669cd3ee2..12049e597 100644 --- a/server/block/cube/face.go +++ b/server/block/cube/face.go @@ -105,15 +105,6 @@ func (f Face) String() string { panic("invalid face") } -// Positive returns whether the face is the positive of its axis. For example, FaceEast is positive, FaceWest is not. -func (f Face) Positive() bool { - switch f { - case FaceUp, FaceSouth, FaceEast: - return true - } - return false -} - // Faces returns a list of all faces, starting with down, then up, then north to west. func Faces() []Face { return faces[:] diff --git a/server/entity/experience_orb_behaviour.go b/server/entity/experience_orb_behaviour.go index ba559bcf0..8b74d94ca 100644 --- a/server/entity/experience_orb_behaviour.go +++ b/server/entity/experience_orb_behaviour.go @@ -1,12 +1,11 @@ package entity import ( - "math" - "time" - "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/world" "github.com/go-gl/mathgl/mgl64" + "math" + "time" ) // ExperienceOrbBehaviourConfig holds optional parameters for the creation of @@ -34,11 +33,10 @@ func (conf ExperienceOrbBehaviourConfig) New() *ExperienceOrbBehaviour { } b := &ExperienceOrbBehaviour{conf: conf, lastSearch: time.Now()} b.passive = PassiveBehaviourConfig{ - Gravity: conf.Gravity, - Drag: conf.Drag, - UnderwaterMovement: 0.02, - ExistenceDuration: conf.ExistenceDuration, - Tick: b.tick, + Gravity: conf.Gravity, + Drag: conf.Drag, + ExistenceDuration: conf.ExistenceDuration, + Tick: b.tick, }.New() return b } diff --git a/server/entity/item_behaviour.go b/server/entity/item_behaviour.go index e57442ba6..61de607d1 100644 --- a/server/entity/item_behaviour.go +++ b/server/entity/item_behaviour.go @@ -1,13 +1,12 @@ package entity import ( - "math" - "time" - "github.com/df-mc/dragonfly/server/internal/nbtconv" "github.com/df-mc/dragonfly/server/item" "github.com/df-mc/dragonfly/server/world" "github.com/go-gl/mathgl/mgl64" + "math" + "time" ) // ItemBehaviourConfig holds optional parameters for an ItemBehaviour. @@ -41,11 +40,10 @@ func (conf ItemBehaviourConfig) New(i item.Stack) *ItemBehaviour { b := &ItemBehaviour{conf: conf, i: i, pickupDelay: conf.PickupDelay} b.passive = PassiveBehaviourConfig{ - Gravity: conf.Gravity, - Drag: conf.Drag, - UnderwaterMovement: 0.02, - ExistenceDuration: conf.ExistenceDuration, - Tick: b.tick, + Gravity: conf.Gravity, + Drag: conf.Drag, + ExistenceDuration: conf.ExistenceDuration, + Tick: b.tick, }.New() return b } diff --git a/server/entity/movement.go b/server/entity/movement.go index c5ce1108e..5b69679e9 100644 --- a/server/entity/movement.go +++ b/server/entity/movement.go @@ -1,11 +1,10 @@ package entity import ( - "math" - "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/world" "github.com/go-gl/mathgl/mgl64" + "math" ) // MovementComputer is used to compute movement of an entity. When constructed, the Gravity of the entity @@ -14,9 +13,6 @@ type MovementComputer struct { Gravity, Drag float64 DragBeforeGravity bool - // UnderwaterMovement is 0.02 for most entities if 0 entity will not be affected by waterflow - UnderwaterMovement float64 - onGround bool } @@ -115,11 +111,6 @@ func (c *MovementComputer) applyHorizontalForces(w *world.World, pos, vel mgl64. friction *= 0.6 } } - - if c.UnderwaterMovement > 0 { - vel = vel.Add(liquidVel(w, cube.PosFromVec3(pos), c.UnderwaterMovement)) - } - vel[0] *= friction vel[2] *= friction return vel @@ -202,38 +193,3 @@ func blockBBoxsAround(e world.Entity, box cube.BBox) []cube.BBox { } return blockBBoxs } - -// liquidVel returns a velocity offset by liquid flow for position -func liquidVel(w *world.World, pos cube.Pos, mul float64) mgl64.Vec3 { - var x int8 - var z int8 - if liq, ok := w.Liquid(pos); ok { - depth := liq.LiquidDepth() - for _, face := range cube.HorizontalFaces() { - bl, ok := w.Liquid(pos.Side(face)) - if ok { - if bl.LiquidDepth() == depth { - continue - } - var smaller bool = depth > bl.LiquidDepth() - val := booleanToByte(smaller == face.Positive()) - switch face.Axis() { - case cube.X: - x += val - case cube.Z: - z += val - default: - panic("should never happen") - } - } - } - } - return mgl64.Vec3{mul * float64(x), 0, mul * float64(z)} -} - -func booleanToByte(val bool) int8 { - if val { - return 1 - } - return -1 -} diff --git a/server/entity/passive.go b/server/entity/passive.go index e0b0e705a..a03fbecf4 100644 --- a/server/entity/passive.go +++ b/server/entity/passive.go @@ -1,11 +1,10 @@ package entity import ( - "math" - "time" - "github.com/df-mc/dragonfly/server/block" "github.com/go-gl/mathgl/mgl64" + "math" + "time" ) // PassiveBehaviourConfig holds optional parameters for a PassiveBehaviour. @@ -15,9 +14,6 @@ type PassiveBehaviourConfig struct { // Drag is used to reduce all axes of the velocity every tick. Velocity is // multiplied with (1-Drag) every tick. Drag float64 - - // UnderwaterMovement is 0.02 for most entities if 0 entity will not be affected by waterflow - UnderwaterMovement float64 // ExistenceDuration is the duration that an entity with this behaviour // should last. Once this time expires, the entity is closed. If // ExistenceDuration is 0, the entity will never expire automatically. @@ -36,10 +32,9 @@ func (conf PassiveBehaviourConfig) New() *PassiveBehaviour { conf.ExistenceDuration = math.MaxInt64 } return &PassiveBehaviour{conf: conf, fuse: conf.ExistenceDuration, mc: &MovementComputer{ - Gravity: conf.Gravity, - Drag: conf.Drag, - DragBeforeGravity: true, - UnderwaterMovement: conf.UnderwaterMovement, + Gravity: conf.Gravity, + Drag: conf.Drag, + DragBeforeGravity: true, }} } diff --git a/server/entity/tnt.go b/server/entity/tnt.go index b21dd8765..d2d7d1c32 100644 --- a/server/entity/tnt.go +++ b/server/entity/tnt.go @@ -1,15 +1,14 @@ package entity import ( - "math" - "math/rand" - "time" - "github.com/df-mc/dragonfly/server/block" "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/internal/nbtconv" "github.com/df-mc/dragonfly/server/world" "github.com/go-gl/mathgl/mgl64" + "math" + "math/rand" + "time" ) // NewTNT creates a new primed TNT entity. @@ -24,10 +23,9 @@ func NewTNT(pos mgl64.Vec3, fuse time.Duration, igniter world.Entity) *Ent { } var tntConf = PassiveBehaviourConfig{ - Gravity: 0.04, - Drag: 0.02, - UnderwaterMovement: 0.02, - Expire: explodeTNT, + Gravity: 0.04, + Drag: 0.02, + Expire: explodeTNT, } // explodeTNT creates an explosion at the position of e.