|
|
@ -1,6 +1,9 @@ |
|
|
|
extends RayCast3D |
|
|
|
|
|
|
|
|
|
|
|
@export var player: Player |
|
|
|
|
|
|
|
|
|
|
|
func _process(_delta: float) -> void: |
|
|
|
if is_colliding(): |
|
|
|
var collider: Object = get_collider() |
|
|
@ -9,9 +12,14 @@ func _process(_delta: float) -> void: |
|
|
|
if Input.is_action_just_pressed("right_click_interact"): |
|
|
|
(collider as Block).destroy_block() |
|
|
|
if Input.is_action_just_pressed("left_click_interact"): |
|
|
|
var new_block_pos: Vector3i = Vector3i(collider.position + get_collision_normal()) |
|
|
|
|
|
|
|
if !is_valid_placement_target(new_block_pos): |
|
|
|
return |
|
|
|
|
|
|
|
EntityManager.create_block.emit( |
|
|
|
InventoryManager.quick_slot_item_id, |
|
|
|
collider.position + get_collision_normal() |
|
|
|
new_block_pos |
|
|
|
) |
|
|
|
|
|
|
|
if Waila.ref.get_target() == collider: |
|
|
@ -25,6 +33,24 @@ func _process(_delta: float) -> void: |
|
|
|
release_target() |
|
|
|
|
|
|
|
|
|
|
|
func is_valid_placement_target(new_block_pos: Vector3i) -> bool: |
|
|
|
# This could probably use some work |
|
|
|
var collision_shape_radius: float = player.collision_shape_standing.shape.radius |
|
|
|
|
|
|
|
var maximums: Vector3 = Vector3(collision_shape_radius, player.current_height, collision_shape_radius) |
|
|
|
var position_min: Vector3i = Vector3i(player.global_position - maximums) |
|
|
|
var position_max: Vector3i = Vector3i(player.global_position + maximums) |
|
|
|
|
|
|
|
if ( |
|
|
|
new_block_pos.x >= position_min.x and new_block_pos.x <= position_max.x and |
|
|
|
new_block_pos.y >= position_min.y and new_block_pos.y <= position_max.y and |
|
|
|
new_block_pos.z >= position_min.z and new_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) |
|
|
|