fix bugs with worlds on vanilla server
This commit is contained in:
parent
1b1bddc17f
commit
6376195732
|
@ -28,3 +28,4 @@ keys.db
|
|||
|
||||
packets.log.gpg
|
||||
customdata.json
|
||||
/logs-to-map/
|
9
go.mod
9
go.mod
|
@ -6,7 +6,7 @@ go 1.20
|
|||
replace github.com/sandertv/gophertunnel => github.com/olebeck/gophertunnel v1.28.1-1
|
||||
|
||||
//replace github.com/df-mc/dragonfly => ./dragonfly
|
||||
replace github.com/df-mc/dragonfly => github.com/olebeck/dragonfly v0.9.3-8
|
||||
replace github.com/df-mc/dragonfly => github.com/olebeck/dragonfly v0.9.3-9
|
||||
|
||||
replace gioui.org => github.com/olebeck/gio v0.0.0-20230321105529-d424f1a59af9
|
||||
|
||||
|
@ -27,6 +27,7 @@ require (
|
|||
github.com/sanbornm/go-selfupdate v0.0.0-20210106163404-c9b625feac49
|
||||
github.com/sandertv/go-raknet v1.12.0
|
||||
github.com/sandertv/gophertunnel v1.28.1
|
||||
github.com/shirou/gopsutil/v3 v3.23.2
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
golang.design/x/lockfree v0.0.1
|
||||
golang.org/x/crypto v0.7.0
|
||||
|
@ -46,15 +47,21 @@ require (
|
|||
github.com/changkun/lockfree v0.0.1 // indirect
|
||||
github.com/cloudfoundry/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21 // indirect
|
||||
github.com/df-mc/atomic v1.10.0 // indirect
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/go-text/typesetting v0.0.0-20221214153724-0399769901d5 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
|
||||
github.com/klauspost/compress v1.15.15 // indirect
|
||||
github.com/kr/binarydist v0.1.0 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
github.com/muhammadmuzzammil1998/jsonc v1.0.0 // indirect
|
||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.11 // indirect
|
||||
github.com/tklauser/numcpus v0.6.0 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 // indirect
|
||||
golang.org/x/image v0.6.0 // indirect
|
||||
|
|
26
go.sum
26
go.sum
|
@ -42,6 +42,8 @@ github.com/flytam/filenamify v1.1.2/go.mod h1:Dzf9kVycwcsBlr2ATg6uxjqiFgKGH+5SKF
|
|||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/go-gl/mathgl v1.0.0 h1:t9DznWJlXxxjeeKLIdovCOVJQk/GzDEL7h/h+Ro2B68=
|
||||
github.com/go-gl/mathgl v1.0.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ=
|
||||
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-text/typesetting v0.0.0-20221214153724-0399769901d5 h1:iOA0HmtpANn48hX2nlDNMu0VVaNza35HJG0WeetBVzQ=
|
||||
github.com/go-text/typesetting v0.0.0-20221214153724-0399769901d5/go.mod h1:/cmOXaoTiO+lbCwkTZBgCvevJpbFsZ5reXIpEJVh5MI=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
|
@ -53,7 +55,9 @@ github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
|
|||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
|
||||
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
|
@ -69,6 +73,8 @@ github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7y
|
|||
github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4=
|
||||
github.com/kr/binarydist v0.1.0 h1:6kAoLA9FMMnNGSehX0s1PdjbEaACznAv/W219j2uvyo=
|
||||
github.com/kr/binarydist v0.1.0/go.mod h1:DY7S//GCoz1BCd0B0EVrinCKAZN3pXe+MDaIZbXQVgM=
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
|
@ -88,6 +94,8 @@ github.com/olebeck/dragonfly v0.9.3-7 h1:zIMWsox18efEe7R+VmJOTJRePU9x2YN3CE1uzfs
|
|||
github.com/olebeck/dragonfly v0.9.3-7/go.mod h1:nnnmYWgSTNQb9x33nBthqN/2vyHlUaijfo+e2y3W5j4=
|
||||
github.com/olebeck/dragonfly v0.9.3-8 h1:w514gGVTK2iv3TDI8EuzSCDHrF2Hv2f+/lIicW0J6Bg=
|
||||
github.com/olebeck/dragonfly v0.9.3-8/go.mod h1:nnnmYWgSTNQb9x33nBthqN/2vyHlUaijfo+e2y3W5j4=
|
||||
github.com/olebeck/dragonfly v0.9.3-9 h1:S386vtOMbS82cuJnTvYsbGYhaQksEMyfkd8JPRtx9Qk=
|
||||
github.com/olebeck/dragonfly v0.9.3-9/go.mod h1:nnnmYWgSTNQb9x33nBthqN/2vyHlUaijfo+e2y3W5j4=
|
||||
github.com/olebeck/gio v0.0.0-20230321105529-d424f1a59af9 h1:TqDsMHwjW5ZYfh+RE8ussT62m0qXqo+QjzSXb7BCVA4=
|
||||
github.com/olebeck/gio v0.0.0-20230321105529-d424f1a59af9/go.mod h1:+W1Kpf96YcfissZocFqIp6O42FDTuphkObbEybp+Ffc=
|
||||
github.com/olebeck/gophertunnel v1.27.4-3 h1:RktAdTNTvCFn6PQou0H3RyqrTo3/xH0bqODrHb/oXAs=
|
||||
|
@ -103,17 +111,33 @@ github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
|
|||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
|
||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
||||
github.com/sanbornm/go-selfupdate v0.0.0-20210106163404-c9b625feac49 h1:LuxslTBxJrrNeKfqoywIERWWhH43TgiVAiPEVlhgNBA=
|
||||
github.com/sanbornm/go-selfupdate v0.0.0-20210106163404-c9b625feac49/go.mod h1:fY313ZGG810aWruFYcyq3coFpHDrWJVoMfSRI81y1r4=
|
||||
github.com/sandertv/go-raknet v1.12.0 h1:olUzZlIJyX/pgj/mrsLCZYjKLNDsYiWdvQ4NIm3z0DA=
|
||||
github.com/sandertv/go-raknet v1.12.0/go.mod h1:Gx+WgZBMQ0V2UoouGoJ8Wj6CDrMBQ4SB2F/ggpl5/+Y=
|
||||
github.com/shirou/gopsutil/v3 v3.23.2 h1:PAWSuiAszn7IhPMBtXsbSCafej7PqUOvY6YywlQUExU=
|
||||
github.com/shirou/gopsutil/v3 v3.23.2/go.mod h1:gv0aQw33GLo3pG8SiWKiQrbDzbRY1K80RyZJ7V4Th1M=
|
||||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM=
|
||||
github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI=
|
||||
github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms=
|
||||
github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
|
||||
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
|
||||
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||
golang.design/x/lockfree v0.0.1 h1:IHFNwZgM5bnZYWkEbzn5lWHMYr8WsRBdCJ/RBVY0xMM=
|
||||
|
@ -154,7 +178,9 @@ golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
|||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
|
Binary file not shown.
|
@ -24,17 +24,23 @@ func (w *WorldState) processChangeDimension(pk *packet.ChangeDimension) {
|
|||
}
|
||||
|
||||
func (w *WorldState) processLevelChunk(pk *packet.LevelChunk) {
|
||||
_, exists := w.chunks[pk.Position]
|
||||
if exists {
|
||||
return
|
||||
}
|
||||
|
||||
// ignore empty chunks THANKS WEIRD SERVER SOFTWARE DEVS
|
||||
if len(pk.RawPayload) == 0 {
|
||||
logrus.Info(locale.Loc("empty_chunk", nil))
|
||||
return
|
||||
}
|
||||
ch, blockNBTs, err := chunk.NetworkDecode(world.AirRID(), pk.RawPayload, int(pk.SubChunkCount), w.Dim.Range(), w.ispre118, w.bp.HasBlocks())
|
||||
|
||||
var subChunkCount int
|
||||
switch pk.SubChunkCount {
|
||||
case protocol.SubChunkRequestModeLimited:
|
||||
fallthrough
|
||||
case protocol.SubChunkRequestModeLimitless:
|
||||
subChunkCount = 0
|
||||
default:
|
||||
subChunkCount = int(pk.SubChunkCount)
|
||||
}
|
||||
|
||||
ch, blockNBTs, err := chunk.NetworkDecode(world.AirRID(), pk.RawPayload, subChunkCount, w.Dim.Range(), w.ispre118, w.bp.HasBlocks())
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return
|
||||
|
@ -52,6 +58,12 @@ func (w *WorldState) processLevelChunk(pk *packet.LevelChunk) {
|
|||
max = int(pk.HighestSubChunk)
|
||||
fallthrough
|
||||
case protocol.SubChunkRequestModeLimitless:
|
||||
var offsetTable []protocol.SubChunkOffset
|
||||
r := w.Dim.Range()
|
||||
for y := int8(r.Min() / 16); y < int8(r.Max()); y++ {
|
||||
offsetTable = append(offsetTable, protocol.SubChunkOffset{0, y, 0})
|
||||
}
|
||||
|
||||
w.proxy.Server.WritePacket(&packet.SubChunkRequest{
|
||||
Dimension: int32(w.Dim.EncodeDimension()),
|
||||
Position: protocol.SubChunkPos{
|
||||
|
@ -69,7 +81,7 @@ func (w *WorldState) processLevelChunk(pk *packet.LevelChunk) {
|
|||
}
|
||||
}
|
||||
if !empty {
|
||||
w.mapUI.SetChunk(pk.Position, ch)
|
||||
w.mapUI.SetChunk(pk.Position, ch, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -103,11 +115,15 @@ func (w *WorldState) processSubChunk(pk *packet.SubChunk) {
|
|||
|
||||
// redraw the chunks
|
||||
for pos := range posToRedraw {
|
||||
w.mapUI.SetChunk(pos, w.chunks[pos])
|
||||
w.mapUI.SetChunk(pos, w.chunks[pos], true)
|
||||
}
|
||||
w.mapUI.SchedRedraw()
|
||||
}
|
||||
|
||||
func blockPosInChunk(pos protocol.BlockPos) (uint8, int16, uint8) {
|
||||
return uint8(pos.X() & 0x0f), int16(pos.Y() & 0x0f), uint8(pos.Z() & 0x0f)
|
||||
}
|
||||
|
||||
func (w *WorldState) ProcessChunkPackets(pk packet.Packet) packet.Packet {
|
||||
switch pk := pk.(type) {
|
||||
case *packet.ChangeDimension:
|
||||
|
@ -118,6 +134,44 @@ func (w *WorldState) ProcessChunkPackets(pk packet.Packet) packet.Packet {
|
|||
w.proxy.SendPopup(locale.Locm("popup_chunk_count", locale.Strmap{"Count": len(w.chunks), "Name": w.WorldName}, len(w.chunks)))
|
||||
case *packet.SubChunk:
|
||||
w.processSubChunk(pk)
|
||||
case *packet.BlockActorData:
|
||||
sp := protocol.SubChunkPos{pk.Position.X() << 4, 0, pk.Position.Z() << 4}
|
||||
b, ok := w.blockNBT[sp]
|
||||
if !ok {
|
||||
w.blockNBT[sp] = []map[string]any{pk.NBTData}
|
||||
} else {
|
||||
for i, v := range b {
|
||||
x, y, z := v["x"].(int32), v["y"].(int32), v["z"].(int32)
|
||||
if x == pk.Position.X() && y == pk.Position.Y() && z == pk.Position.Z() {
|
||||
b[i] = pk.NBTData
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
case *packet.UpdateBlock:
|
||||
cp := protocol.ChunkPos{pk.Position.X() >> 4, pk.Position.Z() >> 4}
|
||||
c, ok := w.chunks[cp]
|
||||
if ok {
|
||||
x, y, z := blockPosInChunk(pk.Position)
|
||||
c.SetBlock(x, y, z, uint8(pk.Layer), pk.NewBlockRuntimeID)
|
||||
w.mapUI.SetChunk(cp, w.chunks[cp], true)
|
||||
}
|
||||
case *packet.UpdateSubChunkBlocks:
|
||||
cp := protocol.ChunkPos{pk.Position.X(), pk.Position.Z()}
|
||||
c, ok := w.chunks[cp]
|
||||
if ok {
|
||||
for _, bce := range pk.Blocks {
|
||||
name, _, _ := chunk.RuntimeIDToState(bce.BlockRuntimeID)
|
||||
logrus.Infof("update %v %s", bce.BlockPos, name)
|
||||
x, y, z := blockPosInChunk(bce.BlockPos)
|
||||
if bce.SyncedUpdateType == packet.EntityToBlockTransition {
|
||||
c.SetBlock(x, y, z, 0, world.AirRID())
|
||||
} else {
|
||||
c.SetBlock(x, y, z, 0, bce.BlockRuntimeID)
|
||||
}
|
||||
}
|
||||
w.mapUI.SetChunk(cp, w.chunks[cp], true)
|
||||
}
|
||||
}
|
||||
return pk
|
||||
}
|
||||
|
|
|
@ -14,9 +14,8 @@ import (
|
|||
|
||||
func isBlockLightblocking(b world.Block) bool {
|
||||
d, isDiffuser := b.(block.LightDiffuser)
|
||||
_, isSlab := b.(block.Slab)
|
||||
noDiffuse := isDiffuser && d.LightDiffusionLevel() == 0
|
||||
return noDiffuse && !isSlab
|
||||
return !noDiffuse
|
||||
}
|
||||
|
||||
func blockColorAt(c *chunk.Chunk, x uint8, y int16, z uint8) (blockColor color.RGBA) {
|
||||
|
@ -30,7 +29,7 @@ func blockColorAt(c *chunk.Chunk, x uint8, y int16, z uint8) (blockColor color.R
|
|||
} else {
|
||||
b, found := world.BlockByRuntimeID(rid)
|
||||
if found {
|
||||
if isBlockLightblocking(b) {
|
||||
if !isBlockLightblocking(b) {
|
||||
return blockColorAt(c, x, y-1, z)
|
||||
}
|
||||
_, isWater := b.(block.Water)
|
||||
|
@ -97,7 +96,7 @@ func chunkGetColorAt(c *chunk.Chunk, x uint8, y int16, z uint8) color.RGBA {
|
|||
return blockColor
|
||||
}
|
||||
|
||||
func Chunk2Img(c *chunk.Chunk) *image.RGBA {
|
||||
func Chunk2Img(c *chunk.Chunk, warn bool) *image.RGBA {
|
||||
img := image.NewRGBA(image.Rect(0, 0, 16, 16))
|
||||
hm := c.HeightMapWithWater()
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
func Test(t *testing.T) {
|
||||
data, _ := os.ReadFile("chunk.bin")
|
||||
ch, _, _ := chunk.NetworkDecode(33, data, 6, cube.Range{0, 255}, true, false)
|
||||
i := world.Chunk2Img(ch)
|
||||
i := world.Chunk2Img(ch, true)
|
||||
f, _ := os.Create("chunk.png")
|
||||
png.Encode(f, i)
|
||||
f.Close()
|
||||
|
@ -34,6 +34,6 @@ func Benchmark_render_chunk(b *testing.B) {
|
|||
ch, _, _ := chunk.NetworkDecode(33, data, 6, cube.Range{0, 255}, true, false)
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
world.Chunk2Img(ch)
|
||||
world.Chunk2Img(ch, true)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ func (w *WorldState) processAddActor(pk *packet.AddActor) {
|
|||
RuntimeID: pk.EntityRuntimeID,
|
||||
UniqueID: pk.EntityUniqueID,
|
||||
EntityType: pk.EntityType,
|
||||
Inventory: make(map[byte]map[byte]protocol.ItemInstance),
|
||||
Metadata: make(map[uint32]any),
|
||||
}
|
||||
w.entities[pk.EntityRuntimeID] = e
|
||||
|
|
|
@ -35,17 +35,28 @@ func (w *WorldState) processItemPacketsServer(pk packet.Packet) packet.Packet {
|
|||
}
|
||||
|
||||
case *packet.InventoryContent:
|
||||
// save content
|
||||
existing, ok := w.openItemContainers[byte(pk.WindowID)]
|
||||
if !ok {
|
||||
if pk.WindowID == 0x0 { // inventory
|
||||
w.openItemContainers[byte(pk.WindowID)] = &itemContainer{
|
||||
Content: pk,
|
||||
}
|
||||
if pk.WindowID == 0x0 { // inventory
|
||||
w.playerInventory = pk.Content
|
||||
} else {
|
||||
// save content
|
||||
existing, ok := w.openItemContainers[byte(pk.WindowID)]
|
||||
if ok {
|
||||
existing.Content = pk
|
||||
}
|
||||
break
|
||||
}
|
||||
existing.Content = pk
|
||||
|
||||
case *packet.InventorySlot:
|
||||
if pk.WindowID == 0x0 {
|
||||
w.playerInventory[pk.Slot] = pk.NewItem
|
||||
} else {
|
||||
// save content
|
||||
existing, ok := w.openItemContainers[byte(pk.WindowID)]
|
||||
if ok {
|
||||
existing.Content.Content[pk.Slot] = pk.NewItem
|
||||
}
|
||||
}
|
||||
|
||||
case *packet.ItemStackResponse:
|
||||
|
||||
case *packet.ContainerClose:
|
||||
// find container info
|
||||
|
@ -172,3 +183,19 @@ func stackToItem(it protocol.ItemStack) item.Stack {
|
|||
s := item.NewStack(t, int(it.Count))
|
||||
return nbtconv.ReadItem(it.NBTData, &s)
|
||||
}
|
||||
|
||||
func playerData(items []protocol.ItemInstance) (ret map[string]any) {
|
||||
ret = map[string]any{}
|
||||
|
||||
if len(items) > 0 {
|
||||
inv := inventory.New(len(items), nil)
|
||||
for i, ii := range items {
|
||||
inv.SetItem(i, stackToItem(ii.Stack))
|
||||
}
|
||||
ret["Inventory"] = nbtconv.InvToNBT(inv)
|
||||
}
|
||||
|
||||
ret["format_version"] = "1.12.0"
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -64,8 +64,9 @@ func (m *MapUI) GetBounds() (min, max protocol.ChunkPos) {
|
|||
}
|
||||
|
||||
type RenderElem struct {
|
||||
pos protocol.ChunkPos
|
||||
ch *chunk.Chunk
|
||||
pos protocol.ChunkPos
|
||||
ch *chunk.Chunk
|
||||
complete bool
|
||||
}
|
||||
|
||||
type MapUI struct {
|
||||
|
@ -188,7 +189,7 @@ func (m *MapUI) Redraw() {
|
|||
break
|
||||
}
|
||||
if r.ch != nil {
|
||||
m.renderedChunks[r.pos] = Chunk2Img(r.ch)
|
||||
m.renderedChunks[r.pos] = Chunk2Img(r.ch, !r.complete)
|
||||
} else {
|
||||
m.renderedChunks[r.pos] = black16x16
|
||||
}
|
||||
|
@ -201,7 +202,6 @@ func (m *MapUI) Redraw() {
|
|||
int32(m.w.PlayerPos.Position.Z()),
|
||||
}
|
||||
|
||||
// total_width := 32 * math.Ceil(float64(chunks_x)/32)
|
||||
chunksPerLine := float64(128 / m.zoomLevel)
|
||||
pxPerBlock := 128 / chunksPerLine / 16 // how many pixels per block
|
||||
pxSizeChunk := int(math.Floor(pxPerBlock * 16))
|
||||
|
@ -223,11 +223,10 @@ func (m *MapUI) Redraw() {
|
|||
utils.DrawImgScaledPos(m.img, m.renderedChunks[_ch], px, pxSizeChunk)
|
||||
}
|
||||
}
|
||||
ChunkCount := len(m.renderedChunks)
|
||||
if m.showOnGui {
|
||||
min, max := m.GetBounds()
|
||||
m.w.gui.Message(messages.UpdateMap, messages.UpdateMapPayload{
|
||||
ChunkCount: ChunkCount,
|
||||
ChunkCount: len(m.renderedChunks),
|
||||
Rotation: m.w.PlayerPos.Yaw,
|
||||
UpdatedTiles: updatedChunks,
|
||||
Tiles: m.renderedChunks,
|
||||
|
@ -261,8 +260,8 @@ func (m *MapUI) ToImage() *image.RGBA {
|
|||
return img2
|
||||
}
|
||||
|
||||
func (m *MapUI) SetChunk(pos protocol.ChunkPos, ch *chunk.Chunk) {
|
||||
m.renderQueue.Enqueue(&RenderElem{pos, ch})
|
||||
func (m *MapUI) SetChunk(pos protocol.ChunkPos, ch *chunk.Chunk, complete bool) {
|
||||
m.renderQueue.Enqueue(&RenderElem{pos, ch, complete})
|
||||
m.SchedRedraw()
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/df-mc/dragonfly/server/world/mcdb"
|
||||
"github.com/df-mc/goleveldb/leveldb/opt"
|
||||
"github.com/go-gl/mathgl/mgl32"
|
||||
"github.com/sandertv/gophertunnel/minecraft"
|
||||
"github.com/sandertv/gophertunnel/minecraft/protocol"
|
||||
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -52,6 +53,7 @@ type WorldState struct {
|
|||
chunks map[protocol.ChunkPos]*chunk.Chunk
|
||||
blockNBT map[protocol.SubChunkPos][]map[string]any
|
||||
openItemContainers map[byte]*itemContainer
|
||||
playerInventory []protocol.ItemInstance
|
||||
entities map[uint64]*entityState
|
||||
Dim world.Dimension
|
||||
PlayerPos TPlayerPos
|
||||
|
@ -104,14 +106,10 @@ var dimensionIDMap = map[uint8]world.Dimension{
|
|||
}
|
||||
|
||||
var (
|
||||
black16x16 = image.NewRGBA(image.Rect(0, 0, 16, 16))
|
||||
offsetTable [24]protocol.SubChunkOffset
|
||||
black16x16 = image.NewRGBA(image.Rect(0, 0, 16, 16))
|
||||
)
|
||||
|
||||
func init() {
|
||||
for i := range offsetTable {
|
||||
offsetTable[i] = protocol.SubChunkOffset{0, int8(i), 0}
|
||||
}
|
||||
for i := 3; i < len(black16x16.Pix); i += 4 {
|
||||
black16x16.Pix[i] = 255
|
||||
}
|
||||
|
@ -155,6 +153,9 @@ func (c *WorldCMD) Execute(ctx context.Context, ui utils.UI) error {
|
|||
w.experimentInventory = c.ExperimentInventory
|
||||
|
||||
proxy.AlwaysGetPacks = true
|
||||
proxy.GameDataModifier = func(gd *minecraft.GameData) {
|
||||
gd.ClientSideGeneration = false
|
||||
}
|
||||
proxy.ConnectCB = w.OnConnect
|
||||
proxy.OnClientConnect = func(hasClient bool) {
|
||||
w.gui.Message(messages.SetUIState, messages.UIStateConnecting)
|
||||
|
@ -330,6 +331,11 @@ func (w *WorldState) SaveAndReset() {
|
|||
}
|
||||
}
|
||||
|
||||
err = provider.SaveLocalPlayerData(playerData(w.playerInventory))
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
|
||||
// write metadata
|
||||
s := provider.Settings()
|
||||
player := w.proxy.Server.GameData().PlayerPosition
|
||||
|
@ -480,7 +486,7 @@ func (w *WorldState) SaveAndReset() {
|
|||
if err != nil {
|
||||
logrus.Error(err)
|
||||
} else {
|
||||
var rdeps []dep
|
||||
//var rdeps []dep
|
||||
for k, p := range packs {
|
||||
if p.Encrypted() && !p.CanDecrypt() {
|
||||
logrus.Warnf("Cant add %s, it is encrypted", p.Name())
|
||||
|
@ -493,14 +499,18 @@ func (w *WorldState) SaveAndReset() {
|
|||
p.ReadAt(data, 0)
|
||||
utils.UnpackZip(bytes.NewReader(data), int64(len(data)), packFolder)
|
||||
|
||||
rdeps = append(rdeps, dep{
|
||||
PackID: p.Manifest().Header.UUID,
|
||||
Version: p.Manifest().Header.Version,
|
||||
})
|
||||
}
|
||||
if len(rdeps) > 0 {
|
||||
//addPacksJSON("world_resource_packs.json", rdeps)
|
||||
/*
|
||||
rdeps = append(rdeps, dep{
|
||||
PackID: p.Manifest().Header.UUID,
|
||||
Version: p.Manifest().Header.Version,
|
||||
})
|
||||
*/
|
||||
}
|
||||
/*
|
||||
if len(rdeps) > 0 {
|
||||
addPacksJSON("world_resource_packs.json", rdeps)
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
|
||||
var DisconnectReason = "Connection lost"
|
||||
|
||||
/*
|
||||
type dummyProto struct {
|
||||
id int32
|
||||
ver string
|
||||
|
@ -38,6 +39,7 @@ func (p dummyProto) ConvertToLatest(pk packet.Packet, _ *minecraft.Conn) []packe
|
|||
func (p dummyProto) ConvertFromLatest(pk packet.Packet, _ *minecraft.Conn) []packet.Packet {
|
||||
return []packet.Packet{pk}
|
||||
}
|
||||
*/
|
||||
|
||||
type (
|
||||
PacketFunc func(header packet.Header, payload []byte, src, dst net.Addr)
|
||||
|
@ -68,6 +70,8 @@ type ProxyContext struct {
|
|||
ConnectCB ConnectCallback
|
||||
// called on every packet after login
|
||||
PacketCB PacketCallback
|
||||
// called to change game data
|
||||
GameDataModifier func(*minecraft.GameData)
|
||||
}
|
||||
|
||||
func NewProxy() (*ProxyContext, error) {
|
||||
|
@ -318,8 +322,13 @@ func (p *ProxyContext) Run(ctx context.Context, serverAddress string) (err error
|
|||
}
|
||||
defer p.Server.Close()
|
||||
|
||||
gd := p.Server.GameData()
|
||||
if p.GameDataModifier != nil {
|
||||
p.GameDataModifier(&gd)
|
||||
}
|
||||
|
||||
// spawn and start the game
|
||||
if err = spawnConn(ctx, p.Client, p.Server); err != nil {
|
||||
if err = spawnConn(ctx, p.Client, p.Server, gd); err != nil {
|
||||
err = fmt.Errorf(locale.Loc("failed_to_spawn", locale.Strmap{"Err": err}))
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import (
|
|||
"runtime"
|
||||
|
||||
"github.com/sanbornm/go-selfupdate/selfupdate"
|
||||
"github.com/shirou/gopsutil/v3/cpu"
|
||||
"github.com/shirou/gopsutil/v3/mem"
|
||||
)
|
||||
|
||||
var Version string
|
||||
|
@ -26,7 +28,13 @@ func (httpRequester *trequester) Fetch(url string) (io.ReadCloser, error) {
|
|||
}
|
||||
// set user agent to know what versions are run
|
||||
h, _ := os.Hostname()
|
||||
req.Header.Add("User-Agent", fmt.Sprintf("%s %s '%s' %d", CmdName, Version, h, runtime.NumCPU()))
|
||||
v, _ := mem.VirtualMemory()
|
||||
c, _ := cpu.Info()
|
||||
var ct string
|
||||
if len(c) > 0 {
|
||||
ct = c[0].ModelName
|
||||
}
|
||||
req.Header.Add("User-Agent", fmt.Sprintf("%s '%s' '%s' %d %d '%s'", CmdName, Version, h, runtime.NumCPU(), v.Total, ct))
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
|
|
|
@ -88,14 +88,14 @@ func connectServer(ctx context.Context, address string, ClientData *login.Client
|
|||
return serverConn, nil
|
||||
}
|
||||
|
||||
func spawnConn(ctx context.Context, clientConn *minecraft.Conn, serverConn *minecraft.Conn) error {
|
||||
func spawnConn(ctx context.Context, clientConn *minecraft.Conn, serverConn *minecraft.Conn, gd minecraft.GameData) error {
|
||||
wg := sync.WaitGroup{}
|
||||
errs := make(chan error, 2)
|
||||
if clientConn != nil {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
errs <- clientConn.StartGame(serverConn.GameData())
|
||||
errs <- clientConn.StartGame(gd)
|
||||
}()
|
||||
}
|
||||
wg.Add(1)
|
||||
|
|
Loading…
Reference in New Issue