<commit_before>package com.voxelwind.server.game.inventories;

import com.voxelwind.api.game.inventories.InventoryType;
import com.voxelwind.api.game.inventories.PlayerInventory;
import com.voxelwind.api.game.item.ItemStack;
import com.voxelwind.server.network.mcpe.packets.McpeMobEquipment;
import com.voxelwind.server.network.session.PlayerSession;

import java.util.Arrays;
import java.util.Optional;

public class VoxelwindBasePlayerInventory extends VoxelwindBaseInventory implements PlayerInventory {
    private final PlayerSession session;
    private final int[] hotbarLinks = new int[9];
    private int heldSlot = 0;

    public VoxelwindBasePlayerInventory(PlayerSession session) {
        // TODO: Verify
        super(InventoryType.PLAYER);
        this.session = session;
        getObserverList().add(session);
        Arrays.fill(hotbarLinks, -1);
    }

    @Override
    public int getUsableInventorySize() {
        // Four slots are reserved for armor, however Voxelwind stores them separately.
        return InventoryType.PLAYER.getInventorySize() - 4;
    }

    @Override
    public int[] getHotbarLinks() {
        return Arrays.copyOf(hotbarLinks, hotbarLinks.length);
    }

    public void setLink(int hotbarSlot, int inventorySlot) {
        hotbarLinks[hotbarSlot] = inventorySlot;
    }

    @Override
    public int getHeldSlot() {
        return heldSlot;
    }

    @Override
    public Optional<ItemStack> getStackInHand() {
        return getItem(getHeldSlot());
    }

    public void setHeldSlot(int heldSlot, boolean sendToPlayer) {
        this.heldSlot = heldSlot;

        if (sendToPlayer) {
            McpeMobEquipment equipmentForSelf = new McpeMobEquipment();
            equipmentForSelf.setEntityId(0);
            equipmentForSelf.setHotbarSlot((byte) heldSlot);
            equipmentForSelf.setInventorySlot((byte) hotbarLinks[heldSlot]);
            equipmentForSelf.setStack(getStackInHand().orElse(null));<commit_msg>Custom usable inventory size no longer required.<commit_after>package com.voxelwind.server.game.inventories;

import com.voxelwind.api.game.inventories.InventoryType;
import com.voxelwind.api.game.inventories.PlayerInventory;
import com.voxelwind.api.game.item.ItemStack;
import com.voxelwind.server.network.mcpe.packets.McpeMobEquipment;
import com.voxelwind.server.network.session.PlayerSession;

import java.util.Arrays;
import java.util.Optional;

public class VoxelwindBasePlayerInventory extends VoxelwindBaseInventory implements PlayerInventory {
    private final PlayerSession session;
    private final int[] hotbarLinks = new int[9];
    private int heldSlot = 0;

    public VoxelwindBasePlayerInventory(PlayerSession session) {
        // TODO: Verify
        super(InventoryType.PLAYER);
        this.session = session;
        getObserverList().add(session);
        Arrays.fill(hotbarLinks, -1);
    }

    @Override
    public int[] getHotbarLinks() {
        return Arrays.copyOf(hotbarLinks, hotbarLinks.length);
    }

    public void setLink(int hotbarSlot, int inventorySlot) {
        hotbarLinks[hotbarSlot] = inventorySlot;
    }

    @Override
    public int getHeldSlot() {
        return heldSlot;
    }

    @Override
    public Optional<ItemStack> getStackInHand() {
        return getItem(getHeldSlot());
    }

    public void setHeldSlot(int heldSlot, boolean sendToPlayer) {
        this.heldSlot = heldSlot;

        if (sendToPlayer) {
            McpeMobEquipment equipmentForSelf = new McpeMobEquipment();
            equipmentForSelf.setEntityId(0);
            equipmentForSelf.setHotbarSlot((byte) heldSlot);
            equipmentForSelf.setInventorySlot((byte) hotbarLinks[heldSlot]);
            equipmentForSelf.setStack(getStackInHand().orElse(null));
{'fraction_non_alphanumeric': 0.09023354564755838, 'fraction_numerical': 0.0023885350318471337, 'mean_word_length': 3.4709371293001188, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6965894', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1119, 'n_words': 213}