class_name Block
|
|
extends StaticBody3D
|
|
|
|
|
|
@onready var block_faces: Node3D = $BlockFaces
|
|
|
|
var id: String
|
|
var resource: BlockResource
|
|
|
|
|
|
func _ready() -> void:
|
|
_apply_materials()
|
|
|
|
|
|
func get_id() -> String:
|
|
return id
|
|
|
|
func set_id(block_id: String) -> void:
|
|
id = block_id
|
|
_get_resource_data()
|
|
_apply_materials()
|
|
|
|
|
|
func _apply_materials() -> void:
|
|
if block_faces == null: return
|
|
|
|
for face: MeshInstance3D in block_faces.get_children():
|
|
face.set_surface_override_material(0, resource.material)
|
|
|
|
func _get_resource_data() -> void:
|
|
if not id:
|
|
printerr("Block ID was expected but was not received")
|
|
return
|
|
|
|
resource = DBItems.ref.data[id]
|