public static void Main() { /* //Yaml.Node n = Yaml.Node.FromFile("minecraft.yaml"); //Console.WriteLine(n); //Console.ReadLine(); YamlMapping ns = (YamlMapping)YamlNode.FromYamlFile("minecraft.yaml")[0]; outputNode(ns); YamlSequence m; YamlNode n; ns.TryGetValue("blocks", out n); m = (YamlSequence)n; foreach(YamlNode i in m) foreach (YamlNode ii in ((YamlMapping)i).Values) Console.WriteLine(ii.Tag); Console.ReadLine(); return;*/ Thread renderThread = new Thread(() => { t.Go(); }); Client mc = t.mc; renderThread.Start(); mc.packetReceived += t.packetHandler; wl("Welcome to SharpMCLibrary"); w("Please enter a name:"); mc.name = Console.ReadLine(); mc.output2 = writeDebug; //mc.connect("127.0.0.1", 25564); //SMPROXY //mc.connect("127.0.0.1", 25565); //LOCAL mc.connect("192.168.0.119", 25565); //LOCAL //mc.connect("37.59.228.108", 25565); //mcags.com string tmp = ""; while (!(tmp == "/exit" || tmp == "/quit")) { tmp = Console.ReadLine(); if (tmp.StartsWith("/")) { if (tmp == "/respawn") { Packet_Respawn r = new Packet_Respawn(); r.Dimension = 0; r.Difficulty = 1; r.Gamemode = 0; r.LevelType = "default"; r.WorldHeight = 256; mc.sendPacket(r); } }else{ mc.sendPacket(new Packet_Chat() { Message=tmp}); } } mc.disconnect(); }
public void packetHandler(object sender,Client.packetReceivedEventArgs e) { switch (e.ID) { case 0x0D: Packet_PlayerPosAndLook p = (Packet_PlayerPosAndLook)e.packet; moveCamera((float)p.x, (float)p.y+3f, (float)p.z); break; case 8: Packet_UpdateHealth h = (Packet_UpdateHealth)e.packet; Console.WriteLine("Health Update: {0} {1}", h.health, h.food); if (h.health <= 0) { Packet_Respawn r = new Packet_Respawn(); r.dim = 0; r.difficulty = 1; r.creative = 0; r.levelType = "default"; r.worldHeight = 256; mc.sendPacket(r); } break; case 0x32: Packet_PreChunk c = (Packet_PreChunk)e.packet; if (c.mode) { if (!chunks.ContainsKey(c.x + "_" + c.z)) chunks.Add(c.x + "_" + c.z, new Chunk()); } else if (chunks.ContainsKey(c.x + "_" + c.z)) chunks.Remove(c.x + "_" + c.z); break; case 0x33: Packet_MapChunk mch = (Packet_MapChunk)e.packet; int cx, cz; cx = mch.x; cz = mch.z; string key = cx + "_" + cz; //output("Chunk: " + key, true); if (!chunks.ContainsKey(key)) { chunks.Add(key, new Chunk()); //output("Chunk had to be added! " + key, true); } chunks[key].update(mch); QueueChunk(chunks[key]); break; case 0x34: Packet_MultiBlockChange mb = (Packet_MultiBlockChange)e.packet; chunks[mb.x + "_" + mb.z].update(mb); QueueChunk(chunks[mb.x + "_" + mb.z]); break; } }
public void packetHandler(object sender,Client.packetReceivedEventArgs e) { switch ((byte)e.Type) { case 0x0D: Packet_PlayerPosAndLook p = (Packet_PlayerPosAndLook)e.packet; moveCamera((float)p.X, (float)p.Y+3f, (float)p.Z); break; case 8: Packet_UpdateHealth h = (Packet_UpdateHealth)e.packet; Console.WriteLine("Health Update: {0} {1}", h.Health, h.Food); if (h.Health <= 0) { Packet_Respawn r = new Packet_Respawn(); r.Dimension = 0; r.Difficulty = 1; r.Gamemode = 0; r.LevelType = "default"; r.WorldHeight = 256; mc.sendPacket(r); } break; /* case 0x32: Packet_PreChunk c = (Packet_PreChunk)e.packet; if (c.Mode) { if (!chunks.ContainsKey(c.X + "_" + c.Z)) chunks.Add(c.X + "_" + c.Z, new Chunk()); } else if (chunks.ContainsKey(c.X + "_" + c.Z)) chunks.Remove(c.X + "_" + c.Z); break; */ case 0x33: Packet_MapChunk mch = (Packet_MapChunk)e.packet; int cx, cz; cx = mch.X; cz = mch.Z; string key = cx + "_" + cz; //output("Chunk: " + key, true); if (!chunks.ContainsKey(key)) { chunks.Add(key, new Chunk()); //output("Chunk had to be added! " + key, true); } chunks[key].update(mch); QueueChunk(chunks[key]); break; case 0x34: Packet_MultiBlockChange mb = (Packet_MultiBlockChange)e.packet; chunks[mb.X + "_" + mb.Z].update(mb); QueueChunk(chunks[mb.X + "_" + mb.Z]); break; } }