Exemplo n.º 1
0
        public void HandlePacket(BedrockTraceHandler caller, Packet packet)
        {
            switch (packet)
            {
            case McpeAddItemEntity mcpePacket:
                HandleMcpeAddItemEntity(mcpePacket);
                break;

            case McpeUpdateBlock mcpePacket:
                HandleMcpeUpdateBlock(caller, mcpePacket);
                break;

            case McpePlayerHotbar mcpePacket:
                HandleMcpePlayerHotbar(mcpePacket);
                break;

            case McpeInventoryContent mcpePacket:
                HandleMcpeInventoryContent(mcpePacket);
                break;

            case McpeInventorySlot mcpePacket:
                HandleInventorySlot(mcpePacket);
                break;

            default:
                return;
            }
        }
Exemplo n.º 2
0
 public void Execute(BedrockTraceHandler caller, string text)
 {
     if (text.Contains("all blocks"))
     {
         ExecuteAllBlocks(caller);
     }
     else if (text.Contains("discover drops"))
     {
         ExecuteDiscoveryOfItemDrops(caller);
     }
     else if (text.Contains("write palette"))
     {
         ExecuteWritePallet(caller);
     }
     else if (text.Contains("pick blocks"))
     {
         ExecutePickBlocks(caller);
     }
     else if (text.Contains("print palette"))
     {
         PrintPalette(caller);
     }
     else
     {
         Log.Debug($"Found no matching method for '{text}'");
     }
 }
Exemplo n.º 3
0
        private void ExecuteWritePallet(BedrockTraceHandler caller)
        {
            var          client  = caller.Client;
            BlockPalette palette = client.BlockPalette;

            _runningBlockMetadataDiscovery = false;

            WritePaletteToJson(palette);
        }
Exemplo n.º 4
0
        private void PrintPalette(BedrockTraceHandler caller)
        {
            var client  = caller.Client;
            var palette = client.BlockPalette;

            foreach (BlockStateContainer blockState in palette.OrderByDescending(bs => bs.Id))
            {
                Log.Warn($"{blockState.Name}");
            }
        }
Exemplo n.º 5
0
        private void SetGameRules(BedrockTraceHandler caller)
        {
            var client = caller.Client;

            SendCommand(client, $"/gamerule randomtickspeed 0");
            SendCommand(client, $"/gamerule doentitydrops false");
            SendCommand(client, $"/gamerule domobloot false");
            SendCommand(client, $"/gamerule domobspawning false");
            SendCommand(client, $"/gamerule dotiledrops false");
            SendCommand(client, $"/gamerule mobgriefing false");
            SendCommand(client, $"/gamerule doweathercycle false");
            SendCommand(client, $"/gamerule showcoordinates true");

            SendCommand(client, $"/gamerule dotiledrops false");
        }
Exemplo n.º 6
0
        private void ExecutePickBlocks(BedrockTraceHandler caller)
        {
            var client = caller.Client;
            int count  = 500;
            int yStart = 100;
            int x      = 0;
            int z      = 0;


            string fileName = Path.GetTempPath() + "pick_items_" + Guid.NewGuid() + ".json";
            var    writer   = File.AppendText(fileName);

            var jsonSerializerSettings = new JsonSerializerSettings
            {
                PreserveReferencesHandling = PreserveReferencesHandling.None,
                Formatting = Formatting.None,
            };

            jsonSerializerSettings.Converters.Add(new NbtIntConverter());
            jsonSerializerSettings.Converters.Add(new NbtStringConverter());

            //BlockPalette palette = client.BlockPalette;
            BlockPalette palette = BlockFactory.BlockPalette;             // only if we have updated it

            _resetEventPlayerHotbar.Reset();

            for (int id = 0; id < count; id++)
            {
                try
                {
                    {
                        var request = new McpeCommandRequest();
                        request.command     = $"/tp TheGrey {x} {150} {z}";
                        request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                        client.SendPacket(request);
                    }

                    var block = BlockFactory.GetBlockById(id);
                    if (block.GetType() == typeof(Block))
                    {
                        continue;
                    }

                    if (block is Cocoa)
                    {
                        continue;                         // crashes on meta=15
                    }
                    int y = yStart;
                    for (int meta = 0; meta <= 15; meta++)
                    {
                        var blockstate = palette.FirstOrDefault(b => b.Id == id && b.Data == meta);
                        if (blockstate == null)
                        {
                            continue;
                        }
                        blockstate.ItemInstance = null;                         // reset to nothing

                        string name = blockstate.Name.Replace("minecraft:", "");
                        if (name == "double_plant" || name == "air" || name.StartsWith("element"))
                        {
                            break;
                        }

                        var pick = McpeBlockPickRequest.CreateObject();
                        pick.x = x;
                        pick.y = y;
                        pick.z = z;
                        client.SendPacket(pick);

                        //Thread.Sleep(100);
                        if (!_resetEventPlayerHotbar.WaitOne(300))
                        {
                            Log.Error($"No picked item for {id}, {meta}, {name}");
                            _lastSelectedItem = new ItemAir();
                            continue;
                            //break;
                        }

                        // Investigate last selected item. This should be the one we picked
                        Item item;
                        lock (_lastSelectedItem)
                        {
                            item = _lastSelectedItem;
                            _lastSelectedItem = new ItemAir();
                        }
                        Log.Warn($"For {id}, {meta} we picked {item}");
                        blockstate.ItemInstance = new ItemPickInstance()
                        {
                            Id       = item.Id,
                            Metadata = item.Metadata,
                            WantNbt  = item.ExtraData != null
                        };
                        string result = JsonConvert.SerializeObject(blockstate, jsonSerializerSettings);
                        writer.WriteLine($"{item}; {result}");
                        writer.Flush();

                        if (blockstate.States.Count == 0)
                        {
                            break;
                        }

                        y += 2;
                    }
                }
                finally
                {
                    x += 2;
                }
            }

            writer.Close();

            WritePaletteToJson(palette);
            Log.Warn("Finished!");
        }
Exemplo n.º 7
0
        private void HandleMcpeUpdateBlock(BedrockTraceHandler caller, McpeUpdateBlock message)
        {
            //if (message.OrderingIndex <= lastNumber) return;
            //lastNumber = message.OrderingIndex;

            if (message.storage != 0)
            {
                return;
            }
            if (message.blockPriority != 3)
            {
                return;
            }

            if (!_runningBlockMetadataDiscovery)
            {
                _resetEventUpdateBlock.Set();
                return;
            }

            int runtimeId = (int)message.blockRuntimeId;
            int bid       = message.coordinates.X / 2;
            int meta      = (message.coordinates.Y - 100) / 2;

            //TODO: Fix for doors and beds. They get 2 updates.
            BlockStateContainer blockstate = caller.Client.BlockPalette[runtimeId];

            if (message.coordinates.X % 2 != 0 || message.coordinates.Y % 2 != 0)
            {
                Log.Warn($"Update block outside of grid {message.coordinates}, {caller.Client.BlockPalette[runtimeId]}");

                if (blockstate.Name.EndsWith("_door"))
                {
                    if (blockstate.States.First(s => s.Name.Equals("upper_block_bit") && ((BlockStateInt)s).Value == 1) != null)
                    {
                        blockstate.Data = (short)meta;
                    }
                }
                else if (blockstate.Name.Equals("minecraft:bed"))
                {
                    if (blockstate.States.First(s => s.Name.Equals("head_piece_bit") && ((BlockStateInt)s).Value == 0) != null)
                    {
                        blockstate.Data = (short)meta;
                    }
                }

                return;
            }

            if (blockstate.Id == 0)
            {
                return;
            }

            if (blockstate.Data == -1)
            {
                lock (_lastUpdatedBlockstate)
                {
                    try
                    {
                        if (bid != blockstate.Id)
                        {
                            Log.Warn($"Wrong id. Expected {blockstate.Id}, got {bid}");
                        }
                        else
                        {
                            blockstate.Data = (short)meta;

                            Log.Debug($"Correct id. Expected {blockstate.Id}, and got {bid}");
                        }

                        Log.Debug($"Block update {bid}, {meta}, with blockstate\n{blockstate}");
                    }
                    finally
                    {
                        Log.Warn($"Got {blockstate.Id}, {meta} storage {message.storage}, {message.blockPriority}");
                        _lastUpdatedBlockstate = blockstate;
                        _resetEventUpdateBlock.Set();
                    }
                }
            }
            else
            {
                Log.Warn($"Blockstate {runtimeId} {blockstate.Id}, {meta} already had meta set to {blockstate.Data}");
            }
        }
Exemplo n.º 8
0
        private void ExecuteAllBlocks(BedrockTraceHandler caller)
        {
            var client = caller.Client;

            if (_runningBlockMetadataDiscovery)
            {
                return;
            }

            client.SendChat("Starting...");

            {
                var request = new McpeCommandRequest();
                request.command     = $"/gamerule dotiledrops false";
                request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                caller.Client.SendPacket(request);
            }

            int x      = 0;
            int yStart = 100;
            int z      = 0;

            int count = 500;

            //for (int t = 0; t < count; t++)
            //{
            //	for (int xd = x - 1; xd <= x + 1; xd++)
            //	{
            //		for (int zd = z - 1; zd <= z + 1; zd++)
            //		{
            //{
            //	var request = new McpeCommandRequest();
            //	request.command = $"/tp TheGrey {xd} {150} {zd}";
            //	request.unknownUuid = new UUID(Guid.NewGuid().ToString());
            //	Client.SendPacket(request);
            //}
            //			for (int yd = yStart - 1; yd < yStart + 34; yd++)
            //			{
            //				//{
            //				//	var request = new McpeCommandRequest();
            //				//	request.command = $"/setblock {xd} {yd} {zd} air 0 replace";
            //				//	request.unknownUuid = new UUID(Guid.NewGuid().ToString());
            //				//	Client.SendPacket(request);
            //_resetEventUpdateBlock.WaitOne();
            //				//}

            //				{
            //					var request = new McpeCommandRequest();
            //					request.command = $"/setblock {xd} {yd} {zd} barrier 0 replace";
            //					request.unknownUuid = new UUID(Guid.NewGuid().ToString());
            //					Client.SendPacket(request);
            //_resetEventUpdateBlock.WaitOne();
            //				}
            //			}
            //		}
            //	}
            //	x += 2;
            //}

            _resetEventUpdateBlock.Reset();
            _resetEventPlayerHotbar.Reset();

            {
                for (int xd = 0; xd <= count * 2; xd++)
                {
                    for (int zd = z; zd <= z; zd++)
                    {
                        if (xd % 10 == 0)
                        {
                            var request = new McpeCommandRequest();
                            request.command     = $"/tp TheGrey {xd} {150} {zd}";
                            request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                            client.SendPacket(request);
                        }

                        for (int yd = yStart; yd < yStart + 33; yd++)
                        {
                            //if (yd != yStart - 1 && yd % 2 != 0)
                            //	continue;
                            //if (yd != yStart - 1 && xd % 2 == 0)
                            //	continue;
                            if (yd % 2 != 0)
                            {
                                continue;
                            }
                            if (xd % 2 != 0)
                            {
                                continue;
                            }

                            {
                                var request = new McpeCommandRequest();
                                request.command     = $"/setblock {xd} {yd} {zd} log 0 replace";
                                request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                                client.SendPacket(request);
                                if (!_resetEventUpdateBlock.WaitOne(1000))
                                {
                                    Log.Warn("wait timeout");
                                }
                            }

                            {
                                var request = new McpeCommandRequest();
                                request.command     = $"/setblock {xd} {yd} {zd} barrier 0 replace";
                                request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                                client.SendPacket(request);
                                if (!_resetEventUpdateBlock.WaitOne(1000))
                                {
                                    Log.Warn("wait timeout");
                                }
                            }
                        }
                    }
                }
            }

            x = 0;
            z = 0;

            {
                var request = new McpeCommandRequest();
                request.command     = $"/tp TheGrey {x} {150} {z}";
                request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                client.SendPacket(request);
            }

            Log.Warn("Staring to run in 1s");
            Thread.Sleep(1000);
            Log.Warn("Running!");

            client.BlockPalette.ForEach(bs => { bs.Data = -1; });
            _runningBlockMetadataDiscovery = true;
            _resetEventUpdateBlock.Reset();
            _resetEventPlayerHotbar.Reset();

            for (int id = 0; id < count; id++)
            {
                try
                {
                    {
                        var request = new McpeCommandRequest();
                        request.command     = $"/tp TheGrey {x} {150} {z}";
                        request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                        client.SendPacket(request);
                    }

                    var block = BlockFactory.GetBlockById(id);
                    if (block.GetType() == typeof(Block))
                    {
                        continue;
                    }

                    if (block is Cocoa)
                    {
                        continue;                         // crashes on meta=15
                    }
                    var    blockstate = client.BlockPalette.FirstOrDefault(b => b.Id == id);
                    string name       = blockstate.Name.Replace("minecraft:", "");

                    if (block is Air)
                    {
                        blockstate.Data = 0;
                        continue;                         // don't want
                    }

                    if (name.StartsWith("element"))
                    {
                        continue;
                    }

                    int y = yStart;
                    for (int meta = 0; meta <= 15; meta++)
                    {
                        Log.Warn($"Setting block {id} {meta} {name}");

                        {
                            var request = new McpeCommandRequest();
                            request.command     = $"/setblock {x} {y} {z} {name} {meta} replace";
                            request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                            client.SendPacket(request);
                        }

                        if (!_resetEventUpdateBlock.WaitOne(500))
                        {
                            {
                                var request = new McpeCommandRequest();
                                request.command     = $"/setblock {x} {y} {z} air 0 replace";
                                request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                                client.SendPacket(request);
                            }
                            //break;
                        }

                        lock (_lastUpdatedBlockstate)
                        {
                            if (_lastUpdatedBlockstate.Id != blockstate.Id)
                            {
                                Log.Warn($"Got wrong ID for blockstate. Expected {blockstate.Id}, got {_lastUpdatedBlockstate.Id}");
                            }

                            var minetBlockstate = GetServerRuntimeId(client.BlockPalette, _internalStates, _lastUpdatedBlockstate.RuntimeId);
                            if (minetBlockstate != null)
                            {
                                if (minetBlockstate.Id != _lastUpdatedBlockstate.Id)
                                {
                                    Log.Warn($"Blockstate BID is different between MiNET and bedrock?");
                                }
                                if (minetBlockstate.Data != _lastUpdatedBlockstate.Data)
                                {
                                    Log.Warn($"Blockstate data is different between MiNET and bedrock? {minetBlockstate}, {_lastUpdatedBlockstate}");
                                }
                            }
                        }

                        if (blockstate.States.Count == 0)
                        {
                            break;
                        }

                        y += 2;
                    }
                }
                finally
                {
                    x += 2;
                }
            }

            client.SendChat($"Finished setting blocks.");
            Log.Warn("Finished!");
        }
Exemplo n.º 9
0
        private void ExecuteDiscoveryOfItemDrops(BedrockTraceHandler caller)
        {
            var client = caller.Client;

            {
                var request = new McpeCommandRequest();
                request.command     = $"/gamerule dotiledrops true";
                request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                client.SendPacket(request);
            }

            int x      = 0;
            int yStart = 100;
            int z      = 0;

            {
                var request = new McpeCommandRequest();
                request.command     = $"/tp TheGrey {x} {150} {z}";
                request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                client.SendPacket(request);
            }

            {
                for (int xd = x - 1; xd <= x + 1; xd++)
                {
                    for (int zd = z - 1; zd <= z + 1; zd++)
                    {
                        for (int yd = yStart - 1; yd < yStart + 34; yd++)
                        {
                            {
                                var request = new McpeCommandRequest();
                                request.command     = $"/setblock {xd} {yd} {zd} glass 0 replace";
                                request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                                client.SendPacket(request);
                            }

                            {
                                var request = new McpeCommandRequest();
                                request.command     = $"/setblock {xd} {yd} {zd} barrier 0 replace";
                                request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                                client.SendPacket(request);
                            }
                        }
                    }
                }
            }

            x = 0;
            z = 0;

            Log.Warn("Running!");
            _resetEventAddItemEntity.Reset();

            int count = 500;
            int y     = yStart;

            for (int id = 1; id < count; id++)
            {
                try
                {
                    var block = BlockFactory.GetBlockById(id);
                    if (block.GetType() == typeof(Block))
                    {
                        continue;
                    }
                    if (block is Cocoa)
                    {
                        continue;                         // crashes on meta=15
                    }
                    var    blockstate = client.BlockPalette.FirstOrDefault(b => b.Id == id);
                    string name       = blockstate.Name.Replace("minecraft:", "");

                    if (name.StartsWith("element"))
                    {
                        continue;
                    }

                    client.BlockPalette.Where(bs => bs.Id == id).ToList().ForEach(bs =>
                    {
                        bs.Data = -1;
                    });

                    {
                        var request = new McpeCommandRequest();
                        request.command     = $"/setblock {x} {y} {z} air 0 replace";
                        request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                        client.SendPacket(request);
                    }

                    Log.Warn($"Setting block {id} {name}");

                    for (int meta = 0; meta <= 15; meta++)
                    {
                        try
                        {
                            Log.Debug($"Setting block {id} {meta} {name}");

                            {
                                var request = new McpeCommandRequest();
                                request.command     = $"/setblock {x} {y} {z} {name} {meta} replace";
                                request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                                client.SendPacket(request);
                            }

                            {
                                var request = new McpeCommandRequest();
                                request.command     = $"/setblock {x} {y} {z} air 0 destroy";
                                request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                                client.SendPacket(request);

                                if (!_resetEventAddItemEntity.WaitOne(1000))
                                {
                                    break;
                                }
                            }
                        }
                        finally
                        {
                            {
                                var request = new McpeCommandRequest();
                                request.command     = $"/kill @e[r=150]";
                                request.unknownUuid = new UUID(Guid.NewGuid().ToString());
                                client.SendPacket(request);
                            }
                        }


                        if (blockstate.States.Count == 0)
                        {
                            break;
                        }
                    }
                }
                finally
                {
                }
            }

            client.SendChat($"Finished setting blocks.");
            Log.Warn("Finished!");
        }
Exemplo n.º 10
0
        private void ExecuteDiscoveryOfItemDrops(BedrockTraceHandler caller)
        {
            var client = caller.Client;

            {
                SendCommand(client, $"/gamerule dotiledrops true");
            }

            int x      = 0;
            int yStart = 100;
            int z      = 0;

            {
                SendCommand(client, $"/tp TheGrey {x} {150} {z}");
            }

            {
                for (int xd = x - 1; xd <= x + 1; xd++)
                {
                    for (int zd = z - 1; zd <= z + 1; zd++)
                    {
                        for (int yd = yStart - 1; yd < yStart + 34; yd++)
                        {
                            {
                                SendCommand(client, $"/setblock {xd} {yd} {zd} glass 0 replace");
                            }

                            {
                                SendCommand(client, $"/setblock {xd} {yd} {zd} barrier 0 replace");
                            }
                        }
                    }
                }
            }

            x = 0;
            z = 0;

            Log.Warn("Running!");
            _resetEventAddItemEntity.Reset();

            int count = 600;
            int y     = yStart;

            for (int id = 1; id < count; id++)
            {
                try
                {
                    var    blockstate = client.BlockPalette.FirstOrDefault(b => b.Id == id);
                    string name       = blockstate.Name.Replace("minecraft:", "");

                    //if (name.StartsWith("element")) continue;

                    client.BlockPalette.Where(bs => bs.Id == id).ToList().ForEach(bs =>
                    {
                        bs.Data = -1;
                    });

                    {
                        SendCommand(client, $"/setblock {x} {y} {z} air 0 replace");
                    }

                    Log.Warn($"Setting block {id} {name}");

                    for (int meta = 0; meta <= 15; meta++)
                    {
                        try
                        {
                            Log.Debug($"Setting block {id} {meta} {name}");

                            {
                                SendCommand(client, $"/setblock {x} {y} {z} {name} {meta} replace");
                            }

                            {
                                SendCommand(client, $"/setblock {x} {y} {z} air 0 destroy");

                                if (!_resetEventAddItemEntity.WaitOne(1000))
                                {
                                    break;
                                }
                            }
                        }
                        finally
                        {
                            {
                                SendCommand(client, $"/kill @e[r=150]");
                            }
                        }


                        if (blockstate.States.Count == 0)
                        {
                            break;
                        }
                    }
                }
                finally
                {
                }
            }

            client.SendChat($"Finished setting blocks.");
            Log.Warn("Finished!");
        }
Exemplo n.º 11
0
        private void ExecuteAllBlocks(BedrockTraceHandler caller)
        {
            var client = caller.Client;

            if (_runningBlockMetadataDiscovery)
            {
                return;
            }

            client.SendChat("Starting...");

            SetGameRules(caller);
            int count = 600;

            void Report(string message)
            {
                Log.Warn(message);
                client.SendChat(message);
            }

            var width = (int)MathF.Ceiling(MathF.Sqrt(count));
            var depth = (int)MathF.Ceiling((float)count / width);


            const int yStart = 100;

            _blockCoordinates.Clear();
            var prevProgress = -1d;

            for (int bx = -width; bx < width; bx += 2)
            {
                if (_blockCoordinates.Count >= count)
                {
                    break;
                }

                for (int bz = -depth; bz < depth; bz += 2)
                {
                    if (_blockCoordinates.Count >= count)
                    {
                        break;
                    }

                    if (bx % 10 == 0)
                    {
                        SendCommand(client, $"/tp TheGrey {bx} {(yStart + 50)} {bz}");
                    }

                    _blockCoordinates.Add(new BlockCoordinates(bx, 0, bz));

                    for (int yd = yStart; yd < yStart + 33; yd++)
                    {
                        SendCommand(client, $"/setblock {bx} {yd} {bz} log 0 replace");
                        //if (!_resetEventUpdateBlock.WaitOne(250)) Log.Warn("wait timeout");

                        SendCommand(client, $"/setblock {bx} {yd} {bz} barrier 0 replace");
                        //if (!_resetEventUpdateBlock.WaitOne(250)) Log.Warn("wait timeout");

                        for (int xd = bx - 1; xd <= bx + 1; xd++)
                        {
                            for (int zd = bz - 1; zd <= bz + 1; zd++)
                            {
                                SendCommand(client, $"/setblock {xd} {yd} {zd} air 0 replace");
                                SendCommand(client, $"/setblock {xd} {yd} {zd} barrier 0 replace");
                            }
                        }
                    }

                    //if (bx % 2 == 0 && bz % 2 == 0)
                    {
                        var progress = ((double)_blockCoordinates.Count / (count)) * 100d;

                        if ((int)progress > prevProgress)
                        {
                            Report($"Prep Progress: {(int)progress}%");
                            prevProgress = progress;
                        }
                    }
                }
            }

            prevProgress = -1;
            _resetEventUpdateBlock.Reset();
            _resetEventPlayerHotbar.Reset();

            var cQueue = new Queue <BlockCoordinates>(_blockCoordinates);

            SendCommand(client, $"/tp TheGrey 0 150 0");

            Report("Staring to run in 1s");
            Thread.Sleep(1000);
            Report("Running!");

            //	client.BlockPalette = BlockFactory.BlockPalette;
            client.BlockPalette.ForEach(bs => { bs.Data = -1; });
            _runningBlockMetadataDiscovery = true;
            _resetEventUpdateBlock.Reset();
            _resetEventPlayerHotbar.Reset();

            for (int id = 0; id < count; id++)
            {
                var progress = ((double)id / (count)) * 100d;

                if ((int)progress > prevProgress)
                {
                    Report($"Place Progress: {(int)progress}%");
                    prevProgress = progress;
                }

                var c = cQueue.Dequeue();
                try
                {
                    SendCommand(client, $"/tp TheGrey {c.X} {150} {c.Z}");

                    //var block = BlockFactory.GetBlockById(id);
                    //if (block.GetType() == typeof(Block))
                    //{
                    //	continue;
                    //}

                    var blockstate = client.BlockPalette.FirstOrDefault(b => b.Id == id);
                    if (blockstate == null)
                    {
                        continue;
                    }

                    string name = blockstate.Name.Replace("minecraft:", "");

                    if ("air".Equals(name))
                    {
                        blockstate.Data = 0;
                        continue;                         // don't want
                    }

                    //if (name.StartsWith("element")) continue;

                    int y = yStart;
                    for (int meta = 0; meta <= 15; meta++)
                    {
                        //	Log.Warn($"Setting block {id} {meta} {name}");

                        SendCommand(client, $"/setblock {c.X} {y} {c.Z} {name} {meta} replace");

                        if (!_resetEventUpdateBlock.WaitOne(500))
                        {
                            SendCommand(client, $"/setblock {c.X} {y} {c.Z} air 0 replace");
                            //break;
                        }

                        lock (_lastUpdatedBlockstate)
                        {
                            if (_lastUpdatedBlockstate.Id != blockstate.Id)
                            {
                                Log.Warn($"Got wrong ID for blockstate. Expected {blockstate.Id}, got {_lastUpdatedBlockstate.Id} (Expected: {blockstate.Name} Got: {_lastUpdatedBlockstate.Name})");
                            }

                            var minetBlockstate = GetServerRuntimeId(client.BlockPalette, _internalStates, _lastUpdatedBlockstate.RuntimeId);
                            if (minetBlockstate != null)
                            {
                                if (minetBlockstate.Id != _lastUpdatedBlockstate.Id)
                                {
                                    Log.Warn($"Blockstate BID is different between MiNET and bedrock?");
                                }
                                if (minetBlockstate.Data != _lastUpdatedBlockstate.Data)
                                {
                                    Log.Warn($"Blockstate data is different between MiNET and bedrock? {minetBlockstate}, {_lastUpdatedBlockstate}");
                                }
                            }
                        }

                        if (blockstate.States.Count == 0)
                        {
                            break;
                        }

                        y += 2;
                    }
                }
                finally
                {
                    //x += 2;
                }
            }

            _runningBlockMetadataDiscovery = false;

            WritePaletteToJson(client.BlockPalette);

            Report($"Finished setting blocks.");
        }
Exemplo n.º 12
0
        private void DiscoverItems(BedrockTraceHandler caller)
        {
            var client = caller.Client;

            client.SendChat("Starting item discovery...");

            ClearInventory(caller);

            Dictionary <string, short> idMapping = new Dictionary <string, short>();

            //for(int i = -400; i < 900; i++)
            {
                //	for (short meta = 0; meta < 15; meta++)
                {
                    foreach (var itemType in typeof(Item).Assembly.GetTypes().Where(x => typeof(Item).IsAssignableFrom(x)))
                    {
                        try
                        {
                            var item = Activator.CreateInstance(itemType) as Item;

                            if (item == null || string.IsNullOrWhiteSpace(item?.Name) || item is ItemAir)
                            {
                                continue;
                            }

                            string itemName = item.Name;

                            if (ItemFactory.Translator.TryGetName(itemName, out var newName))
                            {
                                Log.Warn($"Name mistmatch for item: {item} (Current={item.Name} New={newName})");
                                itemName = newName;
                            }

                            if (idMapping.ContainsKey(item.Name))
                            {
                                continue;
                            }

                            ClearInventory(caller);
                            SendCommand(client, $"/give TheGrey {itemName}");

                            if (!_resetEventInventorySlot.WaitOne(500))
                            {
                                Log.Warn($"Failed to get item: {itemName}");

                                continue;
                            }

                            lock (_lastItem)
                            {
                                var newItem = _lastItem;

                                if (newItem != null && (newItem is not ItemAir && newItem.Count > 0))
                                {
                                    if (!idMapping.TryAdd(item.Name, newItem.Id))
                                    {
                                        Log.Warn($"Duplicate key! Name={item.Name} Id={item.Id} NewName={newItem.Name} NewId={newItem.Id}");
                                    }
                                }

                                _lastItem = new ItemAir()
                                {
                                    Count = 0
                                };
                            }
                        }catch {}
                    }
                }
            }

            client.SendChat($"Finished item discovery...");
            var fileNameItemstates = Path.GetTempPath() + "itemdiscovery_" + Guid.NewGuid() + ".json";

            /*File.WriteAllText(fileNameItemstates, JsonConvert.SerializeObject(items.Distinct(new ItemEqualityComparer()).Select(x => new
             * {
             *      Name = x.Name,
             *      Id = x.Id
             * }).ToArray(), Formatting.Indented));*/

            File.WriteAllText(fileNameItemstates, JsonConvert.SerializeObject(idMapping, Formatting.Indented));
        }
Exemplo n.º 13
0
        private void ClearInventory(BedrockTraceHandler caller)
        {
            var client = caller.Client;

            SendCommand(client, $"/clear TheGrey");
        }