public void ToggleDownfall(Player player) { ThreadPool.QueueUserWorkItem(delegate(object state) { for (int i = 0; i < short.MaxValue; i = i+2000) { var data = i; { McpeLevelEvent levelEvent = new McpeLevelEvent(); levelEvent.eventId = 3001; levelEvent.data = data; player.SendPackage(levelEvent); } //{ // McpeLevelEvent levelEvent = new McpeLevelEvent(); // levelEvent.eventId = 3002; // levelEvent.data = i; // player.SendPackage(levelEvent); //} player.SendMessage("Downfall " + data, type: MessageType.Raw); Thread.Sleep(5000); } for (int i = short.MaxValue; i >= 0; i = i - 2000) { { McpeLevelEvent levelEvent = new McpeLevelEvent(); levelEvent.eventId = 3001; levelEvent.data = i; player.SendPackage(levelEvent); } //{ // McpeLevelEvent levelEvent = new McpeLevelEvent(); // levelEvent.eventId = 3002; // levelEvent.data = i; // player.SendPackage(levelEvent); //} player.SendMessage("Downfall " + i, type: MessageType.Raw); Thread.Sleep(5000); } }); //{ // McpeLevelEvent levelEvent = new McpeLevelEvent(); // levelEvent.eventId = 3001; // levelEvent.data = 100000; // player.SendPackage(levelEvent); //} //{ // McpeLevelEvent levelEvent = new McpeLevelEvent(); // levelEvent.eventId = 3002; // levelEvent.data = 36625; // player.SendPackage(levelEvent); //} player.SendMessage("Toggled downfall", type: MessageType.Raw); }
public void ChangeDimension(Player player) { McpeChangeDimension change = McpeChangeDimension.CreateObject(); change.dimension = 1; change.unknown = 0; player.SendPackage(change); }
public void ToggleDownfall(Player player, int value) { { McpeLevelEvent levelEvent = new McpeLevelEvent(); levelEvent.eventId = 3001; levelEvent.data = value; player.SendPackage(levelEvent); } player.SendMessage("Downfall " + value, type: MessageType.Raw); }
public void GameMode(Player player, int gameMode) { player.SendPackage(new McpeStartGame { seed = -1, generator = 1, gamemode = gameMode, entityId = player.EntityId, spawnX = player.Level.SpawnPoint.X, spawnY = player.Level.SpawnPoint.Y, spawnZ = player.Level.SpawnPoint.Z, x = player.KnownPosition.X, y = player.KnownPosition.Y, z = player.KnownPosition.Z }); }
public override void AddPlayer(Player newPlayer, string broadcastText = null, bool spawn = true) { base.AddPlayer(newPlayer, broadcastText, false); Mob entity = new Mob(new Random().Next(10, 16), this) // Passive mobs //Mob entity = new Mob(new Random().Next(32, 39), this) // Hostile mobs { KnownPosition = newPlayer.KnownPosition, //Data = -(blockId | 0 << 0x10) }; entity.SpawnEntity(); // Despawn the new entity from the player himeself newPlayer.SendPackage(new McpeRemoveEntity() { entityId = entity.EntityId, }); _playerEntities.Add(newPlayer, entity); }
public void SendSetSlot(int slot) { if (slot < HotbarSize && (ItemHotbar[slot] == -1 || ItemHotbar[slot] == slot)) { ItemHotbar[slot] = slot /* + HotbarSize*/; Player.SendPlayerInventory(); McpeMobEquipment order = McpeMobEquipment.CreateObject(); order.entityId = 0; order.item = GetItemInHand(); order.selectedSlot = (byte)slot; // Selected hotbar slot Player.SendPackage(order); } else { McpeContainerSetSlot sendSlot = McpeContainerSetSlot.CreateObject(); sendSlot.windowId = 0; sendSlot.slot = (short)slot; sendSlot.item = Slots[slot]; Player.SendPackage(sendSlot); } }
public void SetHeldItemSlot(int selectedHotbarSlot, bool sendToPlayer = true) { InHandSlot = selectedHotbarSlot; if (sendToPlayer) { McpeMobEquipment order = McpeMobEquipment.CreateObject(); order.entityId = 0; order.item = GetItemInHand(); order.selectedSlot = (byte)selectedHotbarSlot; order.slot = (byte)ItemHotbar[InHandSlot]; Player.SendPackage(order); } McpeMobEquipment broadcast = McpeMobEquipment.CreateObject(); broadcast.entityId = Player.EntityId; broadcast.item = GetItemInHand(); broadcast.selectedSlot = (byte)selectedHotbarSlot; broadcast.slot = (byte)ItemHotbar[InHandSlot]; Player.Level?.RelayBroadcast(Player, broadcast); }
public virtual void SetHeldItemSlot(int selectedHotbarSlot, bool sendToPlayer = true) { InHandSlot = selectedHotbarSlot; if (sendToPlayer) { McpeMobEquipment order = McpeMobEquipment.CreateObject(); order.runtimeEntityId = EntityManager.EntityIdSelf; order.item = GetItemInHand(); order.selectedSlot = (byte)InHandSlot; order.slot = (byte)(InHandSlot + HotbarSize); Player.SendPackage(order); } McpeMobEquipment broadcast = McpeMobEquipment.CreateObject(); broadcast.runtimeEntityId = Player.EntityId; broadcast.item = GetItemInHand(); broadcast.selectedSlot = (byte)InHandSlot; broadcast.slot = (byte)(InHandSlot + HotbarSize); Player.Level?.RelayBroadcast(Player, broadcast); }
public void SendSetSlot(int slot) { if (slot < 0 || slot > Slots.Length - 1) { return; } McpeInventorySlot ssendSlot = McpeInventorySlot.CreateObject(); ssendSlot.inventoryId = 0; ssendSlot.slot = slot; ssendSlot.item = Slots[slot]; Player.SendPackage(ssendSlot); return; if (slot < HotbarSize /* && (ItemHotbar[slot] == -1 || ItemHotbar[slot] == slot)*/) { // ItemHotbar[slot] = slot; //Player.SendPlayerInventory(); McpeMobEquipment order = McpeMobEquipment.CreateObject(); order.runtimeEntityId = EntityManager.EntityIdSelf; order.item = Slots[slot]; order.slot = (byte)slot; order.selectedSlot = (byte)(slot); // Selected hotbar slot Player.SendPackage(order); } else { McpeInventorySlot sendSlot = McpeInventorySlot.CreateObject(); sendSlot.inventoryId = 0; sendSlot.slot = slot; sendSlot.item = Slots[slot]; Player.SendPackage(sendSlot); } }
public virtual void SendHungerAttributes() { var attributes = new PlayerAttributes(); attributes["player.hunger"] = new PlayerAttribute { Name = "player.hunger", MinValue = MinHunger, MaxValue = MaxHunger, Value = Hunger }; attributes["player.saturation"] = new PlayerAttribute { Name = "player.saturation", MinValue = 0, MaxValue = Hunger, Value = (float)Saturation }; attributes["player.exhaustion"] = new PlayerAttribute { Name = "player.exhaustion", MinValue = 0, MaxValue = 5, Value = (float)Exhaustion }; McpeUpdateAttributes attributesPackate = McpeUpdateAttributes.CreateObject(); attributesPackate.entityId = 0; attributesPackate.attributes = attributes; Player.SendPackage(attributesPackate); }
public void Hide(Player player, byte id) { Level level = player.Level; level.HidePlayer(player, true); Mob entity = new Mob(id, level) { KnownPosition = player.KnownPosition, //Data = -(blockId | 0 << 0x10) }; entity.SpawnEntity(); player.SendPackage(new McpeRemoveEntity() { entityId = entity.EntityId, }); _playerEntities[player] = entity; level.BroadcastTextMessage(string.Format("Player {0} spawned as other entity.", player.Username)); }
public void Kit(Player player, int kitId) { var armor = player.Inventory.Armor; var slots = player.Inventory.Slots; switch (kitId) { case 0: // Kit leather tier armor[0] = new MetadataSlot(new ItemStack(298)); // Helmet armor[1] = new MetadataSlot(new ItemStack(299)); // Chest armor[2] = new MetadataSlot(new ItemStack(300)); // Leggings armor[3] = new MetadataSlot(new ItemStack(301)); // Boots break; case 1: // Kit gold tier armor[0] = new MetadataSlot(new ItemStack(314)); // Helmet armor[1] = new MetadataSlot(new ItemStack(315)); // Chest armor[2] = new MetadataSlot(new ItemStack(316)); // Leggings armor[3] = new MetadataSlot(new ItemStack(317)); // Boots break; case 2: // Kit chain tier armor[0] = new MetadataSlot(new ItemStack(302)); // Helmet armor[1] = new MetadataSlot(new ItemStack(303)); // Chest armor[2] = new MetadataSlot(new ItemStack(304)); // Leggings armor[3] = new MetadataSlot(new ItemStack(305)); // Boots break; case 3: // Kit iron tier armor[0] = new MetadataSlot(new ItemStack(306)); // Helmet armor[1] = new MetadataSlot(new ItemStack(307)); // Chest armor[2] = new MetadataSlot(new ItemStack(308)); // Leggings armor[3] = new MetadataSlot(new ItemStack(309)); // Boots break; case 4: // Kit diamond tier armor[0] = new MetadataSlot(new ItemStack(310)); // Helmet armor[1] = new MetadataSlot(new ItemStack(311)); // Chest armor[2] = new MetadataSlot(new ItemStack(312)); // Leggings armor[3] = new MetadataSlot(new ItemStack(313)); // Boots break; } byte c = 0; slots[c++] = new MetadataSlot(new ItemStack(268, 1)); // Wooden Sword slots[c++] = new MetadataSlot(new ItemStack(283, 1)); // Golden Sword slots[c++] = new MetadataSlot(new ItemStack(272, 1)); // Stone Sword slots[c++] = new MetadataSlot(new ItemStack(267, 1)); // Iron Sword slots[c++] = new MetadataSlot(new ItemStack(276, 1)); // Diamond Sword slots[c++] = new MetadataSlot(new ItemStack(261, 1)); // Bow slots[c++] = new MetadataSlot(new ItemStack(262, 64)); // Arrows slots[c++] = new MetadataSlot(new ItemStack(344, 64)); // Eggs slots[c++] = new MetadataSlot(new ItemStack(332, 64)); // Snowballs player.SendPackage(new McpeContainerSetContent { windowId = 0, slotData = player.Inventory.Slots, hotbarData = player.Inventory.ItemHotbar }); player.SendPackage(new McpeContainerSetContent { windowId = 0x78, // Armor windows ID slotData = player.Inventory.Armor, hotbarData = null }); SendEquipmentForPlayer(player); SendArmorForPlayer(player); player.Level.BroadcastTextMessage(string.Format("Player {0} changed kit.", player.Username), type: MessageType.Raw); }
public void GameMode(Player player, int gameMode) { player.GameMode = (GameMode) gameMode; player.SendPackage(new McpeStartGame { seed = -1, generator = 1, gamemode = gameMode, entityId = player.EntityId, spawnX = player.Level.SpawnPoint.X, spawnY = player.Level.SpawnPoint.Y, spawnZ = player.Level.SpawnPoint.Z, x = player.KnownPosition.X, y = player.KnownPosition.Y, z = player.KnownPosition.Z }); player.Level.BroadcastTextMessage(string.Format("{0} changed to game mode {1}.", player.Username, gameMode), type: MessageType.Raw); }
public void Fly(Player player) { player.SendPackage(new McpeAdventureSettings {flags = 0x80}); player.Level.BroadcastTextMessage(string.Format("Player {0} enabled flying.", player.Username), type: MessageType.Raw); }
public void Effect(Player player, int effectId, int amplifier = 1, int duration = 20) { player.SendPackage(new McpeMobEffect { entityId = player.EntityId, eventId = 1, // Add effectId = (byte) effectId, duration = 20*duration, amplifier = (byte) amplifier, particles = 0, }); player.Level.BroadcastTextMessage(string.Format("{0} added effect {1} with strenght {2}", player.Username, effectId, amplifier), type: MessageType.Raw); }
private void DelayedProcessing(PlayerNetworkSession playerSession, ConnectedPackage package) { Player player = playerSession.Player; if (ForwardAllPlayers) { player.SendPackage(new McpeTransfer { endpoint = ForwardTarget }, true); return; } List <Package> messages = package.Messages; foreach (var message in messages) { message.DatagramSequenceNumber = package._datagramSequenceNumber; message.OrderingChannel = package._orderingChannel; message.OrderingIndex = package._orderingIndex; if (message is SplitPartPackage) { message.Source = "Receive SplitPartPackage"; SplitPartPackage splitMessage = message as SplitPartPackage; int spId = package._splitPacketId; int spIdx = package._splitPacketIndex; int spCount = package._splitPacketCount; if (!playerSession.Splits.ContainsKey(spId)) { playerSession.Splits.Add(spId, new SplitPartPackage[spCount]); } SplitPartPackage[] spPackets = playerSession.Splits[spId]; spPackets[spIdx] = splitMessage; bool haveEmpty = false; for (int i = 0; i < spPackets.Length; i++) { haveEmpty = haveEmpty || spPackets[i] == null; } if (!haveEmpty) { Log.DebugFormat("Got all {0} split packages for split ID: {1}", spCount, spId); MemoryStream stream = new MemoryStream(); for (int i = 0; i < spPackets.Length; i++) { SplitPartPackage splitPartPackage = spPackets[i]; byte[] buf = splitPartPackage.Message; stream.Write(buf, 0, buf.Length); splitPartPackage.PutPool(); } playerSession.Splits.Remove(spId); byte[] buffer = stream.ToArray(); try { Package fullMessage = PackageFactory.CreatePackage(buffer[0], buffer) ?? new UnknownPackage(buffer[0], buffer); fullMessage.DatagramSequenceNumber = package._datagramSequenceNumber; fullMessage.OrderingChannel = package._orderingChannel; fullMessage.OrderingIndex = package._orderingIndex; HandlePackage(fullMessage, playerSession); fullMessage.PutPool(); } catch (Exception e) { player.Disconnect("Bad package received from client."); } } continue; } message.Timer.Restart(); HandlePackage(message, playerSession); message.PutPool(); // Handled in HandlePacket now() } }
public void Hide(Player player, string type) { EntityType mobType; try { mobType = (EntityType) Enum.Parse(typeof (EntityType), type, true); } catch (ArgumentException e) { return; } Level level = player.Level; HidePlayer(player, true); Mob entity = new Mob(mobType, level) { KnownPosition = player.KnownPosition, HealthManager = player.HealthManager, NameTag = player.NameTag, }; entity.SpawnEntity(); var remove = McpeRemoveEntity.CreateObject(); remove.entityId = entity.EntityId; player.SendPackage(remove); _playerEntities[player] = entity; level.BroadcastMessage($"Player {player.Username} spawned as {mobType}.", type: MessageType.Raw); }
public void GameMode(Player player, int gameMode) { if (gameMode == 1) { player.Inventory.Slots.Clear(); player.Inventory.Slots.AddRange(InventoryUtils.CreativeInventoryItems); } //player.GameMode = (GameMode) gameMode; player.SendPackage(new McpeStartGame { seed = -1, generator = 1, gamemode = gameMode, entityId = player.EntityId, spawnX = (int)player.Level.SpawnPoint.X, spawnY = (int)player.Level.SpawnPoint.Y, spawnZ = (int)player.Level.SpawnPoint.Z, x = player.KnownPosition.X, y = player.KnownPosition.Y, z = player.KnownPosition.Z }); { McpeContainerSetContent creativeContent = McpeContainerSetContent.CreateObject(); creativeContent.windowId = (byte)0x79; creativeContent.slotData = player.Inventory.GetSlots(); creativeContent.hotbarData = player.Inventory.GetHotbar(); player.SendPackage(creativeContent); } player.Level.BroadcastMessage(string.Format("{0} changed to game mode {1}.", player.Username, gameMode), type: MessageType.Raw); }
public Package RespawnHandler(McpeRespawn packet, Player player) { McpeMobEffect speedEffect = McpeMobEffect.CreateObject(); speedEffect.entityId = 0; speedEffect.eventId = 1; speedEffect.effectId = 1; speedEffect.duration = 0x7fffffff; speedEffect.amplifier = 2; speedEffect.particles = 1; player.SendPackage(speedEffect); McpeMobEffect jumpEffect = McpeMobEffect.CreateObject(); jumpEffect.entityId = 0; jumpEffect.eventId = 1; jumpEffect.effectId = 8; jumpEffect.duration = 0x7fffffff; jumpEffect.amplifier = 2; jumpEffect.particles = 1; player.SendPackage(jumpEffect); if (player.Level.LevelId.Equals("Default")) { player.Level.CurrentWorldTime = 10000; player.Level.IsWorldTimeStarted = false; } player.SendSetTime(); return packet; }