Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix negative number #525

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/MiNET/MiNET/ItemStackInventoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ protected virtual void ProcessDropAction(DropAction action, List<StackResponseCo
dropItem = (Item) sourceItem.Clone();
sourceItem.Count -= count;
dropItem.Count = count;
dropItem.UniqueId = Environment.TickCount;
dropItem.UniqueId = Environment.TickCount & Int32.MaxValue;
}

_player.DropItem(dropItem);
Expand Down Expand Up @@ -307,7 +307,7 @@ protected virtual void ProcessPlaceAction(PlaceAction action, List<StackResponse
destItem = (Item) sourceItem.Clone();
sourceItem.Count -= count;
destItem.Count = count;
destItem.UniqueId = Environment.TickCount;
destItem.UniqueId = Environment.TickCount & Int32.MaxValue;
}

Item existingItem = GetContainerItem(destination.ContainerId, destination.Slot);
Expand Down Expand Up @@ -380,7 +380,7 @@ protected virtual void ProcessTakeAction(TakeAction action, List<StackResponseCo
destItem = (Item) sourceItem.Clone();
sourceItem.Count -= count;
destItem.Count = count;
destItem.UniqueId = Environment.TickCount;
destItem.UniqueId = Environment.TickCount & Int32.MaxValue;
}

SetContainerItem(destination.ContainerId, destination.Slot, destItem);
Expand Down Expand Up @@ -430,7 +430,7 @@ protected virtual void ProcessCraftResultDeprecatedAction(CraftResultDeprecatedA
Item craftingResult = action.ResultItems.FirstOrDefault();
if (craftingResult == null) return;

craftingResult.UniqueId = Environment.TickCount;
craftingResult.UniqueId = Environment.TickCount & Int32.MaxValue;
SetContainerItem(59, 50, craftingResult);
}

Expand All @@ -449,7 +449,7 @@ protected virtual void ProcessCraftCreativeAction(CraftCreativeAction action)
if (creativeItem == null) throw new Exception($"Failed to find inventory item with unique id: {action.CreativeItemNetworkId}");
creativeItem = ItemFactory.GetItem(creativeItem.Id, creativeItem.Metadata);
creativeItem.Count = (byte) creativeItem.MaxStackSize;
creativeItem.UniqueId = Environment.TickCount;
creativeItem.UniqueId = Environment.TickCount & Int32.MaxValue;
Log.Debug($"Creating {creativeItem}");
_player.Inventory.UiInventory.Slots[50] = creativeItem;
}
Expand Down
8 changes: 4 additions & 4 deletions src/MiNET/MiNET/Items/ArmorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override void UseItem(Level world, Player player, BlockCoordinates blockC
byte slot = (byte) player.Inventory.Slots.IndexOf(this);
player.Inventory.SetInventorySlot(slot, player.Inventory.Helmet);

UniqueId = Environment.TickCount;
UniqueId = Environment.TickCount & Int32.MaxValue;
player.Inventory.Helmet = this;
player.SendArmorForPlayer();
}
Expand All @@ -57,7 +57,7 @@ public override void UseItem(Level world, Player player, BlockCoordinates blockC
byte slot = (byte) player.Inventory.Slots.IndexOf(this);
player.Inventory.SetInventorySlot(slot, player.Inventory.Chest);

UniqueId = Environment.TickCount;
UniqueId = Environment.TickCount & Int32.MaxValue;
player.Inventory.Chest = this;
player.SendArmorForPlayer();
}
Expand All @@ -74,7 +74,7 @@ public override void UseItem(Level world, Player player, BlockCoordinates blockC
byte slot = (byte) player.Inventory.Slots.IndexOf(this);
player.Inventory.SetInventorySlot(slot, player.Inventory.Leggings);

UniqueId = Environment.TickCount;
UniqueId = Environment.TickCount & Int32.MaxValue;
player.Inventory.Leggings = this;
player.SendArmorForPlayer();
}
Expand All @@ -91,7 +91,7 @@ public override void UseItem(Level world, Player player, BlockCoordinates blockC
byte slot = (byte) player.Inventory.Slots.IndexOf(this);
player.Inventory.SetInventorySlot(slot, player.Inventory.Boots);

UniqueId = Environment.TickCount;
UniqueId = Environment.TickCount & Int32.MaxValue;
player.Inventory.Boots = this;
player.SendArmorForPlayer();
}
Expand Down
2 changes: 1 addition & 1 deletion src/MiNET/MiNET/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Item : ICloneable
{
private static readonly ILog Log = LogManager.GetLogger(typeof(Item));

public int UniqueId { get; set; } = Environment.TickCount;
public int UniqueId { get; set; } = Environment.TickCount & Int32.MaxValue;
public string Name { get; protected set; } = string.Empty;
public short Id { get; protected set; }
public short Metadata { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/MiNET/MiNET/Items/ItemBow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public override void Release(Level world, Player player, BlockCoordinates blockC
if (!isInfinity)
{
item.Count -= 1;
item.UniqueId = Environment.TickCount;
item.UniqueId = Environment.TickCount & Int32.MaxValue;
if (item.Count <= 0) inventory.OffHand = new ItemAir();

player.SendPlayerInventory();
Expand Down
2 changes: 1 addition & 1 deletion src/MiNET/MiNET/Items/ItemElytra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override void UseItem(Level world, Player player, BlockCoordinates blockC
byte slot = (byte) player.Inventory.Slots.IndexOf(this);
player.Inventory.SetInventorySlot(slot, player.Inventory.Chest);

UniqueId = Environment.TickCount;
UniqueId = Environment.TickCount & Int32.MaxValue;
player.Inventory.Chest = this;
player.SendArmorForPlayer();
}
Expand Down
2 changes: 1 addition & 1 deletion src/MiNET/MiNET/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2560,7 +2560,7 @@ protected virtual void HandleTransactionRecords(List<TransactionRecord> records)
dropItem = (Item) sourceItem.Clone();
sourceItem.Count -= count;
dropItem.Count = count;
dropItem.UniqueId = Environment.TickCount;
dropItem.UniqueId = Environment.TickCount & Int32.MaxValue;
}

DropItem(dropItem);
Expand Down
2 changes: 1 addition & 1 deletion src/MiNET/TestPlugin/CoreCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/MiNET/TestPlugin/NiceLobby/NiceLobbyPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down