|
extends RayCast3D
|
|
|
|
|
|
@export var player: Player
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
if is_colliding():
|
|
var collider: Object = get_collider()
|
|
|
|
if collider is Block:
|
|
if Input.is_action_just_pressed("right_click_interact"):
|
|
(collider as Block).destroy_block()
|
|
if Input.is_action_just_pressed("left_click_interact"):
|
|
var block_pos: Vector3i = Vector3i(collider.position + get_collision_normal())
|
|
|
|
if !is_valid_placement_target(block_pos):
|
|
return
|
|
|
|
EntityManager.create_block.emit(InventoryManager.get_quick_slot_item_id(), block_pos)
|
|
InventoryManager.remove_from_quickslot.emit(1)
|
|
|
|
if Waila.ref.get_target() == collider:
|
|
return
|
|
if not Waila.ref.get_target():
|
|
hook_block(collider)
|
|
else:
|
|
release_target()
|
|
else: # Not looking at anything
|
|
if Waila.ref.get_target():
|
|
release_target()
|
|
|
|
|
|
func is_valid_placement_target(block_pos: Vector3i) -> bool:
|
|
var collision_shape_radius: float = player.collision_shape_standing.shape.radius
|
|
|
|
var collision_size_adjustments: Vector3 = Vector3(collision_shape_radius, 0, collision_shape_radius)
|
|
var player_position_min: Vector3 = player.global_position - collision_size_adjustments
|
|
var player_position_max: Vector3 = player.global_position + collision_size_adjustments
|
|
|
|
player_position_max.y += player.current_height
|
|
|
|
var _is_overlapping_player: bool = (
|
|
block_pos.x >= player_position_min.x and block_pos.x <= player_position_max.x and
|
|
block_pos.y >= player_position_min.y and block_pos.y <= player_position_max.y and
|
|
block_pos.z >= player_position_min.z and block_pos.z <= player_position_max.z
|
|
)
|
|
|
|
return !_is_overlapping_player
|
|
|
|
|
|
func hook_block(target_block: Block) -> void:
|
|
target_block.hook()
|
|
Waila.ref.set_target(target_block)
|
|
|
|
var id: String = target_block.get_id()
|
|
Waila.ref.hook_target(id)
|
|
|
|
func release_target() -> void:
|
|
Waila.ref.get_target().release()
|
|
Waila.ref.set_target(null)
|
|
Waila.ref.release_target()
|