make void black, add preloading resource packs

This commit is contained in:
olebeck 2022-08-15 23:36:06 +02:00
parent c5abf07dad
commit 841ce5ace8
3 changed files with 32 additions and 12 deletions

View File

@ -22,19 +22,21 @@ func Chunk2Img(c *chunk.Chunk) *image.RGBA {
col := color.RGBA{0, 0, 0, 255}
block_rid := c.Block(x, height, z, 0)
b, found := world.BlockByRuntimeID(block_rid)
if found {
col = b.Color()
}
/*
if col.R == 255 && col.B == 255 {
name, nbt := b.EncodeBlock()
fmt.Printf("unknown color %s %s %s\n", reflect.TypeOf(b), name, nbt)
b.Color()
if block_rid == 0 && height == 0 { // void
col = color.RGBA{0, 0, 0, 255}
} else {
b, found := world.BlockByRuntimeID(block_rid)
if found {
col = b.Color()
}
*/
/*
if col.R == 255 && col.B == 255 {
name, nbt := b.EncodeBlock()
fmt.Printf("unknown color %d %s %s %s\n", block_rid, reflect.TypeOf(b), name, nbt)
b.Color()
}
*/
}
if height_liquid > height {
bw := &block.Water{}
wcol := bw.Color()

View File

@ -26,6 +26,7 @@ const TOKEN_FILE = "token.json"
var G_src oauth2.TokenSource
var G_xbl_token *auth.XBLToken
var G_debug bool
var G_preload_packs bool
var G_exit []func() = []func(){}
var pool = packet.NewPool()
@ -104,10 +105,13 @@ func main() {
ctx, cancel := context.WithCancel(context.Background())
flag.BoolVar(&G_debug, "debug", false, "debug mode")
flag.BoolVar(&G_preload_packs, "preload", false, "preload resourcepacks for proxy")
enable_dns := flag.Bool("dns", false, "enable dns server for consoles")
subcommands.Register(subcommands.HelpCommand(), "")
subcommands.ImportantFlag("debug")
subcommands.ImportantFlag("dns")
subcommands.ImportantFlag("preload")
subcommands.HelpCommand()
{ // interactive input

View File

@ -16,6 +16,7 @@ import (
"github.com/sandertv/gophertunnel/minecraft/auth"
"github.com/sandertv/gophertunnel/minecraft/protocol/login"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
"github.com/sandertv/gophertunnel/minecraft/resource"
"golang.org/x/oauth2"
)
@ -152,9 +153,22 @@ func spawn_conn(ctx context.Context, clientConn *minecraft.Conn, serverConn *min
}
func create_proxy(ctx context.Context, server_address string) (l *minecraft.Listener, clientConn, serverConn *minecraft.Conn, err error) {
var packs []*resource.Pack
if G_preload_packs {
fmt.Println("Preloading resourcepacks")
serverConn, err = connect_server(ctx, server_address, nil)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to connect to %s: %s", server_address, err)
}
serverConn.Close()
packs = serverConn.ResourcePacks()
fmt.Printf("%d packs loaded\n", len(packs))
}
_status := minecraft.NewStatusProvider("Server")
listener, err := minecraft.ListenConfig{
StatusProvider: _status,
ResourcePacks: packs,
}.Listen("raknet", ":19132")
if err != nil {
return nil, nil, nil, err