Skip to content

Commit

Permalink
Begin rewrite of player module
Browse files Browse the repository at this point in the history
  • Loading branch information
oq-x committed Jan 2, 2025
1 parent a29bd9c commit f9fe92a
Show file tree
Hide file tree
Showing 73 changed files with 2,801 additions and 5,941 deletions.
20 changes: 10 additions & 10 deletions commands/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"github.com/zeppelinmc/zeppelin/protocol/text"
"github.com/zeppelinmc/zeppelin/server"
"github.com/zeppelinmc/zeppelin/server/command"
"github.com/zeppelinmc/zeppelin/server/session"
"github.com/zeppelinmc/zeppelin/server/player/state"

//"github.com/zeppelinmc/zeppelin/server/session"
"github.com/zeppelinmc/zeppelin/util"
)

Expand All @@ -15,7 +17,7 @@ var debug = command.Command{
Aliases: []string{"f3"},
Namespace: "zeppelin",
Callback: func(ccc command.CommandCallContext) {
s, ok := ccc.Executor.(session.Session)
s, ok := ccc.Executor.(interface{ Player() *state.PlayerEntity })
if !ok {
ccc.Executor.SystemMessage(text.TextComponent{
Text: "This command should be used by a player.",
Expand Down Expand Up @@ -50,23 +52,21 @@ var debug = command.Command{
}
onBlock, _ := c.Block(xb&0x0f, yb-1, zb&0x0f)
sky, _ := c.SkyLightLevel(xb&0x0f, yb, zb&0x0f)
block, _ := c.BlockLightLevel(xb&0x0f, yb, zb&0x0f)

name, props := onBlock.Encode()

ccc.Executor.SystemMessage(text.Unmarshalf(
ccc.Executor.Config().ChatFormatter.Rune(),
"XYZ: %.03f / %.05f / %.03f\nBlock: %d %d %d [%d %d %d]\nChunk: %d %d %d [%d %d in r.%d.%d.mca]\nStanding on: %s [%v]\nFacing: (%.01f / %.01f)\nClient Light: %d (%d sky, %d block)\n\nYou are using: %s",
'&', //ccc.Executor.Config().ChatFormatter.Rune(),
"XYZ: %.03f / %.05f / %.03f\nBlock: %d %d %d [%d %d %d]\nChunk: %d %d %d [%d %d in r.%d.%d.mca]\nStanding on: %s [%v]\nFacing: (%.01f / %.01f)\nClient Light: %d (%d sky, 0 block)\n\nYou are using: %s",
x, y, z,
xb, yb, zb,
xb&0xf, yb&0xf, zb&0xf,
chunkX, chunkY, chunkZ,
chunkX&31, chunkZ&31,
rx, rz,
name, props,
onBlock.Name, onBlock.Properties,
util.NormalizeYaw(yaw), pitch,
sky+block, sky, block,
s.ClientName(),
sky, sky,
"idk",
//s.ClientName(),
))
},
}
11 changes: 4 additions & 7 deletions commands/tick.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package commands

import (
"fmt"
"time"

"github.com/zeppelinmc/zeppelin/protocol/text"
Expand All @@ -19,12 +18,10 @@ var tick = command.Command{
switch command {
case "info":
freq := tickManager.Frequency()
ccc.Executor.SystemMessage(text.TextComponent{
Text: fmt.Sprintf(
"Server Tickers: %d\nTicking Frequency: %.02ftps (expected ticks per second)",
num, 1/(float64(freq)/float64(time.Second)),
),
})
ccc.Executor.SystemMessage(text.Sprintf(
"Server Tickers: %d\nTicking Frequency: %.02ftps (expected ticks per second)",
num, 1/(float64(freq)/float64(time.Second)),
))
case "freeze":
tickManager.Freeze()
ccc.Executor.SystemMessage(text.Sprintf("Froze %d tickers", num))
Expand Down
8 changes: 2 additions & 6 deletions commands/time.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package commands

import (
"strconv"

"github.com/zeppelinmc/zeppelin/protocol/text"
"github.com/zeppelinmc/zeppelin/server"
"github.com/zeppelinmc/zeppelin/server/command"
)

var timecmd = command.Command{
Node: command.NewLiteral("time" /*command.NewCommand("add", command.NewTimeArgument("time", 0)), command.NewCommand("set", command.NewTimeArgument("time", 0))*/),
Callback: func(ccc command.CommandCallContext) {
command := ccc.Arguments.At(0)
/*command := ccc.Arguments.At(0)
w := ccc.Server.(*server.Server).World
switch command {
Expand All @@ -25,6 +21,6 @@ var timecmd = command.Command{
a, _ := w.Time()
ccc.Executor.UpdateTime(a, int64(time))
}
}*/
},
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ require (

require github.com/oq-x/unsafe2 v0.0.0-20240901191313-2b7bec1d9e3b

require github.com/grailbio/base v0.0.11 // indirect
require (
github.com/aimjel/mine-net v0.0.0-20241231185445-f0751c927ecb // indirect
github.com/grailbio/base v0.0.11 // indirect
)

require (
github.com/4kills/go-zlib v1.2.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/StackExchange/wmi v0.0.0-20170410192909-ea383cf3ba6e/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/aimjel/mine-net v0.0.0-20241231184943-192b6fd6bfdc h1:Fl6/rTVRsK3yRvLIe59RgElHb/fpVVo8fOm1SYvAfS8=
github.com/aimjel/mine-net v0.0.0-20241231184943-192b6fd6bfdc/go.mod h1:2p/uMjMBAOvMK8NvNnTsXS7s00IYvbS3Ji3YM2ApzxA=
github.com/aimjel/mine-net v0.0.0-20241231185445-f0751c927ecb h1:DzjkzmO1C8qXdEUSWU0I4hHEi0tuaFNrKeLeRZ8ntZo=
github.com/aimjel/mine-net v0.0.0-20241231185445-f0751c927ecb/go.mod h1:2p/uMjMBAOvMK8NvNnTsXS7s00IYvbS3Ji3YM2ApzxA=
github.com/aimjel/minecraft v0.0.0-20240907220502-e1fe5798908b h1:P5dA2C10r7BqzbhXqjjx07+LBV1tcsioFJrogWBOOBY=
github.com/aimjel/minecraft v0.0.0-20240907220502-e1fe5798908b/go.mod h1:jb47g4nDw3J8JdA4WxQpDx25NoIZiyNCjFOtM1b3Urk=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
Expand Down
61 changes: 7 additions & 54 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package main

import (
_ "embed"
"fmt"
properties2 "github.com/zeppelinmc/zeppelin/properties"
"math/rand"
"net/http"
"os"
"runtime"
"runtime/debug"
Expand All @@ -14,11 +13,9 @@ import (
"time"

"github.com/zeppelinmc/zeppelin/commands"
"github.com/zeppelinmc/zeppelin/protocol/properties"
"github.com/zeppelinmc/zeppelin/server"
"github.com/zeppelinmc/zeppelin/server/command"
"github.com/zeppelinmc/zeppelin/server/world"
"github.com/zeppelinmc/zeppelin/server/world/chunk/section"
"github.com/zeppelinmc/zeppelin/util"
"github.com/zeppelinmc/zeppelin/util/console"
"github.com/zeppelinmc/zeppelin/util/log"
Expand All @@ -29,9 +26,6 @@ var timeStart = time.Now()

func main() {
log.Infolnf("Zeppelin 1.21 Minecraft server with %s on platform %s-%s", runtime.Version(), runtime.GOOS, runtime.GOARCH)
if !loadStates() {
return
}

max, ok := console.GetFlag("xmem")
if ok {
Expand Down Expand Up @@ -100,63 +94,22 @@ func main() {
srv.Start(timeStart)
}

func loadConfig() properties.ServerProperties {
func loadConfig() properties2.ServerProperties {
file, err := os.ReadFile("server.properties")
if err != nil {
file, err := os.Create("server.properties")
if err == nil {
properties.Marshal(file, properties.Default)
properties2.Marshal(file, properties2.Default)
file.Close()
}
return properties.Default
return properties2.Default
}
var cfg properties.ServerProperties
var cfg properties2.ServerProperties

err = properties.Unmarshal(string(file), &cfg)
err = properties2.Unmarshal(string(file), &cfg)
if err != nil {
cfg = properties.Default
cfg = properties2.Default
}

return cfg
}

func loadStates() (ok bool) {
os.Mkdir("resources", 0755)
f, err := os.OpenFile("./resources/blocks", os.O_CREATE|os.O_RDWR, 0755)
if err != nil {
log.ErrorlnClean("Error opening block states file: ", err)
return false
}

if err := section.ImportStates(f); err == nil {
return true
}

log.Info("Downloading block states file")

res, err := http.Get(statesfilei)
if err != nil {
fmt.Println("... error")
log.ErrorlnClean("Error downloading block states file: ", err)
return false
}
if _, err := f.ReadFrom(res.Body); err != nil {
fmt.Println("... error")
log.ErrorlnClean("Error downloading block states file: ", err)
return false
}

f.Seek(0, 0)

fmt.Println("... done")

if err := section.ImportStates(f); err != nil {
log.ErrorlnClean("An error occured while loading block states file: ", err)

return false
}

return true
}

var statesfilei = "https://github.com/ZeppelinMC/resources/raw/main/blocks"
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type ServerProperties struct {

EnforceSecureProfile bool `properties:"enforce-secure-profile"`
EnforceWhitelist bool `properties:"enforce-whitelist"`
EntityBroadcastRangePrecentage int `properties:"entity-broadcast-range-precentage"`
EntityBroadcastRangePrecentage int `properties:"state-broadcast-range-precentage"`
ForceGamemode bool `properties:"force-gamemode"`
FunctionPermissionLevel int `properties:"function-permission-level"`
Gamemode string `properties:"gamemode"`
Expand Down Expand Up @@ -66,9 +66,7 @@ type ServerProperties struct {

SimulationDistance int `properties:"simulation-distance"`

SpawnAnimals bool `properties:"spawn-animals"`
SpawnMonsters bool `properties:"spawn-monsters"`
SpawnNPCs bool `properties:"spawn-npcs"`
SpawnProtection int `properties:"spawn-protection"`

ViewDistance int32 `properties:"view-distance"`
Expand Down Expand Up @@ -102,9 +100,7 @@ var Default = ServerProperties{
RegionFileCompression: "deflate",
ServerPort: 25565,
SimulationDistance: 10,
SpawnAnimals: true,
SpawnMonsters: true,
SpawnNPCs: true,
SpawnProtection: 16,
ViewDistance: 10,
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![zeppelinbanner (1)](https://github.com/user-attachments/assets/21605ec4-1253-460e-84c3-d984df14f212)
# Zeppelin

Highly optimized server implementation written in [Go](https://go.dev) for Minecraft 1.21.1
Highly optimized server implementation written in [Go](https://go.dev) for Minecraft 1.21.3

[Discord Server](https://discord.gg/T8qEtDWPak)

Expand Down
3 changes: 1 addition & 2 deletions server/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package command

import (
"github.com/zeppelinmc/zeppelin/protocol/text"
"github.com/zeppelinmc/zeppelin/server/session"
)

type Command struct {
Expand Down Expand Up @@ -33,8 +32,8 @@ func (a Arguments) Fallback(i int, fb string) string {

type CommandCallContext struct {
Command Command
Executor session.DummySession
Server any
Executor Caller

Arguments Arguments
}
Expand Down
7 changes: 5 additions & 2 deletions server/command/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/zeppelinmc/zeppelin/protocol/net/packet/play"
"github.com/zeppelinmc/zeppelin/protocol/text"
"github.com/zeppelinmc/zeppelin/server/session"
)

type Manager struct {
Expand All @@ -17,6 +16,10 @@ type Manager struct {
graph *play.Commands
}

type Caller interface {
SystemMessage(text.TextComponent) error
}

func NewManager(srv any, cmds ...Command) *Manager {
return &Manager{commands: cmds, srv: srv}
}
Expand All @@ -28,7 +31,7 @@ func (mgr *Manager) Register(cmds ...Command) {
mgr.graph = nil
}

func (mgr *Manager) Call(command string, caller session.DummySession) {
func (mgr *Manager) Call(command string, caller Caller) {
arguments := strings.Split(command, " ")
if len(arguments) == 0 {
caller.SystemMessage(
Expand Down
Loading

0 comments on commit f9fe92a

Please sign in to comment.