module Rosegold::InventoryOperations

Overview

Shared operations for inventory and container menus Extracts common logic from both ContainerMenu and InventoryMenu

Direct including types

Defined in:

rosegold/inventory/inventory_operations.cr

Instance Method Summary

Instance Method Detail

abstract def [](index : Int32) : Rosegold::Slot #

Abstract methods that must be implemented by including classes


[View source]
abstract def []=(index : Int32, slot : Rosegold::Slot) #

[View source]
abstract def allow_modification?(slot_index : Int32) : Bool #

[View source]
def can_stack?(slot1 : Rosegold::Slot, slot2 : Rosegold::Slot) : Bool #

Check if two slots can be stacked together


[View source]
def check_and_fix_desync #

Check for desync and request refresh if needed (vanilla-style recovery)


[View source]
def content : Array(Rosegold::WindowSlot) #

Shared compatibility methods


[View source]
abstract def content_slots : Array(Rosegold::WindowSlot) #

[View source]
def copy_slot(slot : Rosegold::Slot) : Rosegold::Slot #

Create a deep copy of a slot


[View source]
def cursor : Rosegold::Slot #

Cursor slot management


[View source]
def cursor=(cursor : Rosegold::Slot) #

[View source]
def get_max_stack_size(item_slot : Rosegold::Slot) : Int32 #

Get max stack size for an item


[View source]
abstract def get_slot_max_stack_size(slot_index : Int32, item_slot : Rosegold::Slot) : Int32 #

[View source]
def hotbar : Array(Rosegold::WindowSlot) #

[View source]
abstract def hotbar_slot_index(hotbar_nr : Int32) : Int32 #

[View source]
abstract def hotbar_slots : Array(Rosegold::WindowSlot) #

Player inventory delegation methods


[View source]
def increment_state_id : UInt32 #

Vanilla state ID increment with 15-bit wraparound (matches vanilla's incrementStateId)


[View source]
def inventory : Array(Rosegold::WindowSlot) #

[View source]
abstract def inventory_slots : Array(Rosegold::WindowSlot) #

[View source]
def main_hand : Rosegold::Slot #

[View source]
def main_inventory_slots : Array(Rosegold::Slot) #

[View source]
abstract def may_pickup?(slot_index : Int32) : Bool #

[View source]
abstract def may_place?(slot_index : Int32, item_slot : Rosegold::Slot) : Bool #

[View source]
abstract def menu_id : UInt8 #

[View source]
def move_item_stack_to(source_index : Int32, target_start : Int32, target_end : Int32, reverse : Bool = false) : Bool #

Vanilla's moveItemStackTo equivalent - exact implementation from AbstractContainerMenu.java


[View source]
abstract def offhand_slot_index : Int32 #

Abstract methods for slot index calculations (different per menu type)


[View source]
def perform_cursor_drop_operation(button : Int32) #

Shared cursor drop operation (identical in both menus)


[View source]
def perform_drop_operation(slot_index : Int32, button : Int32) #

Shared drop operation (identical in both menus)


[View source]
def perform_hotbar_swap(slot_index : Int32, button : Int32) #

Shared hotbar swap for click operations (identical validation logic)


[View source]
def perform_offhand_swap_operation(slot_index : Int32) #

Shared off-hand swap operation (identical in both menus)


[View source]
def perform_regular_click(slot_index : Int32, button : Int32) #

Shared regular click operation (identical vanilla logic in both menus)


[View source]
abstract def perform_shift_click(slot_index : Int32) #

Keep existing abstract methods


[View source]
def safe_insert(target_slot_index : Int32, cursor_slot : Rosegold::Slot, amount : Int32) #

Vanilla's safeInsert equivalent - safely insert items from cursor to slot


[View source]
def safe_take(source_slot_index : Int32, amount : Int32) #

Vanilla's tryRemove/safeTake equivalent - safely take items from slot


[View source]
def same_item_same_components?(slot1 : Rosegold::Slot, slot2 : Rosegold::Slot) : Bool #

Check if two slots have the same item and components (for stacking)


[View source]
def send_click(slot_index : Int32, button : Int32, click_type) #

Send container click packet with vanilla client-side logic


[View source]
def slots : Array(Rosegold::WindowSlot) #

Shared slot conversion to WindowSlots (identical in both menus)


[View source]
def slots=(new_slots : Array(Rosegold::WindowSlot)) #

[View source]
def slots_match?(slot1 : Rosegold::Slot, slot2 : Rosegold::Slot) : Bool #

Helper method to compare if two slots are equivalent (vanilla's ItemStack.matches equivalent)


[View source]
def swap_hotbar(hotbar_nr, slot : Rosegold::WindowSlot) #

[View source]
def swap_hotbar(hotbar_nr, slot_number) #

Shared hotbar swap operation with abstracted slot calculations


[View source]
def to_s(io) #

[View source]
abstract def total_slots : Int32 #

[View source]
def update_all_slots(slots : Array(Rosegold::Slot), cursor : Rosegold::Slot, packet_state_id : UInt32) #

Update all slots from SetContainerContent packet (vanilla behavior - no validation)


[View source]
def update_slot(index : Int32, slot : Rosegold::Slot, packet_state_id : UInt32) #

Update single slot (vanilla behavior - no validation)


[View source]