save more entity data
This commit is contained in:
parent
d7b559a7a8
commit
ae496e9238
1
build.py
1
build.py
|
@ -23,6 +23,7 @@ if GITHUB_OUTPUT:
|
||||||
with open("./subcommands/resourcepack-d/resourcepack-d.go", "rb") as f:
|
with open("./subcommands/resourcepack-d/resourcepack-d.go", "rb") as f:
|
||||||
PACK_SUPPORT = f.read(100).count(b"package ") > 0
|
PACK_SUPPORT = f.read(100).count(b"package ") > 0
|
||||||
print(f"Pack Support: {PACK_SUPPORT}")
|
print(f"Pack Support: {PACK_SUPPORT}")
|
||||||
|
print(flush=True)
|
||||||
|
|
||||||
LDFLAGS = f"-s -w -X github.com/bedrock-tool/bedrocktool/utils.Version={TAG}"
|
LDFLAGS = f"-s -w -X github.com/bedrock-tool/bedrocktool/utils.Version={TAG}"
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -2,6 +2,7 @@ package world
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bedrock-tool/bedrocktool/utils/behaviourpack"
|
"github.com/bedrock-tool/bedrocktool/utils/behaviourpack"
|
||||||
|
"github.com/bedrock-tool/bedrocktool/utils/nbtconv"
|
||||||
"github.com/df-mc/dragonfly/server/block/cube"
|
"github.com/df-mc/dragonfly/server/block/cube"
|
||||||
"github.com/df-mc/dragonfly/server/world"
|
"github.com/df-mc/dragonfly/server/world"
|
||||||
"github.com/go-gl/mathgl/mgl32"
|
"github.com/go-gl/mathgl/mgl32"
|
||||||
|
@ -19,7 +20,13 @@ type entityState struct {
|
||||||
HeadYaw, BodyYaw float32
|
HeadYaw, BodyYaw float32
|
||||||
Velocity mgl32.Vec3
|
Velocity mgl32.Vec3
|
||||||
|
|
||||||
Metadata protocol.EntityMetadata
|
Metadata protocol.EntityMetadata
|
||||||
|
Inventory map[byte]map[byte]protocol.ItemInstance
|
||||||
|
|
||||||
|
Helmet *protocol.ItemInstance
|
||||||
|
Chestplate *protocol.ItemInstance
|
||||||
|
Leggings *protocol.ItemInstance
|
||||||
|
Boots *protocol.ItemInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
type serverEntityType struct {
|
type serverEntityType struct {
|
||||||
|
@ -84,6 +91,27 @@ func (w *WorldState) processAddActor(pk *packet.AddActor) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var flagNames = map[uint8]string{
|
||||||
|
protocol.EntityDataFlagSheared: "Sheared",
|
||||||
|
protocol.EntityDataFlagCaptain: "IsIllagerCaptain",
|
||||||
|
protocol.EntityDataFlagSitting: "Sitting",
|
||||||
|
protocol.EntityDataFlagBaby: "IsBaby",
|
||||||
|
protocol.EntityDataFlagTamed: "IsTamed",
|
||||||
|
protocol.EntityDataFlagTrusting: "IsTrusting",
|
||||||
|
protocol.EntityDataFlagOrphaned: "IsOrphaned",
|
||||||
|
protocol.EntityDataFlagAngry: "IsAngry",
|
||||||
|
protocol.EntityDataFlagOutOfControl: "IsOutOfControl",
|
||||||
|
protocol.EntityDataFlagSaddled: "Saddled",
|
||||||
|
protocol.EntityDataFlagChested: "Chested",
|
||||||
|
protocol.EntityDataFlagShowBottom: "ShowBottom",
|
||||||
|
protocol.EntityDataFlagGliding: "IsGliding",
|
||||||
|
protocol.EntityDataFlagSwimming: "IsSwimming",
|
||||||
|
protocol.EntityDataFlagEating: "IsEating",
|
||||||
|
protocol.EntityDataFlagScared: "IsScared",
|
||||||
|
protocol.EntityDataFlagStunned: "IsStunned",
|
||||||
|
protocol.EntityDataFlagRoaring: "IsRoaring",
|
||||||
|
}
|
||||||
|
|
||||||
func entityMetadataToNBT(metadata protocol.EntityMetadata, nbt map[string]any) {
|
func entityMetadataToNBT(metadata protocol.EntityMetadata, nbt map[string]any) {
|
||||||
if variant, ok := metadata[protocol.EntityDataKeyVariant]; ok {
|
if variant, ok := metadata[protocol.EntityDataKeyVariant]; ok {
|
||||||
nbt["Variant"] = variant
|
nbt["Variant"] = variant
|
||||||
|
@ -108,6 +136,49 @@ func entityMetadataToNBT(metadata protocol.EntityMetadata, nbt map[string]any) {
|
||||||
nbt["CustomNameVisible"] = false
|
nbt["CustomNameVisible"] = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if metadata.Flag(protocol.EntityDataKeyFlags, protocol.EntityDataFlagNoAI) {
|
||||||
|
nbt["IsAutonomous"] = false
|
||||||
|
}
|
||||||
|
for k, v := range flagNames {
|
||||||
|
nbt[v] = metadata.Flag(protocol.EntityDataKeyFlags, k)
|
||||||
|
}
|
||||||
|
|
||||||
|
AlwaysShowName := metadata.Flag(protocol.EntityDataKeyFlags, protocol.EntityDataFlagAlwaysShowName)
|
||||||
|
if AlwaysShowName {
|
||||||
|
nbt["CustomNameVisible"] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
type effect struct {
|
||||||
|
Id byte
|
||||||
|
Amplifier byte
|
||||||
|
Duration int32
|
||||||
|
DurationEasy int32
|
||||||
|
DurationNormal int32
|
||||||
|
DurationHard int32
|
||||||
|
Ambient bool
|
||||||
|
ShowParticles bool
|
||||||
|
DisplayOnScreenTextureAnimation bool
|
||||||
|
}
|
||||||
|
|
||||||
|
activeEffects := []effect{}
|
||||||
|
addEffect := func(id int, showParticles bool) {
|
||||||
|
activeEffects = append(activeEffects, effect{
|
||||||
|
Id: byte(id),
|
||||||
|
Amplifier: 1,
|
||||||
|
Duration: 10000000,
|
||||||
|
ShowParticles: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
invisible := metadata.Flag(protocol.EntityDataKeyFlags, protocol.EntityDataFlagInvisible)
|
||||||
|
if invisible {
|
||||||
|
addEffect(packet.EffectInvisibility, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(activeEffects) > 0 {
|
||||||
|
nbt["ActiveEffects"] = activeEffects
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func vec3float32(x mgl32.Vec3) []float32 {
|
func vec3float32(x mgl32.Vec3) []float32 {
|
||||||
|
@ -127,6 +198,16 @@ func (s *entityState) ToServerEntity() serverEntity {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
entityMetadataToNBT(s.Metadata, e.EntityType.NBT)
|
entityMetadataToNBT(s.Metadata, e.EntityType.NBT)
|
||||||
|
|
||||||
|
if s.Helmet != nil || s.Chestplate != nil || s.Leggings != nil || s.Boots != nil {
|
||||||
|
armor := make([]map[string]any, 0, 4)
|
||||||
|
armor = append(armor, nbtconv.WriteItem(stackToItem(s.Helmet.Stack), true))
|
||||||
|
armor = append(armor, nbtconv.WriteItem(stackToItem(s.Chestplate.Stack), true))
|
||||||
|
armor = append(armor, nbtconv.WriteItem(stackToItem(s.Leggings.Stack), true))
|
||||||
|
armor = append(armor, nbtconv.WriteItem(stackToItem(s.Boots.Stack), true))
|
||||||
|
e.EntityType.NBT["Armor"] = armor
|
||||||
|
}
|
||||||
|
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,6 +257,24 @@ func (w *WorldState) ProcessEntityPackets(pk packet.Packet) packet.Packet {
|
||||||
e.Pitch = pk.Rotation.X()
|
e.Pitch = pk.Rotation.X()
|
||||||
e.Yaw = pk.Rotation.Y()
|
e.Yaw = pk.Rotation.Y()
|
||||||
}
|
}
|
||||||
|
case *packet.MobEquipment:
|
||||||
|
e, ok := w.entities[pk.EntityRuntimeID]
|
||||||
|
if ok {
|
||||||
|
w, ok := e.Inventory[pk.WindowID]
|
||||||
|
if !ok {
|
||||||
|
w = make(map[byte]protocol.ItemInstance)
|
||||||
|
e.Inventory[pk.WindowID] = w
|
||||||
|
}
|
||||||
|
w[pk.HotBarSlot] = pk.NewItem
|
||||||
|
}
|
||||||
|
case *packet.MobArmourEquipment:
|
||||||
|
e, ok := w.entities[pk.EntityRuntimeID]
|
||||||
|
if ok {
|
||||||
|
e.Helmet = &pk.Helmet
|
||||||
|
e.Chestplate = &pk.Chestplate
|
||||||
|
e.Leggings = &pk.Chestplate
|
||||||
|
e.Boots = &pk.Boots
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return pk
|
return pk
|
||||||
}
|
}
|
||||||
|
|
|
@ -482,6 +482,10 @@ func (w *WorldState) SaveAndReset() {
|
||||||
} else {
|
} else {
|
||||||
var rdeps []dep
|
var rdeps []dep
|
||||||
for k, p := range packs {
|
for k, p := range packs {
|
||||||
|
if p.Encrypted() && !p.CanDecrypt() {
|
||||||
|
logrus.Warnf("Cant add %s, it is encrypted", p.Name())
|
||||||
|
continue
|
||||||
|
}
|
||||||
logrus.Infof(locale.Loc("adding_pack", locale.Strmap{"Name": k}))
|
logrus.Infof(locale.Loc("adding_pack", locale.Strmap{"Name": k}))
|
||||||
packFolder := path.Join(folder, "resource_packs", p.Name())
|
packFolder := path.Join(folder, "resource_packs", p.Name())
|
||||||
os.MkdirAll(packFolder, 0o755)
|
os.MkdirAll(packFolder, 0o755)
|
||||||
|
@ -495,7 +499,7 @@ func (w *WorldState) SaveAndReset() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if len(rdeps) > 0 {
|
if len(rdeps) > 0 {
|
||||||
addPacksJSON("world_resource_packs.json", rdeps)
|
//addPacksJSON("world_resource_packs.json", rdeps)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,18 +40,15 @@ func (m *Map) HandlePointerEvent(e pointer.Event) {
|
||||||
case pointer.Release:
|
case pointer.Release:
|
||||||
m.grabbed = false
|
m.grabbed = false
|
||||||
case pointer.Scroll:
|
case pointer.Scroll:
|
||||||
m.HandleScrollEvent(e)
|
scaleFactor := float32(math.Pow(1.01, float64(e.Scroll.Y)))
|
||||||
|
m.transform = m.transform.Scale(e.Position.Sub(m.center), f32.Pt(scaleFactor, scaleFactor))
|
||||||
|
m.scaleFactor *= scaleFactor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Map) HandleScrollEvent(e pointer.Event) {
|
|
||||||
scaleFactor := float32(math.Pow(1.01, float64(e.Scroll.Y)))
|
|
||||||
m.transform = m.transform.Scale(e.Position.Sub(m.center), f32.Pt(scaleFactor, scaleFactor))
|
|
||||||
m.scaleFactor *= scaleFactor
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Map) Layout(gtx layout.Context) layout.Dimensions {
|
func (m *Map) Layout(gtx layout.Context) layout.Dimensions {
|
||||||
// here we loop through all the events associated with this button.
|
m.center = f32.Pt(float32(gtx.Constraints.Max.X), float32(gtx.Constraints.Max.Y)).Div(2)
|
||||||
|
|
||||||
for _, e := range gtx.Events(m) {
|
for _, e := range gtx.Events(m) {
|
||||||
if e, ok := e.(pointer.Event); ok {
|
if e, ok := e.(pointer.Event); ok {
|
||||||
m.HandlePointerEvent(e)
|
m.HandlePointerEvent(e)
|
||||||
|
@ -64,17 +61,9 @@ func (m *Map) Layout(gtx layout.Context) layout.Dimensions {
|
||||||
dy := float32(m.MapImage.Bounds().Dy())
|
dy := float32(m.MapImage.Bounds().Dy())
|
||||||
size := f32.Pt(dx*m.scaleFactor, dy*m.scaleFactor)
|
size := f32.Pt(dx*m.scaleFactor, dy*m.scaleFactor)
|
||||||
|
|
||||||
m.center = f32.Pt(
|
|
||||||
float32(gtx.Constraints.Max.X),
|
|
||||||
float32(gtx.Constraints.Max.Y),
|
|
||||||
).Div(2)
|
|
||||||
|
|
||||||
// Calculate the offset required to center the image within the widget.
|
|
||||||
offset := m.center.Sub(size.Div(2))
|
|
||||||
|
|
||||||
// Draw the image at the correct position and scale.
|
// Draw the image at the correct position and scale.
|
||||||
defer clip.Rect{Max: gtx.Constraints.Max}.Push(gtx.Ops).Pop()
|
defer clip.Rect{Max: gtx.Constraints.Max}.Push(gtx.Ops).Pop()
|
||||||
op.Affine(m.transform.Offset(offset)).Add(gtx.Ops)
|
op.Affine(m.transform.Offset(m.center.Sub(size.Div(2)))).Add(gtx.Ops)
|
||||||
m.imageOp.Add(gtx.Ops)
|
m.imageOp.Add(gtx.Ops)
|
||||||
paint.PaintOp{}.Add(gtx.Ops)
|
paint.PaintOp{}.Add(gtx.Ops)
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,8 @@ var PackFromBase = func(pack *resource.Pack) Pack {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPacks(server *minecraft.Conn) (packs map[string]*resource.Pack, err error) {
|
func GetPacks(server *minecraft.Conn) (packs map[string]Pack, err error) {
|
||||||
packs = make(map[string]*resource.Pack)
|
packs = make(map[string]Pack)
|
||||||
for _, pack := range server.ResourcePacks() {
|
for _, pack := range server.ResourcePacks() {
|
||||||
pack := PackFromBase(pack)
|
pack := PackFromBase(pack)
|
||||||
if pack.Encrypted() && pack.CanDecrypt() {
|
if pack.Encrypted() && pack.CanDecrypt() {
|
||||||
|
@ -73,9 +73,9 @@ func GetPacks(server *minecraft.Conn) (packs map[string]*resource.Pack, err erro
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
packs[pack.Name()] = pack2
|
packs[pack.Name()] = &Packb{pack2}
|
||||||
} else {
|
} else {
|
||||||
packs[pack.Name()] = pack.Base()
|
packs[pack.Name()] = pack
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue