Class ItemPickUpComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.player.ItemPickUpComponent
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.
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Called when the component is created.createItemFromTexture
(String texture) The method recreates an item entity based on its texture path.Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, getPrio, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
ItemPickUpComponent
-
-
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 -
createItemFromTexture
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, ornull
if the texture does not correspond to a known item type.
-