From 9dd284d79c33cd65230f8606b45fba8d273231d8 Mon Sep 17 00:00:00 2001 From: glancist Date: Fri, 29 Nov 2024 19:49:36 +0000 Subject: [PATCH 1/3] fix --- server/session/entity_metadata.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/session/entity_metadata.go b/server/session/entity_metadata.go index c563ab064..cc804c072 100644 --- a/server/session/entity_metadata.go +++ b/server/session/entity_metadata.go @@ -25,7 +25,6 @@ func (s *Session) parseEntityMetadata(e world.Entity) protocol.EntityMetadata { m[protocol.EntityDataKeyEffectColor] = int32(0) m[protocol.EntityDataKeyEffectAmbience] = byte(0) m[protocol.EntityDataKeyColorIndex] = byte(0) - m[protocol.EntityDataKeyHasNPC] = uint8(1) m.SetFlag(protocol.EntityDataKeyFlags, protocol.EntityDataFlagHasGravity) m.SetFlag(protocol.EntityDataKeyFlags, protocol.EntityDataFlagClimb) @@ -164,6 +163,9 @@ func (s *Session) addSpecificMetadata(e any, m protocol.EntityMetadata) { } m[protocol.EntityDataKeyVisibleMobEffects] = packedEffects } + if d, ok := e.(dialogueProvider); ok { + m[protocol.EntityDataKeyHasNPC] = boolByte(d.CanShowDialogue()) + } if v, ok := e.(variable); ok { m[protocol.EntityDataKeyVariant] = v.Variant() } @@ -273,6 +275,10 @@ type living interface { DeathPosition() (mgl64.Vec3, world.Dimension, bool) } +type dialogueProvider interface { + CanShowDialogue() bool +} + type variable interface { Variant() int32 } From 6c7d4186648c5629c3344bf37113755f498e742a Mon Sep 17 00:00:00 2001 From: glancist Date: Sat, 30 Nov 2024 20:22:33 +0000 Subject: [PATCH 2/3] merge entity riding --- server/entity/rideable.go | 22 ++++ server/entity/rider.go | 13 +++ server/player/handler.go | 9 ++ server/player/player.go | 108 ++++++++++++++++++ server/session/controllable.go | 7 ++ server/session/entity_metadata.go | 6 + server/session/handler_interact.go | 4 + .../session/handler_inventory_transaction.go | 5 + server/session/handler_player_auth_input.go | 10 ++ server/session/world.go | 25 ++++ server/world/viewer.go | 7 ++ 11 files changed, 216 insertions(+) create mode 100644 server/entity/rideable.go create mode 100644 server/entity/rider.go diff --git a/server/entity/rideable.go b/server/entity/rideable.go new file mode 100644 index 000000000..8595ad6c8 --- /dev/null +++ b/server/entity/rideable.go @@ -0,0 +1,22 @@ +package entity + +import ( + "github.com/df-mc/dragonfly/server/world" + "github.com/go-gl/mathgl/mgl32" + "github.com/go-gl/mathgl/mgl64" +) + +// Rideable is an interface for entities that can be ridden. +type Rideable interface { + world.Entity + // SeatPositions returns the possible seat positions for an entity in the order that they will be filled. + SeatPositions() []mgl32.Vec3 + // Riders returns a slice entities that are currently riding an entity in the order that they were added. + Riders() []Rider + // AddRider adds a rider to the entity. + AddRider(e Rider) + // RemoveRider removes a rider from the entity. + RemoveRider(e Rider) + // Move moves the entity using the given vector, yaw, and pitch. + Move(vector mgl64.Vec2, yaw, pitch float32) +} diff --git a/server/entity/rider.go b/server/entity/rider.go new file mode 100644 index 000000000..cdc7a3c0e --- /dev/null +++ b/server/entity/rider.go @@ -0,0 +1,13 @@ +package entity + +import "github.com/go-gl/mathgl/mgl32" + +// Rider is an interface for entities that can ride other entities. +type Rider interface { + // SeatPosition returns the Rider's current seat position. + SeatPosition() mgl32.Vec3 + // MountEntity mounts the Rider to an entity if the entity is Rideable and if there is a seat available. + MountEntity(e Rideable) + // RidingEntity returns the entity the player is currently riding and the player's seat index. + RidingEntity() (Rideable, int) +} diff --git a/server/player/handler.go b/server/player/handler.go index 92adcefe4..61eced171 100644 --- a/server/player/handler.go +++ b/server/player/handler.go @@ -3,6 +3,7 @@ package player import ( "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/cmd" + "github.com/df-mc/dragonfly/server/entity" "github.com/df-mc/dragonfly/server/event" "github.com/df-mc/dragonfly/server/item" "github.com/df-mc/dragonfly/server/player/skin" @@ -152,6 +153,12 @@ type Handler interface { // not sent by every client however, only those with the "Creator > Enable Client Diagnostics" setting // enabled. HandleDiagnostics(p *Player, d session.Diagnostics) + // HandleMount handles when a player mounts an entity. ctx.Cancel() may be called to cancel the player mounting + // an entity. + HandleMount(ctx *Context, r entity.Rideable) + // HandleDismount handles when a player mounts an entity. ctx.Cancel() may be called to force the player + // to re-mount the entity. + HandleDismount(ctx *Context) } // NopHandler implements the Handler interface but does not execute any code when an event is called. The @@ -198,3 +205,5 @@ func (NopHandler) HandleDeath(*Player, world.DamageSource, *bool) func (NopHandler) HandleRespawn(*Player, *mgl64.Vec3, **world.World) {} func (NopHandler) HandleQuit(*Player) {} func (NopHandler) HandleDiagnostics(*Player, session.Diagnostics) {} +func (NopHandler) HandleMount(*Context, entity.Rideable) {} +func (NopHandler) HandleDismount(*Context) {} diff --git a/server/player/player.go b/server/player/player.go index 8267aaa12..ee27773c0 100644 --- a/server/player/player.go +++ b/server/player/player.go @@ -2,6 +2,7 @@ package player import ( "fmt" + "github.com/go-gl/mathgl/mgl32" "math" "math/rand" "net" @@ -52,6 +53,10 @@ type playerData struct { armour *inventory.Armour heldSlot *uint32 + seatPosition mgl32.Vec3 + ridingMu sync.Mutex + riding entity.Rideable + sneaking, sprinting, swimming, gliding, crawling, flying, invisible, immobile, onGround, usingItem bool usingSince time.Time @@ -834,6 +839,7 @@ func (p *Player) kill(src world.DamageSource) { // Wait a little before removing the entity. The client displays a death // animation while the player is dying. time.AfterFunc(time.Millisecond*1100, func() { + p.DismountEntity() p.H().ExecWorld(finishDying) }) } @@ -2746,6 +2752,107 @@ func (p *Player) PunchAir() { p.tx.PlaySound(p.Position(), sound.Attack{}) } +// MountEntity mounts the player to an entity if the entity is rideable and if there is a seat available. +func (p *Player) MountEntity(r entity.Rideable) { + ctx := event.C(p) + if p.Handler().HandleMount(ctx, r); ctx.Cancelled() { + return + } + if p.seat(r) == -1 { + r.AddRider(p) + p.setRiding(r) + riders := r.Riders() + seat := len(riders) + positions := r.SeatPositions() + if len(positions) >= seat { + p.seatPosition = positions[seat-1] + p.updateState() + for _, v := range p.viewers() { + v.ViewEntityMount(p, r, seat-1 == 0) + } + } + return + } + // Check and update seat position + p.checkSeats(r) +} + +// DismountEntity dismounts the player from an entity. +func (p *Player) DismountEntity() { + ctx := event.C(p) + e, seat := p.RidingEntity() + if e != nil { + if p.Handler().HandleDismount(ctx); ctx.Cancelled() { + p.s.ViewEntityMount(p, e, seat-1 == 0) + return + } + e.RemoveRider(p) + p.setRiding(nil) + for _, v := range p.viewers() { + v.ViewEntityDismount(p, e) + } + for _, r := range e.Riders() { + r.MountEntity(e) + } + } +} + +// checkSeats moves a player to the seat corresponding to their current index within the slice of riders. +func (p *Player) checkSeats(e entity.Rideable) { + seat := p.seat(e) + if seat != -1 { + positions := e.SeatPositions() + if positions[seat] != p.seatPosition { + p.seatPosition = positions[seat] + if seat == 0 { + for _, v := range p.viewers() { + v.ViewEntityMount(p, e, true) + } + } + p.updateState() + } + } +} + +// SeatPosition returns the position of the player's seat. +func (p *Player) SeatPosition() mgl32.Vec3 { + return p.seatPosition +} + +// seat returns the index of a player within the slice of riders. +func (p *Player) seat(e entity.Rideable) int { + riders := e.Riders() + for i, r := range riders { + if r == p { + return i + } + } + return -1 +} + +// setRiding saves the entity the Rider is currently riding. +func (p *Player) setRiding(e entity.Rideable) { + p.ridingMu.Lock() + p.riding = e + p.ridingMu.Unlock() +} + +// RidingEntity returns the entity the player is currently riding and the player's seat index. +func (p *Player) RidingEntity() (entity.Rideable, int) { + p.ridingMu.Lock() + defer p.ridingMu.Unlock() + if p.riding != nil { + riders := p.riding.Riders() + for i, r := range riders { + if r == p { + return p.riding, i + } + } + return p.riding, -1 + } + return nil, -1 +} + // UpdateDiagnostics updates the diagnostics of the player. func (p *Player) UpdateDiagnostics(d session.Diagnostics) { p.Handler().HandleDiagnostics(p, d) @@ -2836,6 +2943,7 @@ func (p *Player) close(msg string) { p.respawn(func(np *Player) { np.quit(msg) }) + p.DismountEntity() return } p.quit(msg) diff --git a/server/session/controllable.go b/server/session/controllable.go index 86feaee8e..bb76719f2 100644 --- a/server/session/controllable.go +++ b/server/session/controllable.go @@ -3,6 +3,7 @@ package session import ( "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/cmd" + "github.com/df-mc/dragonfly/server/entity" "github.com/df-mc/dragonfly/server/entity/effect" "github.com/df-mc/dragonfly/server/item" "github.com/df-mc/dragonfly/server/item/inventory" @@ -11,6 +12,7 @@ import ( "github.com/df-mc/dragonfly/server/player/form" "github.com/df-mc/dragonfly/server/player/skin" "github.com/df-mc/dragonfly/server/world" + "github.com/go-gl/mathgl/mgl32" "github.com/go-gl/mathgl/mgl64" "github.com/google/uuid" "golang.org/x/text/language" @@ -95,6 +97,11 @@ type Controllable interface { FinishBreaking() AbortBreaking() + SeatPosition() mgl32.Vec3 + MountEntity(e entity.Rideable) + DismountEntity() + RidingEntity() (entity.Rideable, int) + Exhaust(points float64) OpenSign(pos cube.Pos, frontSide bool) diff --git a/server/session/entity_metadata.go b/server/session/entity_metadata.go index cc804c072..16fe8aa6d 100644 --- a/server/session/entity_metadata.go +++ b/server/session/entity_metadata.go @@ -105,6 +105,12 @@ func (s *Session) addSpecificMetadata(e any, m protocol.EntityMetadata) { m[protocol.EntityDataKeyFuseTime] = int32(t.Fuse().Milliseconds() / 50) m.SetFlag(protocol.EntityDataKeyFlags, protocol.EntityDataFlagIgnited) } + if r, ok := e.(entity.Rider); ok { + m[protocol.EntityDataKeySeatOffset] = r.SeatPosition() + if rd, _ := r.RidingEntity(); rd != nil { + m.SetFlag(protocol.EntityDataKeyFlags, protocol.EntityDataFlagRiding) + } + } if n, ok := e.(named); ok { m[protocol.EntityDataKeyName] = n.NameTag() m[protocol.EntityDataKeyAlwaysShowNameTag] = uint8(1) diff --git a/server/session/handler_interact.go b/server/session/handler_interact.go index 31ef655bb..fda4686ec 100644 --- a/server/session/handler_interact.go +++ b/server/session/handler_interact.go @@ -35,6 +35,10 @@ func (h *InteractHandler) Handle(p packet.Packet, s *Session, _ *world.Tx, c Con int32(pos[2]), }, }) + case packet.InteractActionLeaveVehicle: + if e, _ := c.RidingEntity(); e != nil { + c.DismountEntity() + } default: return fmt.Errorf("unexpected interact packet action %v", pk.ActionType) } diff --git a/server/session/handler_inventory_transaction.go b/server/session/handler_inventory_transaction.go index 2d1cecb03..0b00db33d 100644 --- a/server/session/handler_inventory_transaction.go +++ b/server/session/handler_inventory_transaction.go @@ -3,6 +3,7 @@ package session import ( "fmt" "github.com/df-mc/dragonfly/server/block/cube" + "github.com/df-mc/dragonfly/server/entity" "github.com/df-mc/dragonfly/server/event" "github.com/df-mc/dragonfly/server/item" "github.com/df-mc/dragonfly/server/item/inventory" @@ -134,6 +135,10 @@ func (h *InventoryTransactionHandler) handleUseItemOnEntityTransaction(data *pro var valid bool switch data.ActionType { case protocol.UseItemOnEntityActionInteract: + // Check if the entity is rideable, and if so ride the entity. + if r, ok := e.(entity.Rideable); ok { + c.MountEntity(r) + } valid = c.UseItemOnEntity(e) case protocol.UseItemOnEntityActionAttack: valid = c.AttackEntity(e) diff --git a/server/session/handler_player_auth_input.go b/server/session/handler_player_auth_input.go index 19adc2473..b83b6e193 100644 --- a/server/session/handler_player_auth_input.go +++ b/server/session/handler_player_auth_input.go @@ -41,6 +41,16 @@ func (h PlayerAuthInputHandler) handleMovement(pk *packet.PlayerAuthInput, s *Se } } + // Check if player is riding an entity, and move the entity. + riding, seat := c.RidingEntity() + if riding != nil { + if seat == 0 { + m := pk.MoveVector + riding.Move(mgl64.Vec2{float64(m[0]), float64(m[1])}, pk.Yaw, pk.Pitch) + } + s.ViewEntityMount(c, riding, seat-1 == 0) + } + pk.Position = pk.Position.Sub(mgl32.Vec3{0, 1.62}) // Sub the base offset of players from the pos. newPos := vec32To64(pk.Position) diff --git a/server/session/world.go b/server/session/world.go index e4628bb13..675f6c71f 100644 --- a/server/session/world.go +++ b/server/session/world.go @@ -262,6 +262,31 @@ func (s *Session) ViewEntityTeleport(e world.Entity, position mgl64.Vec3) { }) } +// ViewEntityMount ... +func (s *Session) ViewEntityMount(r world.Entity, rd world.Entity, driver bool) { + linkType := protocol.EntityLinkPassenger + if driver { + linkType = protocol.EntityLinkRider + } + s.writePacket(&packet.SetActorLink{EntityLink: protocol.EntityLink{ + RiddenEntityUniqueID: int64(s.entityRuntimeID(rd)), + RiderEntityUniqueID: int64(s.entityRuntimeID(r)), + Type: byte(linkType), + RiderInitiated: true, + }}) +} + +// ViewEntityDismount ... +func (s *Session) ViewEntityDismount(r world.Entity, rd world.Entity) { + s.writePacket(&packet.SetActorLink{EntityLink: protocol.EntityLink{ + RiddenEntityUniqueID: int64(s.entityRuntimeID(rd)), + RiderEntityUniqueID: int64(s.entityRuntimeID(r)), + Type: byte(protocol.EntityLinkRemove), + RiderInitiated: true, + Immediate: true, + }}) +} + // ViewEntityItems ... func (s *Session) ViewEntityItems(e world.Entity) { runtimeID := s.entityRuntimeID(e) diff --git a/server/world/viewer.go b/server/world/viewer.go index 7ffbbbebf..be06eb6eb 100644 --- a/server/world/viewer.go +++ b/server/world/viewer.go @@ -29,6 +29,11 @@ type Viewer interface { // ViewEntityTeleport views the teleportation of an Entity. The Entity is immediately moved to a different // target position. ViewEntityTeleport(e Entity, pos mgl64.Vec3) + // ViewEntityMount views one entity mounting another. It is called when any entity mounts another or + // changes its role (passenger or driver). + ViewEntityMount(r Entity, rd Entity, driver bool) + // ViewEntityDismount views one entity dismounting another. It is called when any entity is dismounted. + ViewEntityDismount(r Entity, rd Entity) // ViewFurnaceUpdate updates a furnace for the associated session based on previous times. ViewFurnaceUpdate(prevCookTime, cookTime, prevRemainingFuelTime, remainingFuelTime, prevMaxFuelTime, maxFuelTime time.Duration) // ViewBrewingUpdate updates a brewing stand for the associated session based on previous times. @@ -103,3 +108,5 @@ func (NopViewer) ViewWeather(bool, bool) func (NopViewer) ViewBrewingUpdate(time.Duration, time.Duration, int32, int32, int32, int32) {} func (NopViewer) ViewFurnaceUpdate(time.Duration, time.Duration, time.Duration, time.Duration, time.Duration, time.Duration) { } +func (NopViewer) ViewEntityMount(Entity, Entity, bool) {} +func (NopViewer) ViewEntityDismount(Entity, Entity) {} From 929350a8cbbb5c300f7fa8efc970c109231e7548 Mon Sep 17 00:00:00 2001 From: glancist Date: Sat, 30 Nov 2024 20:23:53 +0000 Subject: [PATCH 3/3] Revert "merge entity riding" This reverts commit 6c7d4186648c5629c3344bf37113755f498e742a. --- server/entity/rideable.go | 22 ---- server/entity/rider.go | 13 --- server/player/handler.go | 9 -- server/player/player.go | 108 ------------------ server/session/controllable.go | 7 -- server/session/entity_metadata.go | 6 - server/session/handler_interact.go | 4 - .../session/handler_inventory_transaction.go | 5 - server/session/handler_player_auth_input.go | 10 -- server/session/world.go | 25 ---- server/world/viewer.go | 7 -- 11 files changed, 216 deletions(-) delete mode 100644 server/entity/rideable.go delete mode 100644 server/entity/rider.go diff --git a/server/entity/rideable.go b/server/entity/rideable.go deleted file mode 100644 index 8595ad6c8..000000000 --- a/server/entity/rideable.go +++ /dev/null @@ -1,22 +0,0 @@ -package entity - -import ( - "github.com/df-mc/dragonfly/server/world" - "github.com/go-gl/mathgl/mgl32" - "github.com/go-gl/mathgl/mgl64" -) - -// Rideable is an interface for entities that can be ridden. -type Rideable interface { - world.Entity - // SeatPositions returns the possible seat positions for an entity in the order that they will be filled. - SeatPositions() []mgl32.Vec3 - // Riders returns a slice entities that are currently riding an entity in the order that they were added. - Riders() []Rider - // AddRider adds a rider to the entity. - AddRider(e Rider) - // RemoveRider removes a rider from the entity. - RemoveRider(e Rider) - // Move moves the entity using the given vector, yaw, and pitch. - Move(vector mgl64.Vec2, yaw, pitch float32) -} diff --git a/server/entity/rider.go b/server/entity/rider.go deleted file mode 100644 index cdc7a3c0e..000000000 --- a/server/entity/rider.go +++ /dev/null @@ -1,13 +0,0 @@ -package entity - -import "github.com/go-gl/mathgl/mgl32" - -// Rider is an interface for entities that can ride other entities. -type Rider interface { - // SeatPosition returns the Rider's current seat position. - SeatPosition() mgl32.Vec3 - // MountEntity mounts the Rider to an entity if the entity is Rideable and if there is a seat available. - MountEntity(e Rideable) - // RidingEntity returns the entity the player is currently riding and the player's seat index. - RidingEntity() (Rideable, int) -} diff --git a/server/player/handler.go b/server/player/handler.go index 61eced171..92adcefe4 100644 --- a/server/player/handler.go +++ b/server/player/handler.go @@ -3,7 +3,6 @@ package player import ( "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/cmd" - "github.com/df-mc/dragonfly/server/entity" "github.com/df-mc/dragonfly/server/event" "github.com/df-mc/dragonfly/server/item" "github.com/df-mc/dragonfly/server/player/skin" @@ -153,12 +152,6 @@ type Handler interface { // not sent by every client however, only those with the "Creator > Enable Client Diagnostics" setting // enabled. HandleDiagnostics(p *Player, d session.Diagnostics) - // HandleMount handles when a player mounts an entity. ctx.Cancel() may be called to cancel the player mounting - // an entity. - HandleMount(ctx *Context, r entity.Rideable) - // HandleDismount handles when a player mounts an entity. ctx.Cancel() may be called to force the player - // to re-mount the entity. - HandleDismount(ctx *Context) } // NopHandler implements the Handler interface but does not execute any code when an event is called. The @@ -205,5 +198,3 @@ func (NopHandler) HandleDeath(*Player, world.DamageSource, *bool) func (NopHandler) HandleRespawn(*Player, *mgl64.Vec3, **world.World) {} func (NopHandler) HandleQuit(*Player) {} func (NopHandler) HandleDiagnostics(*Player, session.Diagnostics) {} -func (NopHandler) HandleMount(*Context, entity.Rideable) {} -func (NopHandler) HandleDismount(*Context) {} diff --git a/server/player/player.go b/server/player/player.go index ee27773c0..8267aaa12 100644 --- a/server/player/player.go +++ b/server/player/player.go @@ -2,7 +2,6 @@ package player import ( "fmt" - "github.com/go-gl/mathgl/mgl32" "math" "math/rand" "net" @@ -53,10 +52,6 @@ type playerData struct { armour *inventory.Armour heldSlot *uint32 - seatPosition mgl32.Vec3 - ridingMu sync.Mutex - riding entity.Rideable - sneaking, sprinting, swimming, gliding, crawling, flying, invisible, immobile, onGround, usingItem bool usingSince time.Time @@ -839,7 +834,6 @@ func (p *Player) kill(src world.DamageSource) { // Wait a little before removing the entity. The client displays a death // animation while the player is dying. time.AfterFunc(time.Millisecond*1100, func() { - p.DismountEntity() p.H().ExecWorld(finishDying) }) } @@ -2752,107 +2746,6 @@ func (p *Player) PunchAir() { p.tx.PlaySound(p.Position(), sound.Attack{}) } -// MountEntity mounts the player to an entity if the entity is rideable and if there is a seat available. -func (p *Player) MountEntity(r entity.Rideable) { - ctx := event.C(p) - if p.Handler().HandleMount(ctx, r); ctx.Cancelled() { - return - } - if p.seat(r) == -1 { - r.AddRider(p) - p.setRiding(r) - riders := r.Riders() - seat := len(riders) - positions := r.SeatPositions() - if len(positions) >= seat { - p.seatPosition = positions[seat-1] - p.updateState() - for _, v := range p.viewers() { - v.ViewEntityMount(p, r, seat-1 == 0) - } - } - return - } - // Check and update seat position - p.checkSeats(r) -} - -// DismountEntity dismounts the player from an entity. -func (p *Player) DismountEntity() { - ctx := event.C(p) - e, seat := p.RidingEntity() - if e != nil { - if p.Handler().HandleDismount(ctx); ctx.Cancelled() { - p.s.ViewEntityMount(p, e, seat-1 == 0) - return - } - e.RemoveRider(p) - p.setRiding(nil) - for _, v := range p.viewers() { - v.ViewEntityDismount(p, e) - } - for _, r := range e.Riders() { - r.MountEntity(e) - } - } -} - -// checkSeats moves a player to the seat corresponding to their current index within the slice of riders. -func (p *Player) checkSeats(e entity.Rideable) { - seat := p.seat(e) - if seat != -1 { - positions := e.SeatPositions() - if positions[seat] != p.seatPosition { - p.seatPosition = positions[seat] - if seat == 0 { - for _, v := range p.viewers() { - v.ViewEntityMount(p, e, true) - } - } - p.updateState() - } - } -} - -// SeatPosition returns the position of the player's seat. -func (p *Player) SeatPosition() mgl32.Vec3 { - return p.seatPosition -} - -// seat returns the index of a player within the slice of riders. -func (p *Player) seat(e entity.Rideable) int { - riders := e.Riders() - for i, r := range riders { - if r == p { - return i - } - } - return -1 -} - -// setRiding saves the entity the Rider is currently riding. -func (p *Player) setRiding(e entity.Rideable) { - p.ridingMu.Lock() - p.riding = e - p.ridingMu.Unlock() -} - -// RidingEntity returns the entity the player is currently riding and the player's seat index. -func (p *Player) RidingEntity() (entity.Rideable, int) { - p.ridingMu.Lock() - defer p.ridingMu.Unlock() - if p.riding != nil { - riders := p.riding.Riders() - for i, r := range riders { - if r == p { - return p.riding, i - } - } - return p.riding, -1 - } - return nil, -1 -} - // UpdateDiagnostics updates the diagnostics of the player. func (p *Player) UpdateDiagnostics(d session.Diagnostics) { p.Handler().HandleDiagnostics(p, d) @@ -2943,7 +2836,6 @@ func (p *Player) close(msg string) { p.respawn(func(np *Player) { np.quit(msg) }) - p.DismountEntity() return } p.quit(msg) diff --git a/server/session/controllable.go b/server/session/controllable.go index bb76719f2..86feaee8e 100644 --- a/server/session/controllable.go +++ b/server/session/controllable.go @@ -3,7 +3,6 @@ package session import ( "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/cmd" - "github.com/df-mc/dragonfly/server/entity" "github.com/df-mc/dragonfly/server/entity/effect" "github.com/df-mc/dragonfly/server/item" "github.com/df-mc/dragonfly/server/item/inventory" @@ -12,7 +11,6 @@ import ( "github.com/df-mc/dragonfly/server/player/form" "github.com/df-mc/dragonfly/server/player/skin" "github.com/df-mc/dragonfly/server/world" - "github.com/go-gl/mathgl/mgl32" "github.com/go-gl/mathgl/mgl64" "github.com/google/uuid" "golang.org/x/text/language" @@ -97,11 +95,6 @@ type Controllable interface { FinishBreaking() AbortBreaking() - SeatPosition() mgl32.Vec3 - MountEntity(e entity.Rideable) - DismountEntity() - RidingEntity() (entity.Rideable, int) - Exhaust(points float64) OpenSign(pos cube.Pos, frontSide bool) diff --git a/server/session/entity_metadata.go b/server/session/entity_metadata.go index 16fe8aa6d..cc804c072 100644 --- a/server/session/entity_metadata.go +++ b/server/session/entity_metadata.go @@ -105,12 +105,6 @@ func (s *Session) addSpecificMetadata(e any, m protocol.EntityMetadata) { m[protocol.EntityDataKeyFuseTime] = int32(t.Fuse().Milliseconds() / 50) m.SetFlag(protocol.EntityDataKeyFlags, protocol.EntityDataFlagIgnited) } - if r, ok := e.(entity.Rider); ok { - m[protocol.EntityDataKeySeatOffset] = r.SeatPosition() - if rd, _ := r.RidingEntity(); rd != nil { - m.SetFlag(protocol.EntityDataKeyFlags, protocol.EntityDataFlagRiding) - } - } if n, ok := e.(named); ok { m[protocol.EntityDataKeyName] = n.NameTag() m[protocol.EntityDataKeyAlwaysShowNameTag] = uint8(1) diff --git a/server/session/handler_interact.go b/server/session/handler_interact.go index fda4686ec..31ef655bb 100644 --- a/server/session/handler_interact.go +++ b/server/session/handler_interact.go @@ -35,10 +35,6 @@ func (h *InteractHandler) Handle(p packet.Packet, s *Session, _ *world.Tx, c Con int32(pos[2]), }, }) - case packet.InteractActionLeaveVehicle: - if e, _ := c.RidingEntity(); e != nil { - c.DismountEntity() - } default: return fmt.Errorf("unexpected interact packet action %v", pk.ActionType) } diff --git a/server/session/handler_inventory_transaction.go b/server/session/handler_inventory_transaction.go index 0b00db33d..2d1cecb03 100644 --- a/server/session/handler_inventory_transaction.go +++ b/server/session/handler_inventory_transaction.go @@ -3,7 +3,6 @@ package session import ( "fmt" "github.com/df-mc/dragonfly/server/block/cube" - "github.com/df-mc/dragonfly/server/entity" "github.com/df-mc/dragonfly/server/event" "github.com/df-mc/dragonfly/server/item" "github.com/df-mc/dragonfly/server/item/inventory" @@ -135,10 +134,6 @@ func (h *InventoryTransactionHandler) handleUseItemOnEntityTransaction(data *pro var valid bool switch data.ActionType { case protocol.UseItemOnEntityActionInteract: - // Check if the entity is rideable, and if so ride the entity. - if r, ok := e.(entity.Rideable); ok { - c.MountEntity(r) - } valid = c.UseItemOnEntity(e) case protocol.UseItemOnEntityActionAttack: valid = c.AttackEntity(e) diff --git a/server/session/handler_player_auth_input.go b/server/session/handler_player_auth_input.go index b83b6e193..19adc2473 100644 --- a/server/session/handler_player_auth_input.go +++ b/server/session/handler_player_auth_input.go @@ -41,16 +41,6 @@ func (h PlayerAuthInputHandler) handleMovement(pk *packet.PlayerAuthInput, s *Se } } - // Check if player is riding an entity, and move the entity. - riding, seat := c.RidingEntity() - if riding != nil { - if seat == 0 { - m := pk.MoveVector - riding.Move(mgl64.Vec2{float64(m[0]), float64(m[1])}, pk.Yaw, pk.Pitch) - } - s.ViewEntityMount(c, riding, seat-1 == 0) - } - pk.Position = pk.Position.Sub(mgl32.Vec3{0, 1.62}) // Sub the base offset of players from the pos. newPos := vec32To64(pk.Position) diff --git a/server/session/world.go b/server/session/world.go index 675f6c71f..e4628bb13 100644 --- a/server/session/world.go +++ b/server/session/world.go @@ -262,31 +262,6 @@ func (s *Session) ViewEntityTeleport(e world.Entity, position mgl64.Vec3) { }) } -// ViewEntityMount ... -func (s *Session) ViewEntityMount(r world.Entity, rd world.Entity, driver bool) { - linkType := protocol.EntityLinkPassenger - if driver { - linkType = protocol.EntityLinkRider - } - s.writePacket(&packet.SetActorLink{EntityLink: protocol.EntityLink{ - RiddenEntityUniqueID: int64(s.entityRuntimeID(rd)), - RiderEntityUniqueID: int64(s.entityRuntimeID(r)), - Type: byte(linkType), - RiderInitiated: true, - }}) -} - -// ViewEntityDismount ... -func (s *Session) ViewEntityDismount(r world.Entity, rd world.Entity) { - s.writePacket(&packet.SetActorLink{EntityLink: protocol.EntityLink{ - RiddenEntityUniqueID: int64(s.entityRuntimeID(rd)), - RiderEntityUniqueID: int64(s.entityRuntimeID(r)), - Type: byte(protocol.EntityLinkRemove), - RiderInitiated: true, - Immediate: true, - }}) -} - // ViewEntityItems ... func (s *Session) ViewEntityItems(e world.Entity) { runtimeID := s.entityRuntimeID(e) diff --git a/server/world/viewer.go b/server/world/viewer.go index be06eb6eb..7ffbbbebf 100644 --- a/server/world/viewer.go +++ b/server/world/viewer.go @@ -29,11 +29,6 @@ type Viewer interface { // ViewEntityTeleport views the teleportation of an Entity. The Entity is immediately moved to a different // target position. ViewEntityTeleport(e Entity, pos mgl64.Vec3) - // ViewEntityMount views one entity mounting another. It is called when any entity mounts another or - // changes its role (passenger or driver). - ViewEntityMount(r Entity, rd Entity, driver bool) - // ViewEntityDismount views one entity dismounting another. It is called when any entity is dismounted. - ViewEntityDismount(r Entity, rd Entity) // ViewFurnaceUpdate updates a furnace for the associated session based on previous times. ViewFurnaceUpdate(prevCookTime, cookTime, prevRemainingFuelTime, remainingFuelTime, prevMaxFuelTime, maxFuelTime time.Duration) // ViewBrewingUpdate updates a brewing stand for the associated session based on previous times. @@ -108,5 +103,3 @@ func (NopViewer) ViewWeather(bool, bool) func (NopViewer) ViewBrewingUpdate(time.Duration, time.Duration, int32, int32, int32, int32) {} func (NopViewer) ViewFurnaceUpdate(time.Duration, time.Duration, time.Duration, time.Duration, time.Duration, time.Duration) { } -func (NopViewer) ViewEntityMount(Entity, Entity, bool) {} -func (NopViewer) ViewEntityDismount(Entity, Entity) {}