Class ItemPickUpComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.player.ItemPickUpComponent

public class ItemPickUpComponent extends Component
Component that allows an entity to pick up items when in proximity. Listens for collision events with items and adds them to the inventory on request.
  • Constructor Details

  • Method Details

    • create

      public void create()
      Called when the component is created. Registers listeners for relevant player events: - collisionStart – detects items in proximity - collisionEnd – clears the current target item when leaving range - pick up – attempts to add the current target item to the inventory - focus item – updates the focused inventory slot - drop focused – attempts to drop the currently focused item
      Overrides:
      create in class Component
    • createItemFromTexture

      public Entity createItemFromTexture(String texture)
      The method recreates an item entity based on its texture path. This method is used when dropping items from the inventory back into the world. Since inventory only stores the texture reference the texture string is used here as a lookup key to recreate the appropriate entity using the relevant factory class.
      Parameters:
      texture - the texture file path associated with the item in inventory
      Returns:
      a new Entity matching the texture, or null if the texture does not correspond to a known item type.