You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.3 KiB
37 lines
1.3 KiB
class_name CreativeBuilding |
|
extends Item |
|
|
|
func _process(_delta: float) -> void: |
|
if not player.network.is_local: return |
|
if not is_equipped: return |
|
|
|
var mouse_pos := get_global_mouse_position() |
|
var block_pos := Block.pos_from_vec(mouse_pos) |
|
var block := Game.WORLD.get_block(block_pos) |
|
|
|
rotation = player.position.angle_to_point(mouse_pos) |
|
|
|
if Input.is_action_pressed("interact_primary"): |
|
if block.matter == Matter.NONE: |
|
set_block(block, Matter.PLASTIC, Shape.FULL) |
|
|
|
if Input.is_action_pressed("interact_secondary"): |
|
set_block(block, Matter.NONE, Shape.EMPTY) |
|
|
|
|
|
func set_block(block: Block, matter: Matter, shape: Shape) -> void: |
|
block.matter = matter |
|
block.shape = shape |
|
if not multiplayer.is_server(): |
|
# Inform the server about the requested change. |
|
_on_set_block.rpc_id(1, block.pos, matter.id, shape.id) |
|
|
|
@rpc("reliable") |
|
func _on_set_block(block_pos: Vector2i, matter_id: int, shape_id: int) -> void: |
|
if not multiplayer.is_server(): return # Can only be processed by server. |
|
var block := Game.WORLD.get_block(block_pos) |
|
# TODO: Standerdize on one of these registry methods? |
|
block.matter = Matter.REGISTRY.lookup_by_id(matter_id) |
|
block.shape = Shape.lookup(shape_id) |
|
# TODO: This will cause the player who sent the message to receive |
|
# a block change even though they already changed said block.
|
|
|