mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-05-27 22:23:50 +00:00
itemstack syncing for inevntory
This commit is contained in:
parent
fea50d33e2
commit
921abd48a7
3 changed files with 44 additions and 4 deletions
|
|
@ -11,6 +11,8 @@ public class ItemStack
|
|||
private int _amount;
|
||||
private short _durability;
|
||||
private ItemMeta? _meta;
|
||||
internal Inventory? _ownerInventory;
|
||||
internal int _ownerSlot = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new ItemStack of the specified material with amount 1.
|
||||
|
|
@ -62,7 +64,7 @@ public class ItemStack
|
|||
/// Sets the type of this item.
|
||||
/// </summary>
|
||||
/// <param name="type">New type to set the items in this stack to.</param>
|
||||
public void setType(Material type) => _type = type;
|
||||
public void setType(Material type) { _type = type; SyncToOwner(); }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type id for this item.
|
||||
|
|
@ -77,6 +79,7 @@ public class ItemStack
|
|||
public void setTypeId(int type)
|
||||
{
|
||||
_type = Enum.IsDefined(typeof(Material), type) ? (Material)type : Material.AIR;
|
||||
SyncToOwner();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -89,7 +92,7 @@ public class ItemStack
|
|||
/// Sets the amount of items in this stack.
|
||||
/// </summary>
|
||||
/// <param name="amount">New amount of items in this stack.</param>
|
||||
public void setAmount(int amount) => _amount = amount;
|
||||
public void setAmount(int amount) { _amount = amount; SyncToOwner(); }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the durability of this item.
|
||||
|
|
@ -101,7 +104,7 @@ public class ItemStack
|
|||
/// Sets the durability of this item.
|
||||
/// </summary>
|
||||
/// <param name="durability">Durability of this item.</param>
|
||||
public void setDurability(short durability) => _durability = durability;
|
||||
public void setDurability(short durability) { _durability = durability; SyncToOwner(); }
|
||||
|
||||
/// <summary>
|
||||
/// Get a copy of this ItemStack's ItemMeta.
|
||||
|
|
@ -129,4 +132,22 @@ public class ItemStack
|
|||
internal ItemMeta? getItemMetaInternal() => _meta;
|
||||
|
||||
internal void setItemMetaInternal(ItemMeta? meta) => _meta = meta;
|
||||
|
||||
internal void BindToInventory(Inventory inventory, int slot)
|
||||
{
|
||||
_ownerInventory = inventory;
|
||||
_ownerSlot = slot;
|
||||
}
|
||||
|
||||
internal void UnbindFromInventory()
|
||||
{
|
||||
_ownerInventory = null;
|
||||
_ownerSlot = -1;
|
||||
}
|
||||
|
||||
private void SyncToOwner()
|
||||
{
|
||||
if (_ownerInventory != null && _ownerSlot >= 0)
|
||||
_ownerInventory.setItem(_ownerSlot, this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue