MinecraftConsoles/Minecraft.Server.FourKit/Inventory/DoubleChestInventory.cs
sylvessa f5f9aa1cf5 finish rewrite; port to cmake, loads of other changes
Theres documentation at https://sylvessa.zip/fourkit/ now. And a bunch of other changes. Check the discord server for a more comprehensive list
2026-03-21 14:01:49 -05:00

57 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace Minecraft.Server.FourKit.Inventory;
/// <summary>
/// Represents the inventory of a Double Chest.
/// 54 slots total — left side is slots 026, right side is slots 2753.
/// </summary>
public class DoubleChestInventory : Inventory
{
private readonly Inventory _left;
private readonly Inventory _right;
internal DoubleChestInventory(string title, int size, int entityId)
: base(title, InventoryType.CHEST, size, entityId)
{
_left = new InventorySlice("Left chest", this, 0, 27);
_right = new InventorySlice("Right chest", this, 27, 27);
}
/// <summary>
/// Get the left half of this double chest.
/// </summary>
/// <returns>The left side inventory.</returns>
public Inventory getLeftSide() => _left;
/// <summary>
/// Get the right half of this double chest.
/// </summary>
/// <returns>The right side inventory.</returns>
public Inventory getRightSide() => _right;
// todo: get rid of this class
private sealed class InventorySlice : Inventory
{
private readonly Inventory _parent;
private readonly int _offset;
internal InventorySlice(string name, Inventory parent, int offset, int size)
: base(name, InventoryType.CHEST, size)
{
_parent = parent;
_offset = offset;
}
public override ItemStack? getItem(int index)
{
if (index < 0 || index >= getSize()) return null;
return _parent.getItem(_offset + index);
}
public override void setItem(int index, ItemStack? item)
{
if (index >= 0 && index < getSize())
_parent.setItem(_offset + index, item);
}
}
}