Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented suspicious stew #664

Merged
merged 9 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/item/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,7 @@ func init() {
for _, disc := range sound.MusicDiscs() {
world.RegisterItem(MusicDisc{DiscType: disc})
}
for _, stew := range StewTypes() {
world.RegisterItem(SuspiciousStew{Type: stew})
}
}
38 changes: 38 additions & 0 deletions server/item/suspicious_stew.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package item

import (
"github.com/df-mc/dragonfly/server/world"
)

// SuspiciousStew is a food item that can give the player a status effect that depends on the flower used to craft it.
type SuspiciousStew struct {
defaultFood
JustTalDevelops marked this conversation as resolved.
Show resolved Hide resolved

// Type specifies the type of effect will be given to the player
Type StewType
}

// MaxCount ...
func (SuspiciousStew) MaxCount() int {
return 1
}

// AlwaysConsumable ...
func (SuspiciousStew) AlwaysConsumable() bool {
return true
}

// EncodeItem ...
func (s SuspiciousStew) EncodeItem() (name string, meta int16) {
return "minecraft:suspicious_stew", int16(s.Type.Uint8())
}

// Consume ...
func (s SuspiciousStew) Consume(_ *world.World, c Consumer) Stack {
for _, effect := range s.Type.Effects() {
c.AddEffect(effect)
}
c.Saturate(6, 7.2)

return NewStack(Bowl{}, 1)
}
106 changes: 106 additions & 0 deletions server/item/suspicious_stew_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package item

import (
"time"

"github.com/df-mc/dragonfly/server/entity/effect"
)

// StewType represents a type of suspicious stew.
type StewType struct {
stewType
}

// NightVisionStew returns suspicious stew night vision effect.
func NightVisionStew() StewType {
return StewType{0}
}

// JumpBoostStew returns suspicious stew jump boost effect.
func JumpBoostStew() StewType {
return StewType{1}
}

// WeaknessStew returns suspicious stew weakness effect.
func WeaknessStew() StewType {
return StewType{2}
}

// BlindnessStew returns suspicious stew blindness effect.
func BlindnessStew() StewType {
return StewType{3}
}

// PoisonStew returns suspicious stew poison effect.
func PoisonStew() StewType {
return StewType{4}
}

// SaturationDandelionStew returns suspicious stew saturation effect.
func SaturationDandelionStew() StewType {
return StewType{5}
}

// SaturationOrchidStew returns suspicious stew saturation effect.
func SaturationOrchidStew() StewType {
return StewType{6}
}

// FireResistanceStew returns suspicious stew fire resistance effect.
func FireResistanceStew() StewType {
return StewType{7}
}

// RegenerationStew returns suspicious stew regeneration effect.
func RegenerationStew() StewType {
return StewType{8}
}

// WitherStew returns suspicious stew wither effect.
func WitherStew() StewType {
return StewType{9}
}

// StewTypes ...
func StewTypes() []StewType {
return []StewType{NightVisionStew(), JumpBoostStew(), WeaknessStew(), BlindnessStew(), PoisonStew(), SaturationDandelionStew(), SaturationOrchidStew(), FireResistanceStew(), RegenerationStew(), WitherStew()}
}

type stewType uint8

// Uint8 returns the stew as a uint8.
func (s stewType) Uint8() uint8 {
return uint8(s)
}

// Effects returns suspicious stew effects.
func (s stewType) Effects() []effect.Effect {
effects := []effect.Effect{}

switch s.Uint8() {
case 0:
effects = append(effects, effect.New(effect.NightVision{}, 1, time.Second*4))
case 1:
effects = append(effects, effect.New(effect.JumpBoost{}, 1, time.Second*4))
case 2:
effects = append(effects, effect.New(effect.Weakness{}, 1, time.Second*7))
case 3:
effects = append(effects, effect.New(effect.Blindness{}, 1, time.Second*6))
case 4:
effects = append(effects, effect.New(effect.Poison{}, 1, time.Second*10))
case 5:
effects = append(effects, effect.New(effect.Saturation{}, 1, time.Second*3/10))
case 6:
effects = append(effects, effect.New(effect.Saturation{}, 1, time.Second*3/10))
case 7:
effects = append(effects, effect.New(effect.FireResistance{}, 1, time.Second*2))
case 8:
effects = append(effects, effect.New(effect.Regeneration{}, 1, time.Second*6))
case 9:
effects = append(effects, effect.New(effect.Wither{}, 1, time.Second*6))
default:
panic("should never happen")
}

return effects
}