Skip to content

Commit

Permalink
chunk: Support block aliases properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
JustTalDevelops committed Aug 28, 2022
1 parent c465a38 commit d295bc3
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 3 deletions.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
# worldcompute
live-computation, parsing, and savings of minecraft: bedrock worlds

live-computation, parsing, and saves of minecraft: bedrock servers using gophertunnel and dragonfly.

![example of worldcompute on the hive](example.png)

## usage

download the latest release and move it to its own folder. run the executable and authenticate with xbox live.

when completed, worldcompute will save your xbox live token in the same folder under `token.tok`. unless you delete the
file, you'll be able to use worldcompute without authenticating again.

after authenticating, you can close worldcompute. you'll notice that a configuration will be generated. edit the
configuration to your liking, and then run worldcompute. the worldcompute proxy will now forward connections to the
target server specified.

worldrenderer will automatically run and render the chunks in cache in real-time.

## commands

- `reset` - reset all downloaded chunks in cache.
- `save` - save all downloaded chunks to a folder.
- `cancel` - terminate a save-in-progress.

## supported formats

- `v0` (pre-v1.2.13) (legacy, only used by PM3)
- `v1` (post-v1.2.13, only a single layer)
- `v8/v9` (post-v1.2.13, up to 256 layers) (persistent and runtime)
- `v9 (sub-chunk request system)` (post-v1.18.0, up to 256 layers) (persistent and runtime)

## credits

special thanks to [T 14Raptor](https://github.com/T14Raptor) for the original worldcompute project, and
[Sandertv](https://github.com/Sandertv) for his work on gophertunnel and dragonfly.
32 changes: 32 additions & 0 deletions dragonfly/world/aliases.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package world

import (
_ "embed"
"github.com/sandertv/gophertunnel/minecraft/nbt"
)

var (
//go:embed block_aliases.nbt
blockAliasesData []byte
// aliasMappings maps from a legacy block name alias to an updated name.
aliasMappings = make(map[string]string)
)

// upgradeAliasEntry upgrades a possible alias block entry to the correct/updated block entry.
func upgradeAliasEntry(entry blockState) (blockState, bool) {
if alias, ok := aliasMappings[entry.Name]; ok {
entry.Name = alias
return entry, true
}
if entry.Name == "minecraft:barrier" {
entry.Name = "minecraft:info_update"
}
return blockState{}, false
}

// init creates conversions for each legacy and alias entry.
func init() {
if err := nbt.Unmarshal(blockAliasesData, &aliasMappings); err != nil {
panic(err)
}
}
Binary file added dragonfly/world/block_aliases.nbt
Binary file not shown.
9 changes: 8 additions & 1 deletion dragonfly/world/block_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@ func init() {
return "", nil, false
}
state := blocks[runtimeID]
if updatedEntry, ok := upgradeAliasEntry(state); ok {
state = updatedEntry
}
return state.Name, state.Properties, true
}
chunk.StateToRuntimeID = func(name string, properties map[string]interface{}) (runtimeID uint32, found bool) {
rid, ok := stateRuntimeIDs[stateHash{name: name, properties: hashProperties(properties)}]
state := blockState{Name: name, Properties: properties}
if updatedEntry, ok := upgradeAliasEntry(state); ok {
state = updatedEntry
}
rid, ok := stateRuntimeIDs[stateHash{name: state.Name, properties: hashProperties(state.Properties)}]
return rid, ok
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/pelletier/go-toml v1.9.4
github.com/sandertv/go-raknet v1.11.1 // indirect
github.com/sandertv/gophertunnel v1.24.0
github.com/sandertv/gophertunnel v1.24.6
go.uber.org/atomic v1.9.0
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ github.com/sandertv/go-raknet v1.11.1 h1:0auvhHoZNyC/Z1l5xqniE3JE+w3MGO3n3JXEGHz
github.com/sandertv/go-raknet v1.11.1/go.mod h1:Gx+WgZBMQ0V2UoouGoJ8Wj6CDrMBQ4SB2F/ggpl5/+Y=
github.com/sandertv/gophertunnel v1.24.0 h1:TPxUJtBHeh3hRNQciAoKFcWa6FB8iyB3FqN8+sx4dh4=
github.com/sandertv/gophertunnel v1.24.0/go.mod h1:dMOw79FHxr2azEqiGH20AwdljisAN1kqwu5SjPBnZ5k=
github.com/sandertv/gophertunnel v1.24.6 h1:GIa6QyRNcyw5E9nm0S1NReEOj0GDk6bS/RHQo8lhkXI=
github.com/sandertv/gophertunnel v1.24.6/go.mod h1:dMOw79FHxr2azEqiGH20AwdljisAN1kqwu5SjPBnZ5k=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down

0 comments on commit d295bc3

Please sign in to comment.