mirror of
https://github.com/CosmicStar98/bedrocktool.git
synced 2024-06-09 09:29:45 +00:00
update dragonfly
This commit is contained in:
parent
56ac765b1d
commit
d5dec0af98
2
go.mod
2
go.mod
|
@ -6,7 +6,7 @@ go 1.19
|
||||||
replace github.com/sandertv/gophertunnel => github.com/olebeck/gophertunnel v1.26.2
|
replace github.com/sandertv/gophertunnel => github.com/olebeck/gophertunnel v1.26.2
|
||||||
|
|
||||||
//replace github.com/df-mc/dragonfly => ./dragonfly
|
//replace github.com/df-mc/dragonfly => ./dragonfly
|
||||||
replace github.com/df-mc/dragonfly => github.com/olebeck/dragonfly v0.9.1-2
|
replace github.com/df-mc/dragonfly => github.com/olebeck/dragonfly v0.9.1-3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cloudfoundry-attic/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21
|
github.com/cloudfoundry-attic/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -70,6 +70,8 @@ github.com/olebeck/dragonfly v0.9.1-1 h1:b5CIocRvmxdesW6N6V87xTDH4fFLVthb1GRptbb
|
||||||
github.com/olebeck/dragonfly v0.9.1-1/go.mod h1:ZjzPME6I1nc73voUgr2s5lpkoTxnWuR54V6c1KbULX0=
|
github.com/olebeck/dragonfly v0.9.1-1/go.mod h1:ZjzPME6I1nc73voUgr2s5lpkoTxnWuR54V6c1KbULX0=
|
||||||
github.com/olebeck/dragonfly v0.9.1-2 h1:Rry/efQl4ORUakJNTnHCY0vB6AUmZuUpy+PsLSbWoRY=
|
github.com/olebeck/dragonfly v0.9.1-2 h1:Rry/efQl4ORUakJNTnHCY0vB6AUmZuUpy+PsLSbWoRY=
|
||||||
github.com/olebeck/dragonfly v0.9.1-2/go.mod h1:ZjzPME6I1nc73voUgr2s5lpkoTxnWuR54V6c1KbULX0=
|
github.com/olebeck/dragonfly v0.9.1-2/go.mod h1:ZjzPME6I1nc73voUgr2s5lpkoTxnWuR54V6c1KbULX0=
|
||||||
|
github.com/olebeck/dragonfly v0.9.1-3 h1:ULE04Wx6MzBMuMmjj+xb9VtdYnCRoI6EafOWqcYz1hI=
|
||||||
|
github.com/olebeck/dragonfly v0.9.1-3/go.mod h1:ZjzPME6I1nc73voUgr2s5lpkoTxnWuR54V6c1KbULX0=
|
||||||
github.com/olebeck/gophertunnel v1.26.2 h1:AbiZcmeR5LenSJ5NX/2BPxLC3ddlvgWjrjouPmOB6BA=
|
github.com/olebeck/gophertunnel v1.26.2 h1:AbiZcmeR5LenSJ5NX/2BPxLC3ddlvgWjrjouPmOB6BA=
|
||||||
github.com/olebeck/gophertunnel v1.26.2/go.mod h1:dYFetA6r62huhc1EgR9p8VFAFtKOuGgVE/iXf5CzZ4o=
|
github.com/olebeck/gophertunnel v1.26.2/go.mod h1:dYFetA6r62huhc1EgR9p8VFAFtKOuGgVE/iXf5CzZ4o=
|
||||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
|
|
|
@ -25,10 +25,10 @@ var MAP_ITEM_PACKET packet.InventoryContent = packet.InventoryContent{
|
||||||
WindowID: 119,
|
WindowID: 119,
|
||||||
Content: []protocol.ItemInstance{
|
Content: []protocol.ItemInstance{
|
||||||
{
|
{
|
||||||
StackNetworkID: 1,
|
StackNetworkID: 1, // random if auth inv
|
||||||
Stack: protocol.ItemStack{
|
Stack: protocol.ItemStack{
|
||||||
ItemType: protocol.ItemType{
|
ItemType: protocol.ItemType{
|
||||||
NetworkID: 420,
|
NetworkID: 420, // overwritten in onconnect
|
||||||
MetadataValue: 0,
|
MetadataValue: 0,
|
||||||
},
|
},
|
||||||
BlockRuntimeID: 0,
|
BlockRuntimeID: 0,
|
||||||
|
@ -102,7 +102,7 @@ func (m *MapUI) Start() {
|
||||||
Width: 128,
|
Width: 128,
|
||||||
Height: 128,
|
Height: 128,
|
||||||
Pixels: utils.Img2rgba(m.img),
|
Pixels: utils.Img2rgba(m.img),
|
||||||
UpdateFlags: 2,
|
UpdateFlags: packet.MapUpdateFlagTexture,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"image"
|
"image"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
"image/png"
|
"image/png"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -59,7 +60,6 @@ type WorldState struct {
|
||||||
chunks map[protocol.ChunkPos]*chunk.Chunk
|
chunks map[protocol.ChunkPos]*chunk.Chunk
|
||||||
blockNBT map[protocol.SubChunkPos][]map[string]any
|
blockNBT map[protocol.SubChunkPos][]map[string]any
|
||||||
openItemContainers map[byte]*itemContainer
|
openItemContainers map[byte]*itemContainer
|
||||||
airRid uint32
|
|
||||||
|
|
||||||
Dim world.Dimension
|
Dim world.Dimension
|
||||||
WorldName string
|
WorldName string
|
||||||
|
@ -87,7 +87,6 @@ func NewWorldState() *WorldState {
|
||||||
Dim: nil,
|
Dim: nil,
|
||||||
WorldName: "world",
|
WorldName: "world",
|
||||||
PlayerPos: TPlayerPos{},
|
PlayerPos: TPlayerPos{},
|
||||||
airRid: 6692,
|
|
||||||
}
|
}
|
||||||
w.ui = NewMapUI(w)
|
w.ui = NewMapUI(w)
|
||||||
return w
|
return w
|
||||||
|
@ -209,7 +208,7 @@ func (w *WorldState) ProcessLevelChunk(pk *packet.LevelChunk) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ch, blockNBTs, err := chunk.NetworkDecode(w.airRid, pk.RawPayload, int(pk.SubChunkCount), w.Dim.Range(), w.ispre118)
|
ch, blockNBTs, err := chunk.NetworkDecode(world.AirRID(), pk.RawPayload, int(pk.SubChunkCount), w.Dim.Range(), w.ispre118)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return
|
return
|
||||||
|
@ -320,6 +319,10 @@ func (w *WorldState) Reset() {
|
||||||
|
|
||||||
// writes the world to a folder, resets all the chunks
|
// writes the world to a folder, resets all the chunks
|
||||||
func (w *WorldState) SaveAndReset() {
|
func (w *WorldState) SaveAndReset() {
|
||||||
|
if len(w.chunks) == 0 {
|
||||||
|
w.Reset()
|
||||||
|
return
|
||||||
|
}
|
||||||
logrus.Infof(locale.Loc("saving_world", locale.Strmap{"Name": w.WorldName, "Count": len(w.chunks)}))
|
logrus.Infof(locale.Loc("saving_world", locale.Strmap{"Name": w.WorldName, "Count": len(w.chunks)}))
|
||||||
|
|
||||||
// open world
|
// open world
|
||||||
|
@ -492,6 +495,13 @@ func (w *WorldState) SaveAndReset() {
|
||||||
PackId: w.bp.Manifest.Header.UUID,
|
PackId: w.bp.Manifest.Header.UUID,
|
||||||
Version: w.bp.Manifest.Header.Version,
|
Version: w.bp.Manifest.Header.Version,
|
||||||
}})
|
}})
|
||||||
|
|
||||||
|
if ld.Experiments == nil {
|
||||||
|
ld.Experiments = map[string]any{}
|
||||||
|
}
|
||||||
|
ld.Experiments["data_driven_items"] = true
|
||||||
|
ld.Experiments["experiments_ever_used"] = true
|
||||||
|
ld.Experiments["saved_with_toggled_experiments"] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if w.saveImage {
|
if w.saveImage {
|
||||||
|
@ -515,6 +525,14 @@ func (w *WorldState) OnConnect(proxy *utils.ProxyContext) {
|
||||||
w.proxy = proxy
|
w.proxy = proxy
|
||||||
gd := w.proxy.Server.GameData()
|
gd := w.proxy.Server.GameData()
|
||||||
|
|
||||||
|
world.InsertCustomItems(gd.Items)
|
||||||
|
|
||||||
|
map_item_id, _ := world.ItemRidByName("minecraft:filled_map")
|
||||||
|
MAP_ITEM_PACKET.Content[0].Stack.ItemType.NetworkID = map_item_id
|
||||||
|
if gd.ServerAuthoritativeInventory {
|
||||||
|
MAP_ITEM_PACKET.Content[0].StackNetworkID = rand.Int31n(32)
|
||||||
|
}
|
||||||
|
|
||||||
if len(gd.CustomBlocks) > 0 {
|
if len(gd.CustomBlocks) > 0 {
|
||||||
logrus.Info(locale.Loc("using_customblocks", nil))
|
logrus.Info(locale.Loc("using_customblocks", nil))
|
||||||
|
|
||||||
|
@ -561,11 +579,12 @@ func (w *WorldState) OnConnect(proxy *utils.ProxyContext) {
|
||||||
case <-w.ctx.Done():
|
case <-w.ctx.Done():
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
for {
|
t := time.NewTicker(1 * time.Second)
|
||||||
time.Sleep(1 * time.Second)
|
for range t.C {
|
||||||
if w.proxy.Client != nil {
|
if w.proxy.Client != nil {
|
||||||
err := w.proxy.Client.WritePacket(&MAP_ITEM_PACKET)
|
err := w.proxy.Client.WritePacket(&MAP_ITEM_PACKET)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -613,6 +632,44 @@ func (w *WorldState) ProcessPacketClient(pk packet.Packet) (packet.Packet, bool)
|
||||||
w.ui.SchedRedraw()
|
w.ui.SchedRedraw()
|
||||||
forward = false
|
forward = false
|
||||||
}
|
}
|
||||||
|
case *packet.ItemStackRequest:
|
||||||
|
var requests []protocol.ItemStackRequest
|
||||||
|
for _, isr := range pk.Requests {
|
||||||
|
for _, sra := range isr.Actions {
|
||||||
|
if sra, ok := sra.(*protocol.TakeStackRequestAction); ok {
|
||||||
|
if sra.Source.StackNetworkID == MAP_ITEM_PACKET.Content[0].StackNetworkID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sra, ok := sra.(*protocol.DropStackRequestAction); ok {
|
||||||
|
if sra.Source.StackNetworkID == MAP_ITEM_PACKET.Content[0].StackNetworkID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sra, ok := sra.(*protocol.DestroyStackRequestAction); ok {
|
||||||
|
if sra.Source.StackNetworkID == MAP_ITEM_PACKET.Content[0].StackNetworkID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sra, ok := sra.(*protocol.PlaceInContainerStackRequestAction); ok {
|
||||||
|
if sra.Source.StackNetworkID == MAP_ITEM_PACKET.Content[0].StackNetworkID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sra, ok := sra.(*protocol.TakeOutContainerStackRequestAction); ok {
|
||||||
|
if sra.Source.StackNetworkID == MAP_ITEM_PACKET.Content[0].StackNetworkID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sra, ok := sra.(*protocol.DestroyStackRequestAction); ok {
|
||||||
|
if sra.Source.StackNetworkID == MAP_ITEM_PACKET.Content[0].StackNetworkID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
requests = append(requests, isr)
|
||||||
|
}
|
||||||
|
pk.Requests = requests
|
||||||
case *packet.MobEquipment:
|
case *packet.MobEquipment:
|
||||||
if pk.NewItem.Stack.NBTData["map_uuid"] == int64(VIEW_MAP_ID) {
|
if pk.NewItem.Stack.NBTData["map_uuid"] == int64(VIEW_MAP_ID) {
|
||||||
forward = false
|
forward = false
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/bedrock-tool/bedrocktool/utils"
|
"github.com/bedrock-tool/bedrocktool/utils"
|
||||||
|
"github.com/df-mc/dragonfly/server/world"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/sandertv/gophertunnel/minecraft/protocol"
|
"github.com/sandertv/gophertunnel/minecraft/protocol"
|
||||||
"github.com/sandertv/gophertunnel/minecraft/resource"
|
"github.com/sandertv/gophertunnel/minecraft/resource"
|
||||||
|
@ -21,65 +22,9 @@ type BehaviourPack struct {
|
||||||
blocks []blockBehaviour
|
blocks []blockBehaviour
|
||||||
}
|
}
|
||||||
|
|
||||||
type description struct {
|
|
||||||
Identifier string `json:"identifier"`
|
|
||||||
IsExperimental bool `json:"is_experimental"`
|
|
||||||
RegisterToCreativeMenu bool `json:"register_to_creative_menu"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type menu_category struct {
|
|
||||||
Category string `json:"category"`
|
|
||||||
Group string `json:"group"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func menu_category_from_map(in map[string]any) menu_category {
|
|
||||||
return menu_category{
|
|
||||||
Category: in["category"].(string),
|
|
||||||
Group: in["group"].(string),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type permutation struct {
|
|
||||||
Components map[string]any `json:"components"`
|
|
||||||
Condition string `json:"condition"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func permutations_from_list(in []map[string]any) (out []permutation) {
|
|
||||||
for _, v := range in {
|
|
||||||
out = append(out, permutation{
|
|
||||||
Components: v["components"].(map[string]any),
|
|
||||||
Condition: v["condition"].(string),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
type property struct {
|
|
||||||
Enum []any `json:"enum"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func properties_from_list(in []map[string]any) (out []property) {
|
|
||||||
for _, v := range in {
|
|
||||||
out = append(out, property{
|
|
||||||
Enum: v["enum"].([]any),
|
|
||||||
Name: v["name"].(string),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
type minecraftBlock struct {
|
|
||||||
Description description `json:"description"`
|
|
||||||
Components map[string]any `json:"components,omitempty"`
|
|
||||||
MenuCategory menu_category `json:"menu_category,omitempty"`
|
|
||||||
Permutations []permutation `json:"permutations,omitempty"`
|
|
||||||
Properties []property `json:"properties,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type blockBehaviour struct {
|
type blockBehaviour struct {
|
||||||
FormatVersion string `json:"format_version"`
|
FormatVersion string `json:"format_version"`
|
||||||
MinecraftBlock minecraftBlock `json:"minecraft:block"`
|
MinecraftBlock world.MinecraftBlock `json:"minecraft:block"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func check(err error) {
|
func check(err error) {
|
||||||
|
@ -127,56 +72,8 @@ func (bp *BehaviourPack) AddDependency(id string, ver [3]int) {
|
||||||
|
|
||||||
func (bp *BehaviourPack) AddBlock(block protocol.BlockEntry) {
|
func (bp *BehaviourPack) AddBlock(block protocol.BlockEntry) {
|
||||||
entry := blockBehaviour{
|
entry := blockBehaviour{
|
||||||
FormatVersion: "1.16.0",
|
FormatVersion: "1.16.0",
|
||||||
MinecraftBlock: minecraftBlock{
|
MinecraftBlock: world.ParseBlock(block),
|
||||||
Description: description{
|
|
||||||
Identifier: block.Name,
|
|
||||||
IsExperimental: true,
|
|
||||||
RegisterToCreativeMenu: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
v2 := false
|
|
||||||
|
|
||||||
if perms, ok := block.Properties["permutations"].([]map[string]any); ok {
|
|
||||||
entry.MinecraftBlock.Permutations = permutations_from_list(perms)
|
|
||||||
v2 = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if comps, ok := block.Properties["components"].(map[string]any); ok {
|
|
||||||
delete(comps, "minecraft:creative_category")
|
|
||||||
|
|
||||||
for k, v := range comps {
|
|
||||||
if v, ok := v.(map[string]any); ok {
|
|
||||||
// fix {"value": 0.1} -> 0.1
|
|
||||||
if v, ok := v["value"]; ok {
|
|
||||||
comps[k] = v
|
|
||||||
}
|
|
||||||
// fix {"lightLevel": 15} -> 15
|
|
||||||
if v, ok := v["lightLevel"]; ok {
|
|
||||||
comps[k] = v
|
|
||||||
}
|
|
||||||
// fix missing * instance
|
|
||||||
if k == "minecraft:material_instances" {
|
|
||||||
comps[k] = v["materials"].(map[string]any)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
entry.MinecraftBlock.Components = comps
|
|
||||||
v2 = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if menu, ok := block.Properties["menu_category"].(map[string]any); ok {
|
|
||||||
entry.MinecraftBlock.MenuCategory = menu_category_from_map(menu)
|
|
||||||
v2 = true
|
|
||||||
}
|
|
||||||
if props, ok := block.Properties["properties"].([]map[string]any); ok {
|
|
||||||
entry.MinecraftBlock.Properties = properties_from_list(props)
|
|
||||||
v2 = true
|
|
||||||
}
|
|
||||||
if !v2 {
|
|
||||||
entry.MinecraftBlock.Components = block.Properties
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bp.blocks = append(bp.blocks, entry)
|
bp.blocks = append(bp.blocks, entry)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user