Skip to content

Commit

Permalink
Fixed throwing velocity of splash and lingering potions and bottle o'…
Browse files Browse the repository at this point in the history
… enchanting (#972)
  • Loading branch information
mmm545 authored Dec 24, 2024
1 parent 69cca3a commit 918a904
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion server/entity/effect/fire_resistance.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ type fireResistance struct {

// RGBA ...
func (fireResistance) RGBA() color.RGBA {
return color.RGBA{R: 0xe4, G: 0x9a, B: 0x3a, A: 0xff}
return color.RGBA{R: 0xff, G: 0x99, B: 0x00, A: 0xff}
}
2 changes: 1 addition & 1 deletion server/entity/effect/instant_damage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (i instantDamage) Apply(e world.Entity, eff Effect) {

// RGBA ...
func (instantDamage) RGBA() color.RGBA {
return color.RGBA{R: 0x43, G: 0x0a, B: 0x09, A: 0xff}
return color.RGBA{R: 0xa9, G: 0x65, B: 0x6a, A: 0xff}
}

// InstantDamageSource is used for damage caused by an effect.instantDamage
Expand Down
2 changes: 1 addition & 1 deletion server/entity/effect/invisibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ func (invisibility) End(e world.Entity, _ int) {

// RGBA ...
func (invisibility) RGBA() color.RGBA {
return color.RGBA{R: 0x7f, G: 0x83, B: 0x92, A: 0xff}
return color.RGBA{R: 0xf6, G: 0xf6, B: 0xf6, A: 0xff}
}
2 changes: 1 addition & 1 deletion server/entity/effect/jump_boost.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ type jumpBoost struct {

// RGBA ...
func (jumpBoost) RGBA() color.RGBA {
return color.RGBA{R: 0x22, G: 0xff, B: 0x4c, A: 0xff}
return color.RGBA{R: 0xfd, G: 0xff, B: 0x84, A: 0xff}
}
2 changes: 1 addition & 1 deletion server/entity/effect/night_vision.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ type nightVision struct {

// RGBA ...
func (nightVision) RGBA() color.RGBA {
return color.RGBA{R: 0x1f, G: 0x1f, B: 0xa1, A: 0xff}
return color.RGBA{R: 0xc2, G: 0xff, B: 0x66, A: 0xff}
}
2 changes: 1 addition & 1 deletion server/entity/effect/poison.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (poison) Apply(e world.Entity, eff Effect) {

// RGBA ...
func (poison) RGBA() color.RGBA {
return color.RGBA{R: 0x4e, G: 0x93, B: 0x31, A: 0xff}
return color.RGBA{R: 0x87, G: 0xa3, B: 0x63, A: 0xff}
}

// PoisonDamageSource is used for damage caused by an effect.poison or
Expand Down
2 changes: 1 addition & 1 deletion server/entity/effect/resistance.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ func (resistance) Multiplier(e world.DamageSource, lvl int) float64 {

// RGBA ...
func (resistance) RGBA() color.RGBA {
return color.RGBA{R: 0x99, G: 0x45, B: 0x3a, A: 0xff}
return color.RGBA{R: 0x91, G: 0x46, B: 0xf0, A: 0xff}
}
2 changes: 1 addition & 1 deletion server/entity/effect/slow_falling.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ type slowFalling struct {

// RGBA ...
func (slowFalling) RGBA() color.RGBA {
return color.RGBA{R: 0xf7, G: 0xf8, B: 0xe0, A: 0xff}
return color.RGBA{R: 0xf3, G: 0xcf, B: 0xb9, A: 0xff}
}
2 changes: 1 addition & 1 deletion server/entity/effect/slowness.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ func (slowness) End(e world.Entity, lvl int) {

// RGBA ...
func (slowness) RGBA() color.RGBA {
return color.RGBA{R: 0x5a, G: 0x6c, B: 0x81, A: 0xff}
return color.RGBA{R: 0x8b, G: 0xaf, B: 0xe0, A: 0xff}
}
2 changes: 1 addition & 1 deletion server/entity/effect/speed.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ func (speed) End(e world.Entity, lvl int) {

// RGBA ...
func (speed) RGBA() color.RGBA {
return color.RGBA{R: 0x7c, G: 0xaf, B: 0xc6, A: 0xff}
return color.RGBA{R: 0x33, G: 0xeb, B: 0xff, A: 0xff}
}
2 changes: 1 addition & 1 deletion server/entity/effect/water_breathing.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ type waterBreathing struct {

// RGBA ...
func (waterBreathing) RGBA() color.RGBA {
return color.RGBA{R: 0x2e, G: 0x52, B: 0x99, A: 0xff}
return color.RGBA{R: 0x98, G: 0xda, B: 0xc0, A: 0xff}
}
2 changes: 1 addition & 1 deletion server/entity/effect/wither.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (wither) Apply(e world.Entity, eff Effect) {

// RGBA ...
func (wither) RGBA() color.RGBA {
return color.RGBA{R: 0x35, G: 0x2a, B: 0x27, A: 0xff}
return color.RGBA{R: 0x73, G: 0x61, B: 0x56, A: 0xff}
}

// WitherDamageSource is used for damage caused by an effect.wither applied
Expand Down
8 changes: 0 additions & 8 deletions server/item/book_and_quill.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,3 @@ func (b BookAndQuill) EncodeNBT() map[string]any {
func (BookAndQuill) EncodeItem() (name string, meta int16) {
return "minecraft:writable_book", 0
}

// max ...
func max(a, b int) int {
if a > b {
return a
}
return b
}
2 changes: 1 addition & 1 deletion server/item/bottle_of_enchanting.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type BottleOfEnchanting struct{}
// Use ...
func (b BottleOfEnchanting) Use(tx *world.Tx, user User, ctx *UseContext) bool {
create := tx.World().EntityRegistry().Config().BottleOfEnchanting
opts := world.EntitySpawnOpts{Position: eyePosition(user), Velocity: user.Rotation().Vec3().Mul(0.7)}
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
2 changes: 1 addition & 1 deletion server/item/lingering_potion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +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
opts := world.EntitySpawnOpts{Position: eyePosition(user), Velocity: user.Rotation().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
17 changes: 16 additions & 1 deletion server/item/splash_potion.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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"
"math"
)

// SplashPotion is an item that grants effects when thrown.
Expand All @@ -20,14 +22,27 @@ func (s SplashPotion) MaxCount() int {
// Use ...
func (s SplashPotion) Use(tx *world.Tx, user User, ctx *UseContext) bool {
create := tx.World().EntityRegistry().Config().SplashPotion
opts := world.EntitySpawnOpts{Position: eyePosition(user), Velocity: user.Rotation().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{})

ctx.SubtractFromCount(1)
return true
}

// throwableOffset adds an upwards offset pitch to a throwable entity.
// In vanilla, items such as Splash Potions, Lingering Potions, and
// 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(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 r
}

// EncodeItem ...
func (s SplashPotion) EncodeItem() (name string, meta int16) {
return "minecraft:splash_potion", int16(s.Type.Uint8())
Expand Down

0 comments on commit 918a904

Please sign in to comment.