-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server/item: Implemented suspicious stew. (#664)
- Loading branch information
1 parent
1e05e0c
commit 967faf1
Showing
3 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
// 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |