diff --git a/handlers/worlds/worldstate/entity.go b/handlers/worlds/worldstate/entity.go index 8cfb809..e16425e 100644 --- a/handlers/worlds/worldstate/entity.go +++ b/handlers/worlds/worldstate/entity.go @@ -307,6 +307,23 @@ func (s *EntityState) ToServerEntity(links []int64, properties []behaviourpack.E } s.toNBT(e.EntityType.NBT) + if len(s.Properties.FloatProperties)+len(s.Properties.IntegerProperties) > 0 { + nbtProperties := map[string]any{} + for _, prop := range s.Properties.FloatProperties { + propDef := properties[prop.Index] + nbtProperties[propDef.Name] = prop.Value + } + for _, prop := range s.Properties.IntegerProperties { + propDef := properties[prop.Index] + if propDef.Type == behaviourpack.PropertyTypeBool { + nbtProperties[propDef.Name] = prop.Value == 1 + } else { + nbtProperties[propDef.Name] = prop.Value + } + } + e.EntityType.NBT["properties"] = nbtProperties + } + var linksTag []map[string]any for i, el := range links { linksTag = append(linksTag, map[string]any{ diff --git a/handlers/worlds/worldstate/world.go b/handlers/worlds/worldstate/world.go index 6ed044f..0617fac 100644 --- a/handlers/worlds/worldstate/world.go +++ b/handlers/worlds/worldstate/world.go @@ -41,6 +41,12 @@ type worldStateInterface interface { GetEntity(id EntityRuntimeID) *EntityState AddEntityLink(el protocol.EntityLink) } + +type resourcePackDependency struct { + UUID string `json:"pack_id"` + Version [3]int `json:"version"` +} + type World struct { // called when a chunk is added ChunkFunc func(world.ChunkPos, *chunk.Chunk) @@ -66,7 +72,7 @@ type World struct { ResourcePacks []resource.Pack resourcePacksDone chan error - resourcePackDependencies []resource.Dependency + resourcePackDependencies []resourcePackDependency // closed when this world is done finish chan struct{} @@ -188,7 +194,7 @@ func (w *World) storeMemToProvider() error { return nil } -func addPacksJSON(fs utils.WriterFS, name string, deps []resource.Dependency) error { +func addPacksJSON(fs utils.WriterFS, name string, deps []resourcePackDependency) error { f, err := fs.Create(name) if err != nil { return err @@ -200,10 +206,20 @@ func addPacksJSON(fs utils.WriterFS, name string, deps []resource.Dependency) er return nil } +var removeSpace = strings.NewReplacer(" ", "") + +func formatPackName(packName string) string { + packName = text.Clean(packName) + packName, _ = filenamify.FilenamifyV2(packName) + packName = removeSpace.Replace(packName) + packName = packName[:10] + return packName +} + func (w *World) addResourcePacks() error { packNames := make(map[string][]string) for _, pack := range w.ResourcePacks { - packName := pack.Name() + packName := formatPackName(pack.Name()) packNames[packName] = append(packNames[packName], pack.UUID()) } @@ -213,30 +229,29 @@ func (w *World) addResourcePacks() error { log.Warn("Cant add is encrypted") continue } - logrus.Infof(locale.Loc("adding_pack", locale.Strmap{"Name": pack.Name()})) + logrus.Infof(locale.Loc("adding_pack", locale.Strmap{"Name": text.Clean(pack.Name())})) messages.Router.Handle(&messages.Message{ Source: "subcommand", Target: "ui", Data: messages.ProcessingWorldUpdate{ Name: w.Name, - State: "Adding Resourcepack " + pack.Name(), + State: "Adding Resourcepack " + text.Clean(pack.Name()), }, }) - packName := pack.Name() + packName := formatPackName(pack.Name()) if packIds := packNames[packName]; len(packIds) > 1 { - packName = fmt.Sprintf("%s_%d", packName, slices.Index(packIds, pack.UUID())) + packName = fmt.Sprintf("%s_%d", packName[:8], slices.Index(packIds, pack.UUID())) } - packName = text.Clean(packName) - packName, _ = filenamify.FilenamifyV2(packName) + err := utils.CopyFS(pack, utils.SubFS(utils.OSWriter{Base: w.Folder}, path.Join("resource_packs", packName))) if err != nil { log.Error(err) continue } - w.resourcePackDependencies = append(w.resourcePackDependencies, resource.Dependency{ + w.resourcePackDependencies = append(w.resourcePackDependencies, resourcePackDependency{ UUID: pack.Manifest().Header.UUID, Version: pack.Manifest().Header.Version, }) @@ -287,7 +302,7 @@ func (w *World) FinalizePacks(serverName string) error { return err } - err = addPacksJSON(fs, "world_behavior_packs.json", []resource.Dependency{{ + err = addPacksJSON(fs, "world_behavior_packs.json", []resourcePackDependency{{ UUID: w.BehaviorPack.Manifest.Header.UUID, Version: w.BehaviorPack.Manifest.Header.Version, }}) diff --git a/utils/behaviourpack/entity.go b/utils/behaviourpack/entity.go index 86f896b..fdebe7c 100644 --- a/utils/behaviourpack/entity.go +++ b/utils/behaviourpack/entity.go @@ -50,6 +50,13 @@ type EntityPropertyJson struct { ClientSync bool `json:"client_sync"` } +const ( + PropertyTypeInt = iota + PropertyTypeFloat + PropertyTypeBool + PropertyTypeEnum +) + func (bp *Pack) AddEntity(entity EntityIn) { ns, _ := ns_name_split(entity.Identifier) if ns == "minecraft" { @@ -130,18 +137,18 @@ func (bp *Pack) AddEntity(entity EntityIn) { var prop EntityPropertyJson prop.ClientSync = true switch v.Type { - case propertyTypeInt: + case PropertyTypeInt: prop.Type = "int" prop.Range = []any{int(v.Min), int(v.Max)} prop.Default = int(v.Min) - case propertyTypeFloat: + case PropertyTypeFloat: prop.Type = "float" prop.Range = []any{v.Min, v.Max} prop.Default = v.Min - case propertyTypeBool: + case PropertyTypeBool: prop.Type = "bool" prop.Default = false - case propertyTypeEnum: + case PropertyTypeEnum: prop.Type = "enum" prop.Values = v.Enum prop.Default = v.Enum[0] @@ -154,13 +161,6 @@ func (bp *Pack) AddEntity(entity EntityIn) { bp.entities[entity.Identifier] = entry } -const ( - propertyTypeInt = iota - propertyTypeFloat - propertyTypeBool - propertyTypeEnum -) - func (bp *Pack) GetEntityTypeProperties(entityType string) []EntityProperty { return bp.entityProperties[entityType] } @@ -192,7 +192,7 @@ func (bp *Pack) SyncActorProperty(pk *packet.SyncActorProperty) { prop.Type = propertyType switch propertyType { - case propertyTypeInt: + case PropertyTypeInt: min, ok := property["min"].(int32) if !ok { continue @@ -203,7 +203,7 @@ func (bp *Pack) SyncActorProperty(pk *packet.SyncActorProperty) { } prop.Min = float32(min) prop.Max = float32(max) - case propertyTypeFloat: + case PropertyTypeFloat: min, ok := property["min"].(int32) if !ok { continue @@ -214,8 +214,8 @@ func (bp *Pack) SyncActorProperty(pk *packet.SyncActorProperty) { } prop.Min = float32(min) prop.Max = float32(max) - case propertyTypeBool: - case propertyTypeEnum: + case PropertyTypeBool: + case PropertyTypeEnum: prop.Enum, _ = property["enum"].([]any) default: fmt.Printf("Unknown property type %d", propertyType) diff --git a/utils/behaviourpack/item.go b/utils/behaviourpack/item.go index 0b1cb1c..b584cb4 100644 --- a/utils/behaviourpack/item.go +++ b/utils/behaviourpack/item.go @@ -43,6 +43,18 @@ func (bp *Pack) ApplyComponentEntries(entries []protocol.ItemComponentEntry) { continue } if components, ok := ice.Data["components"].(map[string]any); ok { + if _, ok := components["minecraft:icon"]; !ok { + if item_properties, ok := components["item_properties"].(map[string]any); ok { + components["minecraft:icon"] = item_properties["minecraft:icon"] + } + } + + if icon, ok := components["minecraft:icon"].(map[string]any); ok { + if textures, ok := icon["textures"].(map[string]any); ok { + icon["textures"] = textures["default"] + } + } + item.MinecraftItem.Components = components } }