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.quick_slot_item_id, block_pos) 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: # This needs some work as it's still not quite reliable # Sometimes can't place in the position directly in front of the player var collision_shape_radius: float = player.collision_shape_standing.shape.radius - 0.2 # Fuzzy magic number (bad dev, bad) var maximums: Vector3 = Vector3(collision_shape_radius, 0, collision_shape_radius) var position_min: Vector3i = Vector3i(player.global_position - maximums) var position_max: Vector3i = Vector3i(player.global_position + maximums) position_max.y = player.current_height if ( block_pos.x >= position_min.x and block_pos.x <= position_max.x and block_pos.y >= position_min.y and block_pos.y <= position_max.y and block_pos.z >= position_min.z and block_pos.z <= position_max.z ): return false return true 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()