public void SendCraftingEvent() { var recipe = _recipeToSend; if (recipe != null) { { McpeContainerSetSlot setSlot = new McpeContainerSetSlot(); setSlot.item = new MetadataSlot(new ItemStack(new ItemBlock(new Block(17), 0), 1)); setSlot.windowId = 0; setSlot.slot = 0; SendPackage(setSlot); } { McpePlayerEquipment eq = new McpePlayerEquipment(); eq.entityId = _entityId; eq.slot = 9; eq.selectedSlot = 0; eq.item = new MetadataSlot(new ItemStack(new ItemBlock(new Block(17), 0), 1)); SendPackage(eq); } Log.Error("Sending crafting event: " + recipe.Id); McpeCraftingEvent crafting = new McpeCraftingEvent(); crafting.windowId = 0; crafting.recipeType = 1; crafting.recipeId = recipe.Id; { MetadataSlots slotData = new MetadataSlots(); slotData[0] = new MetadataSlot(new ItemStack(new ItemBlock(new Block(17), 0), 1)); crafting.input = slotData; } { MetadataSlots slotData = new MetadataSlots(); slotData[0] = new MetadataSlot(new ItemStack(new ItemBlock(new Block(5), 0), 4)); crafting.result = slotData; } SendPackage(crafting); //{ // McpeContainerSetSlot setSlot = new McpeContainerSetSlot(); // setSlot.item = new MetadataSlot(new ItemStack(new ItemBlock(new Block(5), 0), 4)); // setSlot.windowId = 0; // setSlot.slot = 0; // SendPackage(setSlot); //} { McpePlayerEquipment eq = new McpePlayerEquipment(); eq.entityId = _entityId; eq.slot = 10; eq.selectedSlot = 1; eq.item = new MetadataSlot(new ItemStack(new ItemBlock(new Block(5), 0), 4)); SendPackage(eq); } } }
public override void SpawnToPlayer(Player player) { { McpeAddPlayer message = McpeAddPlayer.CreateObject(); message.clientId = EntityId; message.username = NameTag ?? Name; message.entityId = EntityId; message.x = KnownPosition.X; message.y = KnownPosition.Y; message.z = KnownPosition.Z; message.yaw = KnownPosition.Yaw; message.headYaw = KnownPosition.HeadYaw; message.pitch = KnownPosition.Pitch; message.skin = Skin; message.metadata = GetMetadata().GetBytes(); player.SendPackage(message); } { McpePlayerEquipment message = McpePlayerEquipment.CreateObject(); message.entityId = EntityId; message.item = ItemInHand.Id; message.meta = ItemInHand.Metadata; message.slot = 0; player.SendPackage(message); } { McpePlayerArmorEquipment message = McpePlayerArmorEquipment.CreateObject(); message.entityId = EntityId; message.helmet = (byte)(Helmet - 256); message.chestplate = (byte)(Chest - 256); message.leggings = (byte)(Leggings - 256); message.boots = (byte)(Boots - 256); player.SendPackage(message); } }
private void SendEquipmentForPlayer(Player player) { var msg = McpePlayerEquipment.CreateObject(); msg.entityId = player.EntityId; msg.item = player.Inventory.GetItemInHand(); msg.slot = 0; player.Level.RelayBroadcast(msg); }
protected virtual void SendEquipment() { McpePlayerEquipment message = McpePlayerEquipment.CreateObject(); message.entityId = EntityId; message.item = ItemInHand; message.slot = 0; Level.RelayBroadcast(message); }
public void SendEquipmentForPlayer(Player receiver, Player player) { McpePlayerEquipment mcpePlayerEquipment = McpePlayerEquipment.CreateObject(); mcpePlayerEquipment.entityId = player.EntityId; mcpePlayerEquipment.item = new MetadataSlot(player.Inventory.GetItemInHand()); mcpePlayerEquipment.slot = 0; receiver.SendPackage(mcpePlayerEquipment); }
public void SetHeldItemSlotNoSend(int slot) { InHandSlot = slot; McpePlayerEquipment broadcast = McpePlayerEquipment.CreateObject(); broadcast.entityId = Player.EntityId; broadcast.item = GetItemInHand(); broadcast.selectedSlot = (byte)slot; Player.Level?.RelayBroadcast(broadcast); }
public void SetHeldItemSlot(int slot) { McpePlayerEquipment order = McpePlayerEquipment.CreateObject(); order.entityId = 0; order.selectedSlot = (byte)slot; Player.SendPackage(order); McpePlayerEquipment broadcast = McpePlayerEquipment.CreateObject(); broadcast.entityId = Player.EntityId; broadcast.selectedSlot = (byte)slot; Player.Level.RelayBroadcast(broadcast); }
public override void SpawnToPlayer(Player player) { { Player fake = new Player(null, null, 0) { ClientUuid = Uuid, EntityId = EntityId, NameTag = NameTag ?? Name, Skin = Skin }; McpePlayerList playerList = McpePlayerList.CreateObject(); playerList.records = new PlayerAddRecords { fake }; player.SendPackage(playerList); //player.SendDirectPackage(playerList); } { McpeAddPlayer message = McpeAddPlayer.CreateObject(); message.uuid = Uuid; message.username = NameTag ?? Name; message.entityId = EntityId; message.x = KnownPosition.X; message.y = KnownPosition.Y; message.z = KnownPosition.Z; message.yaw = KnownPosition.Yaw; message.headYaw = KnownPosition.HeadYaw; message.pitch = KnownPosition.Pitch; message.metadata = GetMetadata(); player.SendPackage(message); } { McpePlayerEquipment message = McpePlayerEquipment.CreateObject(); message.entityId = EntityId; message.item = ItemInHand; message.slot = 0; player.SendPackage(message); } { McpePlayerArmorEquipment armorEquipment = McpePlayerArmorEquipment.CreateObject(); armorEquipment.entityId = EntityId; armorEquipment.helmet = new MetadataSlot(new ItemStack()); armorEquipment.chestplate = new MetadataSlot(new ItemStack()); armorEquipment.leggings = new MetadataSlot(new ItemStack()); armorEquipment.boots = new MetadataSlot(new ItemStack()); player.SendPackage(armorEquipment); } }
/// <summary> /// Handles the player equipment. /// </summary> /// <param name="message">The message.</param> private void HandlePlayerEquipment(McpePlayerEquipment message) { if (HealthManager.IsDead) { return; } Inventory.ItemInHand.Value.Id = message.item; Inventory.ItemInHand.Value.Metadata = message.meta; McpePlayerEquipment msg = McpePlayerEquipment.CreateObject(); msg.entityId = EntityId; msg.item = message.item; msg.meta = message.meta; msg.slot = message.slot; msg.selectedSlot = message.selectedSlot; Level.RelayBroadcast(this, msg); }
public void SetHeldItemSlot(int selectedHotbarSlot, bool sendToPlayer = true) { InHandSlot = selectedHotbarSlot; if (sendToPlayer) { McpePlayerEquipment order = McpePlayerEquipment.CreateObject(); order.entityId = 0; order.item = GetItemInHand(); order.selectedSlot = (byte)selectedHotbarSlot; order.slot = (byte)ItemHotbar[InHandSlot]; Player.SendPackage(order); } McpePlayerEquipment broadcast = McpePlayerEquipment.CreateObject(); broadcast.entityId = Player.EntityId; broadcast.item = GetItemInHand(); broadcast.selectedSlot = (byte)selectedHotbarSlot; broadcast.slot = (byte)ItemHotbar[InHandSlot]; Player.Level?.RelayBroadcast(broadcast); }
public void SendSetSlot(int slot) { if (slot < HotbarSize && (ItemHotbar[slot] == -1 || ItemHotbar[slot] == slot)) { ItemHotbar[slot] = slot /* + HotbarSize*/; Player.SendPlayerInventory(); McpePlayerEquipment order = McpePlayerEquipment.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 SpawnToAll(Player newPlayer) { lock (_playerWriteLock) { List <Player> spawnedPlayers = GetSpawnedPlayers().ToList(); spawnedPlayers.Add(newPlayer); Player[] sendList = spawnedPlayers.ToArray(); McpePlayerList playerListMessage = McpePlayerList.CreateObject(); playerListMessage.records = new PlayerAddRecords(spawnedPlayers); var bytes = playerListMessage.Encode(); playerListMessage.records = null; MemoryStream memStream = new MemoryStream(); memStream.Write(BitConverter.GetBytes(Endian.SwapInt32(bytes.Length)), 0, 4); memStream.Write(bytes, 0, bytes.Length); McpeBatch batch = McpeBatch.CreateObject(); byte[] buffer = Player.CompressBytes(memStream.ToArray(), CompressionLevel.Optimal); batch.payloadSize = buffer.Length; batch.payload = buffer; batch.Encode(); newPlayer.SendPackage(batch); McpePlayerList playerList = McpePlayerList.CreateObject(); playerList.records = new PlayerAddRecords { newPlayer }; playerList.Encode(); playerList.records = null; RelayBroadcast(newPlayer, sendList, playerList); McpeAddPlayer mcpeAddPlayer = McpeAddPlayer.CreateObject(); mcpeAddPlayer.uuid = newPlayer.ClientUuid; mcpeAddPlayer.username = newPlayer.Username; mcpeAddPlayer.entityId = newPlayer.EntityId; mcpeAddPlayer.x = newPlayer.KnownPosition.X; mcpeAddPlayer.y = newPlayer.KnownPosition.Y; mcpeAddPlayer.z = newPlayer.KnownPosition.Z; mcpeAddPlayer.yaw = newPlayer.KnownPosition.Yaw; mcpeAddPlayer.headYaw = newPlayer.KnownPosition.HeadYaw; mcpeAddPlayer.pitch = newPlayer.KnownPosition.Pitch; mcpeAddPlayer.metadata = newPlayer.GetMetadata(); RelayBroadcast(newPlayer, sendList, mcpeAddPlayer); McpePlayerEquipment mcpePlayerEquipment = McpePlayerEquipment.CreateObject(); mcpePlayerEquipment.entityId = newPlayer.EntityId; mcpePlayerEquipment.item = new MetadataSlot(newPlayer.Inventory.GetItemInHand()); mcpePlayerEquipment.slot = 0; RelayBroadcast(newPlayer, sendList, mcpePlayerEquipment); McpePlayerArmorEquipment mcpePlayerArmorEquipment = McpePlayerArmorEquipment.CreateObject(); mcpePlayerArmorEquipment.entityId = newPlayer.EntityId; mcpePlayerArmorEquipment.helmet = new MetadataSlot(new ItemStack(newPlayer.Inventory.Helmet, 0)); mcpePlayerArmorEquipment.chestplate = new MetadataSlot(new ItemStack(newPlayer.Inventory.Chest, 0)); mcpePlayerArmorEquipment.leggings = new MetadataSlot(new ItemStack(newPlayer.Inventory.Leggings, 0)); mcpePlayerArmorEquipment.boots = new MetadataSlot(new ItemStack(newPlayer.Inventory.Boots, 0)); RelayBroadcast(newPlayer, sendList, mcpePlayerArmorEquipment); foreach (Player spawnedPlayer in spawnedPlayers) { SendAddForPlayer(newPlayer, spawnedPlayer, false); } } }
private void OnMcpePlayerEquipment(McpePlayerEquipment message) { Log.Debug($"PlayerEquipment: Entity ID: {message.entityId}, Selected Slot: {message.selectedSlot}, Slot: {message.slot}, Item ID: {message.item.Value.Id}, NBT: {message.item.Value.ExtraData}"); }
public override void SpawnToPlayers(Player[] players) { { Player fake = new Player(null, null) { ClientUuid = Uuid, EntityId = EntityId, NameTag = NameTag ?? Name, Skin = Skin }; McpePlayerList playerList = McpePlayerList.CreateObject(); playerList.records = new PlayerAddRecords { fake }; Level.RelayBroadcast(players, playerList); } { McpeAddPlayer message = McpeAddPlayer.CreateObject(); message.uuid = Uuid; message.username = NameTag ?? Name; message.entityId = EntityId; message.x = KnownPosition.X; message.y = KnownPosition.Y; message.z = KnownPosition.Z; message.yaw = KnownPosition.Yaw; message.headYaw = KnownPosition.HeadYaw; message.pitch = KnownPosition.Pitch; message.metadata = GetMetadata(); Level.RelayBroadcast(players, message); } { McpePlayerEquipment message = McpePlayerEquipment.CreateObject(); message.entityId = EntityId; message.item = ItemInHand; message.slot = 0; Level.RelayBroadcast(players, message); } { McpePlayerArmorEquipment armorEquipment = McpePlayerArmorEquipment.CreateObject(); armorEquipment.entityId = EntityId; armorEquipment.helmet = ItemFactory.GetItem(Helmet); armorEquipment.chestplate = ItemFactory.GetItem(Chest); armorEquipment.leggings = ItemFactory.GetItem(Leggings); armorEquipment.boots = ItemFactory.GetItem(Boots); Level.RelayBroadcast(players, armorEquipment); } { Player fake = new Player(null, null) { ClientUuid = Uuid, EntityId = EntityId, NameTag = NameTag ?? Name, Skin = Skin }; McpePlayerList playerList = McpePlayerList.CreateObject(); playerList.records = new PlayerRemoveRecords { fake }; Level.RelayBroadcast(players, playerList); } // Probably not needed BroadcastSetEntityData(); }
protected virtual void HandlePlayerEquipment(McpePlayerEquipment message) { if (HealthManager.IsDead) return; ItemStack itemStack = message.item.Value; if (GameMode != GameMode.Creative && itemStack != null && !VerifyItemStack(itemStack)) { Log.Error($"Kicked {Username} for equipment hacking."); Disconnect("Error #376. Please report this error."); } byte selectedHotbarSlot = message.selectedSlot; int selectedInventorySlot = (byte) (message.slot - PlayerInventory.HotbarSize); Log.Info($"Player {Username} called set equiptment with inv slot: {selectedInventorySlot}({message.slot}) and hotbar slot {message.selectedSlot} and Item ID: {message.item.Value.Id} with count item count: {message.item.Value.Count}"); // 255 indicates empty hmmm if (selectedInventorySlot < 0 || (message.slot != 255 && selectedInventorySlot >= Inventory.Slots.Count)) { if (GameMode != GameMode.Creative) { Log.Error($"Player {Username} set equiptment fails with inv slot: {selectedInventorySlot}({message.slot}) and hotbar slot {selectedHotbarSlot} for inventory size: {Inventory.Slots.Count} and Item ID: {message.item?.Value?.Id}"); } return; } if (message.slot == 255) { //Inventory.ItemHotbar[selectedHotbarSlot] = -1; //return; selectedInventorySlot = -1; } else { for (int i = 0; i < Inventory.ItemHotbar.Length; i++) { if (Inventory.ItemHotbar[i] == selectedInventorySlot) { Inventory.ItemHotbar[i] = Inventory.ItemHotbar[selectedHotbarSlot]; break; } } } Inventory.ItemHotbar[selectedHotbarSlot] = selectedInventorySlot; Inventory.SetHeldItemSlotNoSend(selectedHotbarSlot); //if (selectedInventorySlot < Inventory.Slots.Count) //{ // Inventory.Slots[selectedInventorySlot] = message.item.Value; //} Log.Info($"Player {Username} set equiptment with inv slot: {selectedInventorySlot}({message.slot}) and hotbar slot {selectedHotbarSlot}"); }
public void SendCraftingEvent2() { var recipe = _recipeToSend; if (recipe != null) { Log.Error("Sending crafting event: " + recipe.Id); McpeCraftingEvent crafting = new McpeCraftingEvent(); crafting.windowId = 0; crafting.recipeType = 1; crafting.recipeId = recipe.Id; { ItemStacks slotData = new ItemStacks(); for (int i = 0; i < recipe.Input.Length; i++) { slotData.Add(recipe.Input[i]); McpeContainerSetSlot setSlot = new McpeContainerSetSlot { item = recipe.Input[i], windowId = 0, slot = (short) (i) }; SendPackage(setSlot); Log.Error("Set set slot"); } crafting.input = slotData; { McpePlayerEquipment eq = new McpePlayerEquipment { entityId = _entityId, slot = 9, selectedSlot = 0, item = recipe.Input[0] }; SendPackage(eq); Log.Error("Set eq slot"); } } { ItemStacks slotData = new ItemStacks {recipe.Result}; crafting.result = slotData; } SendPackage(crafting); } //{ // McpeContainerSetSlot setSlot = new McpeContainerSetSlot(); // setSlot.item = new MetadataSlot(new ItemStack(new ItemDiamondAxe(0), 1)); // setSlot.windowId = 0; // setSlot.slot = 0; // SendPackage(setSlot); //} //{ // McpePlayerEquipment eq = new McpePlayerEquipment(); // eq.entityId = _entityId; // eq.slot = 9; // eq.selectedSlot = 0; // eq.item = new MetadataSlot(new ItemStack(new ItemDiamondAxe(0), 1)); // SendPackage(eq); //} }
public void SendCraftingEvent() { var recipe = _recipeToSend; if (recipe != null) { { McpeContainerSetSlot setSlot = new McpeContainerSetSlot(); setSlot.item = new ItemBlock(new Block(17), 0) {Count = 1}; setSlot.windowId = 0; setSlot.slot = 0; SendPackage(setSlot); } { McpePlayerEquipment eq = new McpePlayerEquipment(); eq.entityId = _entityId; eq.slot = 9; eq.selectedSlot = 0; eq.item = new ItemBlock(new Block(17), 0) {Count = 1}; SendPackage(eq); } Log.Error("Sending crafting event: " + recipe.Id); McpeCraftingEvent crafting = new McpeCraftingEvent(); crafting.windowId = 0; crafting.recipeType = 1; crafting.recipeId = recipe.Id; { ItemStacks slotData = new ItemStacks {new ItemBlock(new Block(17), 0) {Count = 1}}; crafting.input = slotData; } { ItemStacks slotData = new ItemStacks {new ItemBlock(new Block(5), 0) {Count = 1}}; crafting.result = slotData; } SendPackage(crafting); //{ // McpeContainerSetSlot setSlot = new McpeContainerSetSlot(); // setSlot.item = new MetadataSlot(new ItemStack(new ItemBlock(new Block(5), 0), 4)); // setSlot.windowId = 0; // setSlot.slot = 0; // SendPackage(setSlot); //} { McpePlayerEquipment eq = new McpePlayerEquipment(); eq.entityId = _entityId; eq.slot = 10; eq.selectedSlot = 1; eq.item = new ItemBlock(new Block(5), 0) {Count = 1}; SendPackage(eq); } } }
private void OnMcpePlayerEquipment(McpePlayerEquipment message) { Log.Debug($"PlayerEquipment: Entity ID: {message.entityId}, Selected Slot: {message.selectedSlot}, Slot: {message.slot}, Item ID: {message.item.Id}"); }
public void SendCraftingEvent2() { var recipe = _recipeToSend; if (recipe != null) { Log.Error("Sending crafting event: " + recipe.Id); McpeCraftingEvent crafting = new McpeCraftingEvent(); crafting.windowId = 0; crafting.recipeType = 1; crafting.recipeId = recipe.Id; { var slotData = new MetadataSlots(); for (int i = 0; i < recipe.Input.Length; i++) { slotData[i] = new MetadataSlot(new ItemStack(recipe.Input[i], 1)); McpeContainerSetSlot setSlot = new McpeContainerSetSlot { item = new MetadataSlot(new ItemStack(recipe.Input[i], 1)), windowId = 0, slot = (short)(i) }; SendPackage(setSlot); Log.Error("Set set slot"); } crafting.input = slotData; { McpePlayerEquipment eq = new McpePlayerEquipment { entityId = _entityId, slot = 9, selectedSlot = 0, item = new MetadataSlot(new ItemStack(recipe.Input[0], 1)) }; SendPackage(eq); Log.Error("Set eq slot"); } } { MetadataSlots slotData = new MetadataSlots(); slotData[0] = new MetadataSlot(recipe.Result); crafting.result = slotData; } SendPackage(crafting); } //{ // McpeContainerSetSlot setSlot = new McpeContainerSetSlot(); // setSlot.item = new MetadataSlot(new ItemStack(new ItemDiamondAxe(0), 1)); // setSlot.windowId = 0; // setSlot.slot = 0; // SendPackage(setSlot); //} //{ // McpePlayerEquipment eq = new McpePlayerEquipment(); // eq.entityId = _entityId; // eq.slot = 9; // eq.selectedSlot = 0; // eq.item = new MetadataSlot(new ItemStack(new ItemDiamondAxe(0), 1)); // SendPackage(eq); //} }
/// <summary> /// Handles the player equipment. /// </summary> /// <param name="message">The message.</param> private void HandlePlayerEquipment(McpePlayerEquipment message) { if (HealthManager.IsDead) return; Inventory.ItemInHand.Value.Id = message.item; Inventory.ItemInHand.Value.Metadata = message.meta; McpePlayerEquipment msg = McpePlayerEquipment.CreateObject(); msg.entityId = EntityId; msg.item = message.item; msg.meta = message.meta; msg.slot = message.slot; msg.selectedSlot = message.selectedSlot; Level.RelayBroadcast(this, msg); }
/// <summary> /// Handles the player equipment. /// </summary> /// <param name="message">The message.</param> protected virtual void HandlePlayerEquipment(McpePlayerEquipment message) { if (HealthManager.IsDead) return; //if(GameMode == GameMode.Survival) { int slot = (message.slot - 9); if (slot < 0 || slot > Inventory.Slots.Count || Inventory.Slots[((byte) slot)] == null) { //Level.BroadcastTextMessage(string.Format("Inventory change detected for player: {0} Slot: {1}", Username, slot), type: MessageType.Raw); //SendPackage(new McpeContainerSetContent //{ // windowId = 0, // slotData = Inventory.Slots, // hotbarData = Inventory.ItemHotbar //}); return; } ItemStack existing = Inventory.Slots[(byte) slot]; ItemStack selected = Inventory.Slots[message.selectedSlot]; Inventory.Slots[(byte) slot] = selected; Inventory.Slots[message.selectedSlot] = existing; Inventory.ItemInHand = existing.Item; } McpePlayerEquipment msg = McpePlayerEquipment.CreateObject(); msg.entityId = EntityId; msg.item = message.item; msg.meta = message.meta; msg.slot = message.slot; msg.selectedSlot = message.selectedSlot; Level.RelayBroadcast(this, msg); }