extends GridMap class_name Chunk var x = 0 var z = 0 var size = 0 var should_remove = false func _init(x: int, z: int, size: int): self.x = x self.z = z self.size = size mesh_library = load("res://assets/blocs/blocs.meshlib") cell_size = Vector3(1, 1, 1) cell_center_x = false cell_center_y = false cell_center_z = false set_collision_layer_value(7, true) set_collision_mask_value(7, true) set_collision_layer_value(8, true) set_collision_mask_value(8, true) create_chunk() create_water() func create_chunk(): for mx in size: for mz in size: var position = Vector2i(mx + (size) * x, mz + (size) * z) # position.x = min(position.x, Global.world.width - 1) # position.y = min(position.y, Global.world.height - 1) var bloc = Global.world.get_bloc(position) var my: float = bloc.position.y var meshID var mesh_rotation if bloc.type != 0: var neighbours = Global.world.get_neighbours_4_at_same_height(position) if neighbours == Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_3 mesh_rotation = Global.GRID_ROTATION[3] elif neighbours == Global.directions_4.LEFT: meshID = Global.bloc_sides_id.SIDE_3 mesh_rotation = Global.GRID_ROTATION[1] elif neighbours == Global.directions_4.LEFT + Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_2_OPPOSITE mesh_rotation = Global.GRID_ROTATION[0] elif neighbours == Global.directions_4.BOTTOM: meshID = Global.bloc_sides_id.SIDE_3 mesh_rotation = Global.GRID_ROTATION[0] elif neighbours == Global.directions_4.BOTTOM + Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_2_ANGLE mesh_rotation = Global.GRID_ROTATION[3] elif neighbours == Global.directions_4.BOTTOM + Global.directions_4.LEFT: meshID = Global.bloc_sides_id.SIDE_2_ANGLE mesh_rotation = Global.GRID_ROTATION[0] elif neighbours == Global.directions_4.BOTTOM + Global.directions_4.LEFT + Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_1 mesh_rotation = Global.GRID_ROTATION[0] elif neighbours == Global.directions_4.TOP: meshID = Global.bloc_sides_id.SIDE_3 mesh_rotation = Global.GRID_ROTATION[2] elif neighbours == Global.directions_4.TOP + Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_2_ANGLE mesh_rotation = Global.GRID_ROTATION[2] elif neighbours == Global.directions_4.TOP + Global.directions_4.LEFT: meshID = Global.bloc_sides_id.SIDE_2_ANGLE mesh_rotation = Global.GRID_ROTATION[1] elif neighbours == Global.directions_4.TOP + Global.directions_4.LEFT + Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_1 mesh_rotation = Global.GRID_ROTATION[2] elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM: meshID = Global.bloc_sides_id.SIDE_2_OPPOSITE mesh_rotation = Global.GRID_ROTATION[1] elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM + Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_1 mesh_rotation = Global.GRID_ROTATION[3] elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM + Global.directions_4.LEFT: meshID = Global.bloc_sides_id.SIDE_1 mesh_rotation = Global.GRID_ROTATION[1] elif neighbours == Global.directions_4.TOP + Global.directions_4.BOTTOM + Global.directions_4.LEFT + Global.directions_4.RIGHT: meshID = Global.bloc_sides_id.SIDE_0 mesh_rotation = Global.GRID_ROTATION[0] elif neighbours == 0: meshID = Global.bloc_sides_id.SIDE_4 mesh_rotation = Global.GRID_ROTATION[0] set_cell_item( Vector3(mx, my, mz) , meshID, mesh_rotation) func create_water(): var plane_mesh = PlaneMesh.new() plane_mesh.size = Vector2(size, size) plane_mesh.material = preload("res://assets/water.material") var mesh_instance = MeshInstance3D.new() mesh_instance.mesh = plane_mesh var collision_shape = CollisionShape3D.new() var box = BoxShape3D.new() box.size = Vector3(512, 0, 512) collision_shape.shape = box var static_body = StaticBody3D.new() static_body.set_name("Ocean") static_body.set_collision_layer_value(8, true) static_body.add_child(mesh_instance) static_body.add_child(collision_shape) static_body.translate(Vector3(size/2, 0.5, size/2)) add_child(static_body)