From 67dc196a1e231b3dca36822dd222fefce189cabd Mon Sep 17 00:00:00 2001 From: TheFirewall Date: Fri, 2 Oct 2020 15:34:51 +0300 Subject: [PATCH 1/3] Fix negative number --- src/MiNET/MiNET/ItemStackInventoryManager.cs | 10 +++++----- src/MiNET/MiNET/Items/ArmorBase.cs | 8 ++++---- src/MiNET/MiNET/Items/Item.cs | 2 +- src/MiNET/MiNET/Items/ItemBow.cs | 2 +- src/MiNET/MiNET/Items/ItemElytra.cs | 2 +- src/MiNET/MiNET/Player.cs | 2 +- src/MiNET/TestPlugin/CoreCommands.cs | 2 +- .../TestPlugin/NiceLobby/NiceLobbyPlugin.cs | 16 ++++++++-------- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/MiNET/MiNET/ItemStackInventoryManager.cs b/src/MiNET/MiNET/ItemStackInventoryManager.cs index 8ddafa068..b10b77693 100644 --- a/src/MiNET/MiNET/ItemStackInventoryManager.cs +++ b/src/MiNET/MiNET/ItemStackInventoryManager.cs @@ -188,7 +188,7 @@ protected virtual void ProcessDropAction(DropAction action, List records) dropItem = (Item) sourceItem.Clone(); sourceItem.Count -= count; dropItem.Count = count; - dropItem.UniqueId = Environment.TickCount; + dropItem.UniqueId = Environment.TickCount & Int32.MaxValue; } DropItem(dropItem); diff --git a/src/MiNET/TestPlugin/CoreCommands.cs b/src/MiNET/TestPlugin/CoreCommands.cs index 904837152..77414dec1 100644 --- a/src/MiNET/TestPlugin/CoreCommands.cs +++ b/src/MiNET/TestPlugin/CoreCommands.cs @@ -1270,7 +1270,7 @@ public void Kit(Player player, int kitId) inventory.Slots[c++] = new ItemGoldenSword(); // Golden Sword inventory.Slots[c++] = new ItemIronSword(); // Iron Sword inventory.Slots[c++] = new ItemDiamondSword(); // Diamond Sword - inventory.Slots[c++] = new ItemArrow {Count = 64, UniqueId = Environment.TickCount}; // Arrows + inventory.Slots[c++] = new ItemArrow {Count = 64, UniqueId = Environment.TickCount & Int32.MaxValue}; // Arrows inventory.Slots[c++] = new ItemEgg {Count = 64}; // Eggs inventory.Slots[c++] = new ItemSnowball {Count = 64}; // Snowballs inventory.Slots[c++] = new ItemIronSword diff --git a/src/MiNET/TestPlugin/NiceLobby/NiceLobbyPlugin.cs b/src/MiNET/TestPlugin/NiceLobby/NiceLobbyPlugin.cs index e80f2f624..146839c36 100644 --- a/src/MiNET/TestPlugin/NiceLobby/NiceLobbyPlugin.cs +++ b/src/MiNET/TestPlugin/NiceLobby/NiceLobbyPlugin.cs @@ -512,31 +512,31 @@ private void OnPlayerJoin(object o, PlayerEventArgs eventArgs) { Count = 1, Metadata = 0, - UniqueId = Environment.TickCount + UniqueId = Environment.TickCount & Int32.MaxValue }; player.Inventory.Slots[idx++] = new ItemIronSword() { Count = 1, Metadata = 0, - UniqueId = Environment.TickCount + UniqueId = Environment.TickCount & Int32.MaxValue }; player.Inventory.Slots[idx++] = new ItemIronSword() { Count = 1, Metadata = 0, - UniqueId = Environment.TickCount + UniqueId = Environment.TickCount & Int32.MaxValue }; player.Inventory.Slots[idx++] = new ItemIronSword() { Count = 1, Metadata = 0, - UniqueId = Environment.TickCount + UniqueId = Environment.TickCount & Int32.MaxValue }; - player.Inventory.Helmet = new ItemDiamondHelmet() {UniqueId = Environment.TickCount}; - player.Inventory.Chest = new ItemElytra() {UniqueId = Environment.TickCount}; - player.Inventory.Leggings = new ItemDiamondLeggings() {UniqueId = Environment.TickCount}; - player.Inventory.Boots = new ItemDiamondBoots() {UniqueId = Environment.TickCount}; + player.Inventory.Helmet = new ItemDiamondHelmet() {UniqueId = Environment.TickCount & Int32.MaxValue}; + player.Inventory.Chest = new ItemElytra() {UniqueId = Environment.TickCount & Int32.MaxValue}; + player.Inventory.Leggings = new ItemDiamondLeggings() {UniqueId = Environment.TickCount & Int32.MaxValue}; + player.Inventory.Boots = new ItemDiamondBoots() {UniqueId = Environment.TickCount & Int32.MaxValue}; //while (player.Inventory.SetFirstEmptySlot(new ItemIronAxe(), false)) { } player.SendPlayerInventory(); From 8319349ead79aff9d8f59f820032b940b200a9f5 Mon Sep 17 00:00:00 2001 From: TheFirewall Date: Fri, 2 Oct 2020 16:24:03 +0300 Subject: [PATCH 2/3] =?UTF-8?q?Add=C2=A0drops=C2=A0in=C2=A0BreakEvent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MiNET/MiNET/Worlds/Level.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/MiNET/MiNET/Worlds/Level.cs b/src/MiNET/MiNET/Worlds/Level.cs index 631b31847..9aae010ee 100644 --- a/src/MiNET/MiNET/Worlds/Level.cs +++ b/src/MiNET/MiNET/Worlds/Level.cs @@ -1376,8 +1376,9 @@ public void BreakBlock(Player player, BlockCoordinates blockCoordinates, BlockFa Item inHand = player.Inventory.GetItemInHand(); bool canBreak = inHand.BreakBlock(this, player, block, blockEntity); - - if (!canBreak || !AllowBreak || player.GameMode == GameMode.Spectator || !OnBlockBreak(new BlockBreakEventArgs(player, this, block, null))) + List drops = new List(); + drops.AddRange(block.GetDrops(inHand ?? new ItemAir())); + if (!canBreak || !AllowBreak || player.GameMode == GameMode.Spectator || !OnBlockBreak(new BlockBreakEventArgs(player, this, block, drops))) { // Revert @@ -1385,7 +1386,7 @@ public void BreakBlock(Player player, BlockCoordinates blockCoordinates, BlockFa } else { - BreakBlock(player, block, blockEntity, inHand, face); + BreakBlock(player, block, drops, blockEntity, inHand, face); player.Inventory.DamageItemInHand(ItemDamageReason.BlockBreak, null, block); player.HungerManager.IncreaseExhaustion(0.025f); @@ -1421,11 +1422,14 @@ private static void RevertBlockAction(Player player, Block block, BlockEntity bl } } - public void BreakBlock(Player player, Block block, BlockEntity blockEntity = null, Item tool = null, BlockFace face = BlockFace.None) + public void BreakBlock(Player player, Block block, List drops = null, BlockEntity blockEntity = null, Item tool = null, BlockFace face = BlockFace.None) { block.BreakBlock(this, face); - var drops = new List(); - drops.AddRange(block.GetDrops(tool ?? new ItemAir())); + if (drops == null) + { + drops = new List(); + drops.AddRange(block.GetDrops(tool ?? new ItemAir())); + } if (blockEntity != null) { From 4691205055c14761d8e74a219ddc14cc58c9138c Mon Sep 17 00:00:00 2001 From: TheFirewall Date: Fri, 2 Oct 2020 16:26:40 +0300 Subject: [PATCH 3/3] =?UTF-8?q?Revert=20"Add=C2=A0drops=C2=A0in=C2=A0Break?= =?UTF-8?q?Event"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 8319349ead79aff9d8f59f820032b940b200a9f5. --- src/MiNET/MiNET/Worlds/Level.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/MiNET/MiNET/Worlds/Level.cs b/src/MiNET/MiNET/Worlds/Level.cs index 9aae010ee..631b31847 100644 --- a/src/MiNET/MiNET/Worlds/Level.cs +++ b/src/MiNET/MiNET/Worlds/Level.cs @@ -1376,9 +1376,8 @@ public void BreakBlock(Player player, BlockCoordinates blockCoordinates, BlockFa Item inHand = player.Inventory.GetItemInHand(); bool canBreak = inHand.BreakBlock(this, player, block, blockEntity); - List drops = new List(); - drops.AddRange(block.GetDrops(inHand ?? new ItemAir())); - if (!canBreak || !AllowBreak || player.GameMode == GameMode.Spectator || !OnBlockBreak(new BlockBreakEventArgs(player, this, block, drops))) + + if (!canBreak || !AllowBreak || player.GameMode == GameMode.Spectator || !OnBlockBreak(new BlockBreakEventArgs(player, this, block, null))) { // Revert @@ -1386,7 +1385,7 @@ public void BreakBlock(Player player, BlockCoordinates blockCoordinates, BlockFa } else { - BreakBlock(player, block, drops, blockEntity, inHand, face); + BreakBlock(player, block, blockEntity, inHand, face); player.Inventory.DamageItemInHand(ItemDamageReason.BlockBreak, null, block); player.HungerManager.IncreaseExhaustion(0.025f); @@ -1422,14 +1421,11 @@ private static void RevertBlockAction(Player player, Block block, BlockEntity bl } } - public void BreakBlock(Player player, Block block, List drops = null, BlockEntity blockEntity = null, Item tool = null, BlockFace face = BlockFace.None) + public void BreakBlock(Player player, Block block, BlockEntity blockEntity = null, Item tool = null, BlockFace face = BlockFace.None) { block.BreakBlock(this, face); - if (drops == null) - { - drops = new List(); - drops.AddRange(block.GetDrops(tool ?? new ItemAir())); - } + var drops = new List(); + drops.AddRange(block.GetDrops(tool ?? new ItemAir())); if (blockEntity != null) {