diff --git a/cmd/bedrocktool/main.go b/cmd/bedrocktool/main.go index 82699ac..a9e4612 100644 --- a/cmd/bedrocktool/main.go +++ b/cmd/bedrocktool/main.go @@ -9,6 +9,7 @@ import ( "os/signal" "runtime/debug" "syscall" + "time" "github.com/bedrock-tool/bedrocktool/locale" "github.com/bedrock-tool/bedrocktool/utils" @@ -37,6 +38,9 @@ func (c *CLI) Start(ctx context.Context, cancel context.CancelFunc) error { utils.InitDNS() utils.InitExtraDebug(ctx) subcommands.Execute(ctx) + time.Sleep(50 * time.Millisecond) + cancel() + time.Sleep(50 * time.Millisecond) return nil } diff --git a/subcommands/resourcepack-d/resourcepack-d.go b/subcommands/resourcepack-d/resourcepack-d.go index cc08f3a..9bd0cc4 100644 Binary files a/subcommands/resourcepack-d/resourcepack-d.go and b/subcommands/resourcepack-d/resourcepack-d.go differ diff --git a/subcommands/world/entity.go b/subcommands/world/entity.go index 1f948af..ab344f4 100644 --- a/subcommands/world/entity.go +++ b/subcommands/world/entity.go @@ -126,6 +126,9 @@ func entityMetadataToNBT(metadata protocol.EntityMetadata, nbt map[string]any) { if color2, ok := metadata[protocol.EntityDataKeyColorTwoIndex]; ok { nbt["Color2"] = color2 } + if skinID, ok := metadata[protocol.EntityDataKeySkinID]; ok { + nbt["SkinID"] = int32(skinID.(int32)) + } if name, ok := metadata[protocol.EntityDataKeyName]; ok { nbt["CustomName"] = name @@ -219,9 +222,12 @@ func (w *worldsServer) ProcessEntityPackets(pk packet.Packet) packet.Packet { case *packet.SetActorData: e, ok := w.worldState.entities[pk.EntityRuntimeID] if ok { - for k, v := range pk.EntityMetadata { - e.Metadata[k] = v - } + e.Metadata = pk.EntityMetadata + w.bp.AddEntity(behaviourpack.EntityIn{ + Identifier: e.EntityType, + Attr: nil, + Meta: pk.EntityMetadata, + }) } case *packet.SetActorMotion: e, ok := w.worldState.entities[pk.EntityRuntimeID] diff --git a/subcommands/world/world.go b/subcommands/world/world.go index d4988a4..7a33e0f 100644 --- a/subcommands/world/world.go +++ b/subcommands/world/world.go @@ -286,7 +286,7 @@ func (w *worldsServer) SaveAndReset() { } for _, cp := range fp.Filter(func(cp protocol.ChunkPos) bool { - return fp.Some(func(sc *chunk.SubChunk) bool { + return !fp.Some(func(sc *chunk.SubChunk) bool { return !sc.Empty() })(w.worldState.chunks[cp].Sub()) })(keys) { diff --git a/utils/behaviourpack/entity.go b/utils/behaviourpack/entity.go index f7b0fa4..21642bf 100644 --- a/utils/behaviourpack/entity.go +++ b/utils/behaviourpack/entity.go @@ -35,24 +35,26 @@ func (bp *BehaviourPack) AddEntity(entity EntityIn) { return } - if _, ok := bp.entities[entity.Identifier]; ok { - return + entry, ok := bp.entities[entity.Identifier] + if !ok { + entry = entityBehaviour{ + FormatVersion: bp.formatVersion, + MinecraftEntity: MinecraftEntity{ + Description: EntityDescription{ + Identifier: entity.Identifier, + Spawnable: true, + Summonable: true, + Experimental: true, + }, + ComponentGroups: make(map[string]any), + Components: make(map[string]any), + Events: nil, + }, + } + } else { + println() } - entry := entityBehaviour{ - FormatVersion: bp.formatVersion, - MinecraftEntity: MinecraftEntity{ - Description: EntityDescription{ - Identifier: entity.Identifier, - Spawnable: true, - Summonable: true, - Experimental: true, - }, - ComponentGroups: make(map[string]any), - Components: make(map[string]any), - Events: nil, - }, - } for _, av := range entity.Attr { switch av.Name { case "minecraft:health": @@ -72,6 +74,13 @@ func (bp *BehaviourPack) AddEntity(entity EntityIn) { "value": scale, } } + AlwaysShowName := entity.Meta.Flag(protocol.EntityDataKeyFlags, protocol.EntityDataFlagAlwaysShowName) + if AlwaysShowName { + entry.MinecraftEntity.Components["minecraft:nameable"] = map[string]any{ + "always_show": true, + "allow_name_tag_renaming": false, + } + } bp.entities[entity.Identifier] = entry } diff --git a/utils/proxy.go b/utils/proxy.go index 4b8df25..bda6824 100644 --- a/utils/proxy.go +++ b/utils/proxy.go @@ -259,11 +259,9 @@ func (p *ProxyContext) Run(ctx context.Context, serverAddress string) (err error var packs []*resource.Pack if Options.Preload { logrus.Info(locale.Loc("preloading_packs", nil)) - var serverConn *minecraft.Conn - serverConn, err = connectServer(ctx, serverAddress, nil, true, nil) + serverConn, err := connectServer(ctx, serverAddress, nil, true, nil) if err != nil { - err = fmt.Errorf(locale.Loc("failed_to_connect", locale.Strmap{"Address": serverAddress, "Err": err})) - return + return fmt.Errorf(locale.Loc("failed_to_connect", locale.Strmap{"Address": serverAddress, "Err": err})) } serverConn.Close() packs = serverConn.ResourcePacks()