Skip to content

Latest commit

 

History

History
98 lines (75 loc) · 4.06 KB

File metadata and controls

98 lines (75 loc) · 4.06 KB

Android Inventory Slot Filtering Implementation

Overview

This update implements slot filtering for the Android entity's inventory system, ensuring that items can only be placed in appropriate slots.

Changes Made

1. Custom Slot Classes Created

ArmorSlot

  • Purpose: Only accepts armor items matching the specific equipment slot type
  • Location: Slots 1-4 (boots=1, leggings=2, chestplate=3, helmet=4)
  • Filtering: Uses component-based armor detection that works with vanilla and modded armor
  • Visual: Uses vanilla armor slot background sprites (helmet, chestplate, leggings, boots)

ChipSlot

  • Purpose: Only accepts chip items from ModItems.CHIP
  • Location: Slots 6-8 (first 3 general slots converted to chip slots)
  • Filtering: Only allows ModItems.CHIP items
  • Visual: Currently uses default slot background (can be enhanced with custom texture)

MainHandSlot

  • Purpose: Accepts weapons, tools, and general items but excludes armor
  • Location: Slot 0 (main hand)
  • Filtering: Rejects armor items using component detection, allows everything else
  • Visual: Uses vanilla sword icon for empty slot

OffHandSlot

  • Purpose: Accepts shields and secondary items but excludes armor
  • Location: Slot 5 (offhand)
  • Filtering: Rejects armor items using component detection, allows everything else
  • Visual: Uses vanilla shield icon for empty slot

GeneralSlot

  • Purpose: Accepts general items but excludes armor and chips
  • Location: Slots 9-11 (remaining general inventory)
  • Filtering: Rejects armor items and chip items using component detection
  • Visual: Uses default slot background

2. AndroidInventoryScreenHandler Updates

  • Imports: Added custom slot imports and EquipmentSlot
  • Slot Creation: Replaced generic Slot instances with appropriate filtered slots
  • Armor Slot Mapping: Fixed slot indices to match EquipmentSlot.getIndex() values
  • QuickMove: Simplified to rely on Slot.canInsert() filtering

3. Slot Layout

Slot Index | Type        | Purpose           | Position
-----------|-------------|-------------------|----------
0          | MainHand    | Weapons/Tools     | (81, 8)
1          | ArmorSlot   | Boots            | (8, 62) 
2          | ArmorSlot   | Leggings         | (8, 44)
3          | ArmorSlot   | Chestplate       | (8, 26)
4          | ArmorSlot   | Helmet           | (8, 8)
5          | OffHand     | Shields/Secondary | (81, 26)
6-8        | ChipSlot    | Chips Only       | Top right row
9-11       | GeneralSlot | General Items    | Bottom right row

Armor Detection (ArmorUtils)

The armor detection system uses Minecraft's component system for robust compatibility:

  • Component-Based: Uses DataComponentTypes.EQUIPPABLE and EquippableComponent
  • Modded Compatibility: Works with any armor that properly implements the equippable component
  • Vanilla Support: Full support for all vanilla armor types
  • Equipment Slot Matching: Precise slot type detection for armor filtering

Methods:

  • isArmor(ItemStack): Detects any armor item using component data
  • isArmorOfType(ItemStack, EquipmentSlot): Matches armor to specific equipment slots

Testing

A test class SlotFilteringTest has been created to verify filtering behavior:

  • Armor slots only accept matching armor types
  • Chip slots only accept chip items
  • Main hand rejects armor but accepts other items
  • General slots reject both armor and chips
  • Empty stacks are properly rejected by all slots

Visual Improvements

  • Armor slots show appropriate empty slot icons (helmet, chestplate, leggings, boots)
  • Main hand shows sword icon when empty
  • Offhand shows shield icon when empty
  • Icons only display when slots are empty (like vanilla player inventory)

Compatibility

  • Maintains backward compatibility with existing inventory structure
  • Respects Minecraft's EquipmentSlot system for armor items
  • Full modded armor support through component-based detection
  • Works with shift-click (quickMove) operations
  • Follows vanilla UI patterns for empty slot icons