Skip to content

Commit

Permalink
splash_potion.go: Make throwableOffset() accept and return a cube.Rot…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
mmm545 committed Dec 24, 2024
1 parent 343d086 commit 9b61275
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
4 changes: 1 addition & 3 deletions server/item/bottle_of_enchanting.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ type BottleOfEnchanting struct{}
// Use ...
func (b BottleOfEnchanting) Use(tx *world.Tx, user User, ctx *UseContext) bool {
create := tx.World().EntityRegistry().Config().BottleOfEnchanting
r := user.Rotation()
r[1] = throwableOffset(r[1])
opts := world.EntitySpawnOpts{Position: eyePosition(user), Velocity: r.Vec3().Mul(0.6)}
opts := world.EntitySpawnOpts{Position: eyePosition(user), Velocity: throwableOffset(user.Rotation()).Vec3().Mul(0.6)}
tx.AddEntity(create(opts, user))
tx.PlaySound(user.Position(), sound.ItemThrow{})

Expand Down
4 changes: 1 addition & 3 deletions server/item/lingering_potion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ func (l LingeringPotion) MaxCount() int {
// Use ...
func (l LingeringPotion) Use(tx *world.Tx, user User, ctx *UseContext) bool {
create := tx.World().EntityRegistry().Config().LingeringPotion
r := user.Rotation()
r[1] = throwableOffset(r[1])
opts := world.EntitySpawnOpts{Position: eyePosition(user), Velocity: r.Vec3().Mul(0.5)}
opts := world.EntitySpawnOpts{Position: eyePosition(user), Velocity: throwableOffset(user.Rotation()).Vec3().Mul(0.5)}
tx.AddEntity(create(opts, l.Type, user))
tx.PlaySound(user.Position(), sound.ItemThrow{})

Expand Down
15 changes: 7 additions & 8 deletions server/item/splash_potion.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package item

import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/item/potion"
"github.com/df-mc/dragonfly/server/world"
"github.com/df-mc/dragonfly/server/world/sound"
Expand All @@ -21,9 +22,7 @@ func (s SplashPotion) MaxCount() int {
// Use ...
func (s SplashPotion) Use(tx *world.Tx, user User, ctx *UseContext) bool {
create := tx.World().EntityRegistry().Config().SplashPotion
r := user.Rotation()
r[1] = throwableOffset(r[1])
opts := world.EntitySpawnOpts{Position: eyePosition(user), Velocity: r.Vec3().Mul(0.5)}
opts := world.EntitySpawnOpts{Position: eyePosition(user), Velocity: throwableOffset(user.Rotation()).Vec3().Mul(0.5)}
tx.AddEntity(create(opts, s.Type, user))
tx.PlaySound(user.Position(), sound.ItemThrow{})

Expand All @@ -36,12 +35,12 @@ func (s SplashPotion) Use(tx *world.Tx, user User, ctx *UseContext) bool {
// Bottle o' Enchanting are thrown at a higher angle than where the
// player is looking at.
// The added offset is an ellipse-like shape based on what the input pitch is.
func throwableOffset(pitch float64) float64 {
pitch = max(min(pitch, 89.9), -89.9)
pitch -= math.Sqrt(math.Pow(89.9, 2)-math.Pow(pitch, 2)) * (26.5 / 89.9)
pitch = max(min(pitch, 89.9), -89.9)
func throwableOffset(r cube.Rotation) cube.Rotation {
r[1] = max(min(r[1], 89.9), -89.9)
r[1] -= math.Sqrt(math.Pow(89.9, 2)-math.Pow(r[1], 2)) * (26.5 / 89.9)
r[1] = max(min(r[1], 89.9), -89.9)

return pitch
return r
}

// EncodeItem ...
Expand Down

0 comments on commit 9b61275

Please sign in to comment.