diff --git a/main.go b/main.go index 11506bb..428c76b 100644 --- a/main.go +++ b/main.go @@ -64,6 +64,13 @@ var cfg config.Config var prof bool func main() { + if util.HasArg("-gencfg") { + log.Info("Generating config file") + f, _ := os.OpenFile("config.toml", os.O_RDWR|os.O_CREATE, 0666) + toml.NewEncoder(f).Encode(config.DefaultConfig) + f.Close() + return + } server.OldState, _ = term.MakeRaw(int(os.Stdin.Fd())) log.Info("Starting Dynamite 1.20.1 server") diff --git a/server/block/acacia_log.go b/server/block/acacia_log.go new file mode 100644 index 0000000..0884b23 --- /dev/null +++ b/server/block/acacia_log.go @@ -0,0 +1,34 @@ +package block + +import "github.com/dynamitemc/dynamite/server/world/chunk" + +type AcaciaLog struct { + Stripped bool + Axis Axis +} + +func (d AcaciaLog) EncodedName() string { + if d.Stripped { + return "minecraft:stripped_acacia_log" + } + return "minecraft:acacia_log" +} + +func (g AcaciaLog) Properties() map[string]string { + return map[string]string{ + "axis": g.Axis, + } +} + +func (AcaciaLog) New(n string, p map[string]string) chunk.Block { + return AcaciaLog{ + Stripped: n == "minecraft:stripped_acacia_log", + Axis: p["axis"], + } +} + +func (AcaciaLog) BreakInfo() BreakInfo { + return BreakInfo{ + Hardness: 2, + } +} diff --git a/server/block/air.go b/server/block/air.go index 8828c0d..15dee7a 100644 --- a/server/block/air.go +++ b/server/block/air.go @@ -12,6 +12,6 @@ func (Air) Properties() map[string]string { return nil } -func (a Air) New(map[string]string) chunk.Block { +func (a Air) New(string, map[string]string) chunk.Block { return a } diff --git a/server/block/bedrock.go b/server/block/bedrock.go index 2cf005c..7c94bda 100644 --- a/server/block/bedrock.go +++ b/server/block/bedrock.go @@ -18,6 +18,6 @@ func (g Bedrock) Properties() map[string]string { return nil } -func (d Bedrock) New(p map[string]string) chunk.Block { +func (d Bedrock) New(string, map[string]string) chunk.Block { return d } diff --git a/server/block/birch_log.go b/server/block/birch_log.go new file mode 100644 index 0000000..0f04cc9 --- /dev/null +++ b/server/block/birch_log.go @@ -0,0 +1,34 @@ +package block + +import "github.com/dynamitemc/dynamite/server/world/chunk" + +type BirchLog struct { + Stripped bool + Axis Axis +} + +func (d BirchLog) EncodedName() string { + if d.Stripped { + return "minecraft:stripped_birch_log" + } + return "minecraft:birch_log" +} + +func (g BirchLog) Properties() map[string]string { + return map[string]string{ + "axis": g.Axis, + } +} + +func (BirchLog) New(n string, p map[string]string) chunk.Block { + return BirchLog{ + Stripped: n == "minecraft:stripped_birch_log", + Axis: p["axis"], + } +} + +func (BirchLog) BreakInfo() BreakInfo { + return BreakInfo{ + Hardness: 2, + } +} diff --git a/server/block/block.go b/server/block/block.go index e6a94f5..6e7ae2b 100644 --- a/server/block/block.go +++ b/server/block/block.go @@ -13,9 +13,27 @@ func init() { chunk.RegisterBlock(GrassBlock{}) chunk.RegisterBlock(Snow{}) chunk.RegisterBlock(Bedrock{}) + chunk.RegisterBlock(AcaciaLog{}) + chunk.RegisterBlock(AcaciaLog{Stripped: true}) + + chunk.RegisterBlock(BirchLog{}) + chunk.RegisterBlock(BirchLog{Stripped: true}) + + chunk.RegisterBlock(CherryLog{}) + chunk.RegisterBlock(CherryLog{Stripped: true}) + + chunk.RegisterBlock(DarkOakLog{}) + chunk.RegisterBlock(DarkOakLog{Stripped: true}) + + chunk.RegisterBlock(OakLog{}) + chunk.RegisterBlock(OakLog{Stripped: true}) + + chunk.RegisterBlock(SpruceLog{}) + chunk.RegisterBlock(SpruceLog{Stripped: true}) } type BreakInfo struct { + Hardness float64 Unbreakable bool } diff --git a/server/block/cherry_log.go b/server/block/cherry_log.go new file mode 100644 index 0000000..4b83d9c --- /dev/null +++ b/server/block/cherry_log.go @@ -0,0 +1,34 @@ +package block + +import "github.com/dynamitemc/dynamite/server/world/chunk" + +type CherryLog struct { + Stripped bool + Axis Axis +} + +func (d CherryLog) EncodedName() string { + if d.Stripped { + return "minecraft:stripped_cherry_log" + } + return "minecraft:cherry_log" +} + +func (g CherryLog) Properties() map[string]string { + return map[string]string{ + "axis": g.Axis, + } +} + +func (CherryLog) New(n string, p map[string]string) chunk.Block { + return CherryLog{ + Stripped: n == "minecraft:stripped_cherry_log", + Axis: p["axis"], + } +} + +func (CherryLog) BreakInfo() BreakInfo { + return BreakInfo{ + Hardness: 2, + } +} diff --git a/server/block/dark_oak_log.go b/server/block/dark_oak_log.go new file mode 100644 index 0000000..5f9b79b --- /dev/null +++ b/server/block/dark_oak_log.go @@ -0,0 +1,44 @@ +package block + +import ( + "github.com/dynamitemc/dynamite/server/world/chunk" +) + +type Axis = string + +const ( + AxisX Axis = "x" + AxisY Axis = "y" + AxisZ Axis = "z" +) + +type DarkOakLog struct { + Stripped bool + Axis Axis +} + +func (d DarkOakLog) EncodedName() string { + if d.Stripped { + return "minecraft:stripped_dark_oak_log" + } + return "minecraft:dark_oak_log" +} + +func (g DarkOakLog) Properties() map[string]string { + return map[string]string{ + "axis": g.Axis, + } +} + +func (DarkOakLog) New(n string, p map[string]string) chunk.Block { + return DarkOakLog{ + Stripped: n == "minecraft:stripped_dark_oak_log", + Axis: p["axis"], + } +} + +func (DarkOakLog) BreakInfo() BreakInfo { + return BreakInfo{ + Hardness: 2, + } +} diff --git a/server/block/dirt.go b/server/block/dirt.go index 5113f17..0b20aa3 100644 --- a/server/block/dirt.go +++ b/server/block/dirt.go @@ -19,6 +19,6 @@ func (g Dirt) Properties() map[string]string { return nil } -func (d Dirt) New(p map[string]string) chunk.Block { +func (d Dirt) New(string, map[string]string) chunk.Block { return d } diff --git a/server/block/grass_block.go b/server/block/grass_block.go index e156357..907cb69 100644 --- a/server/block/grass_block.go +++ b/server/block/grass_block.go @@ -1,8 +1,6 @@ package block import ( - "fmt" - "github.com/dynamitemc/dynamite/server/block/pos" "github.com/dynamitemc/dynamite/server/world" "github.com/dynamitemc/dynamite/server/world/chunk" @@ -22,7 +20,7 @@ func (g GrassBlock) Properties() map[string]string { } } -func (GrassBlock) New(p map[string]string) chunk.Block { +func (GrassBlock) New(_ string, p map[string]string) chunk.Block { var a GrassBlock if p["snowy"] == "true" { a.Snowy = true @@ -33,7 +31,6 @@ func (GrassBlock) New(p map[string]string) chunk.Block { func (g GrassBlock) Tick(p pos.BlockPosition, d *world.Dimension, _ uint) chunk.Block { if g.Snowy { b := d.Block(p.X(), p.Y()+1, p.Z()) - fmt.Printf("%s\n\r", b.EncodedName()) if _, ok := b.(Snow); !ok { g.Snowy = false } diff --git a/server/block/oak_log.go b/server/block/oak_log.go new file mode 100644 index 0000000..9e1fa75 --- /dev/null +++ b/server/block/oak_log.go @@ -0,0 +1,34 @@ +package block + +import "github.com/dynamitemc/dynamite/server/world/chunk" + +type OakLog struct { + Stripped bool + Axis Axis +} + +func (d OakLog) EncodedName() string { + if d.Stripped { + return "minecraft:stripped_oak_log" + } + return "minecraft:oak_log" +} + +func (g OakLog) Properties() map[string]string { + return map[string]string{ + "axis": g.Axis, + } +} + +func (OakLog) New(n string, p map[string]string) chunk.Block { + return OakLog{ + Stripped: n == "minecraft:stripped_oak_log", + Axis: p["axis"], + } +} + +func (OakLog) BreakInfo() BreakInfo { + return BreakInfo{ + Hardness: 2, + } +} diff --git a/server/block/snow.go b/server/block/snow.go index 15e8a55..7e2a672 100644 --- a/server/block/snow.go +++ b/server/block/snow.go @@ -20,7 +20,7 @@ func (s Snow) Properties() map[string]string { } } -func (Snow) New(m map[string]string) chunk.Block { +func (Snow) New(_ string, m map[string]string) chunk.Block { l, _ := strconv.Atoi(m["layers"]) if l == 0 { l = 1 diff --git a/server/block/spruce_log.go b/server/block/spruce_log.go new file mode 100644 index 0000000..e382396 --- /dev/null +++ b/server/block/spruce_log.go @@ -0,0 +1,34 @@ +package block + +import "github.com/dynamitemc/dynamite/server/world/chunk" + +type SpruceLog struct { + Stripped bool + Axis Axis +} + +func (d SpruceLog) EncodedName() string { + if d.Stripped { + return "minecraft:stripped_spruce_log" + } + return "minecraft:spruce_log" +} + +func (g SpruceLog) Properties() map[string]string { + return map[string]string{ + "axis": g.Axis, + } +} + +func (SpruceLog) New(n string, p map[string]string) chunk.Block { + return SpruceLog{ + Stripped: n == "minecraft:stripped_spruce_log", + Axis: p["axis"], + } +} + +func (SpruceLog) BreakInfo() BreakInfo { + return BreakInfo{ + Hardness: 2, + } +} diff --git a/server/world/chunk/block.go b/server/world/chunk/block.go index 1b31321..39f1cae 100644 --- a/server/world/chunk/block.go +++ b/server/world/chunk/block.go @@ -3,7 +3,7 @@ package chunk type Block interface { EncodedName() string - New(map[string]string) Block + New(string, map[string]string) Block Properties() map[string]string } @@ -17,8 +17,8 @@ func (u UnknownBlock) EncodedName() string { return u.encodedName } -func (u UnknownBlock) New(m map[string]string) Block { - return UnknownBlock{encodedName: u.encodedName, properties: m} +func (u UnknownBlock) New(n string, m map[string]string) Block { + return UnknownBlock{encodedName: n, properties: m} } func (u UnknownBlock) Properties() map[string]string { diff --git a/server/world/chunk/register.go b/server/world/chunk/register.go index d7a4273..32cb5f1 100644 --- a/server/world/chunk/register.go +++ b/server/world/chunk/register.go @@ -13,11 +13,13 @@ var nbtBytes []byte type blockInfo struct { Properties map[string][]string `json:"properties"` - States []struct { - Id int `json:"id"` - Default bool `json:"default"` - Properties map[string]string - } + States []blockState +} + +type blockState struct { + Id int `json:"id"` + Default bool `json:"default"` + Properties map[string]string } var blocks map[string]blockInfo @@ -55,7 +57,17 @@ func DefaultBlock(name string) Block { return nil } block := blocks[b.EncodedName()] - return b.New(block.States[0].Properties) + d, _ := defaultState(block.States) + return b.New(name, d.Properties) +} + +func defaultState(s []blockState) (_ blockState, ok bool) { + for _, i := range s { + if i.Default { + return i, ok + } + } + return } func GetBlockId(b Block) (int, bool) { diff --git a/server/world/chunk/section.go b/server/world/chunk/section.go index c4549e5..07ebbb5 100644 --- a/server/world/chunk/section.go +++ b/server/world/chunk/section.go @@ -33,7 +33,7 @@ func newSection(data []int64, blocks []blockEntry, bLight, sLight []int8) (s *se for _, entry := range blocks { b := GetBlock(entry.Name) if entry.Properties != nil { - b = b.New(entry.Properties) + b = b.New(entry.Name, entry.Properties) } id, ok := GetBlockId(b) diff --git a/server/world/tick/tick.go b/server/world/tick/tick.go index 0406e88..3cbc33e 100644 --- a/server/world/tick/tick.go +++ b/server/world/tick/tick.go @@ -72,11 +72,11 @@ func (t *Ticker) tick(tick uint) { } func blockTick(srv *server.Server, d *world.Dimension, tick uint, rts int) { - randomTickedBlocks := 0 for h, c := range d.Chunks() { cx, cz := h.Position() for cy, s := range c.Sections { + randomTickedBlocks := 0 for x := 0; x < 15; x++ { for y := 0; y < 15; y++ { for z := 0; z < 15; z++ { @@ -91,8 +91,8 @@ func blockTick(srv *server.Server, d *world.Dimension, tick uint, rts int) { if randomTickedBlocks < rts && randBool() { if bl, ok := b.(block.RandomTicker); ok { srv.SetBlock(d, x1, y1, z1, bl.RandomTick(pos, d, tick), world.SetBlockReplace) + randomTickedBlocks++ } - randomTickedBlocks++ } } }