-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
70 lines (56 loc) · 1.83 KB
/
main.go
File metadata and controls
70 lines (56 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"github.com/bedrock-gophers/living/living"
"github.com/bedrock-gophers/spawner/spawner"
_ "github.com/bedrock-gophers/spawner/spawner"
"github.com/df-mc/dragonfly/server"
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/entity"
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/player"
"github.com/df-mc/dragonfly/server/player/chat"
"github.com/df-mc/dragonfly/server/world"
"github.com/sirupsen/logrus"
"math/rand"
)
func main() {
log := logrus.New()
log.Formatter = &logrus.TextFormatter{ForceColors: true}
log.Level = logrus.DebugLevel
chat.Global.Subscribe(chat.StdoutSubscriber{})
conf, err := server.DefaultConfig().Config(log)
if err != nil {
log.Fatalln(err)
}
srv := conf.New()
srv.CloseOnProgramEnd()
srv.Listen()
for srv.Accept(accept) {
}
}
// Define a custom entity type for Enderman.
type entityTypeEnderman struct{}
// EncodeEntity ...
func (entityTypeEnderman) EncodeEntity() string {
return "minecraft:enderman"
}
// BBox ...
func (entityTypeEnderman) BBox(world.Entity) cube.BBox {
return cube.Box(-0.3, 0, -0.3, 0.3, 2.9, 0.3)
}
func init() {
spawner.RegisterEntityType(entityTypeEnderman{}, func(pos cube.Pos, w *world.World) world.Entity {
enderman := living.NewLivingEntity(entityTypeEnderman{}, 40, 0.3, []item.Stack{item.NewStack(item.EnderPearl{}, rand.Intn(2)+1)}, &entity.MovementComputer{
Gravity: 0.08,
Drag: 0.02,
DragBeforeGravity: true,
}, pos.Vec3(), w)
return enderman
})
}
func accept(p *player.Player) {
p.Inventory().AddItem(item.NewStack(spawner.SpawnEgg{Kind: entityTypeEnderman{}}, 1))
p.Inventory().AddItem(item.NewStack(spawner.Spawner{}, 1))
p.Inventory().AddItem(item.NewStack(item.Pickaxe{Tier: item.ToolTierGold}, 1))
p.SetGameMode(world.GameModeSurvival)
}