small fixes

This commit is contained in:
olebeck 2023-04-02 14:20:50 +02:00
parent 88589933ea
commit 9b3a31879a
6 changed files with 41 additions and 24 deletions

View File

@ -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
}

View File

@ -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]

View File

@ -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) {

View File

@ -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
}

View File

@ -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()