Skip to content

Commit 8af2e3b

Browse files
Update all calls to the new API
Yeah... this is a mess. I don't know if I like this.
1 parent c1c9961 commit 8af2e3b

17 files changed

+399
-838
lines changed

src/block_definitions.rs

Lines changed: 33 additions & 472 deletions
Large diffs are not rendered by default.

src/data_processing.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::args::Args;
2-
use crate::block_definitions::{DIRT, GRASS_BLOCK, SNOW_BLOCK};
2+
use crate::block_definitions::BLOCKS;
33
use crate::cartesian::XZPoint;
44
use crate::element_processing::*;
55
use crate::ground::Ground;
@@ -141,7 +141,7 @@ pub fn generate_world(
141141
let total_iterations_grnd: f64 = (scale_factor_x + 1.0) * (scale_factor_z + 1.0);
142142
let progress_increment_grnd: f64 = 30.0 / total_iterations_grnd;
143143

144-
let groundlayer_block = if args.winter { SNOW_BLOCK } else { GRASS_BLOCK };
144+
let groundlayer_block = if args.winter { BLOCKS.by_name("snow_block").unwrap() } else { BLOCKS.by_name("grass_block").unwrap() };
145145

146146
// Differentiate between terrain and non-terrain generation
147147
if ground.elevation_enabled {
@@ -168,8 +168,8 @@ pub fn generate_world(
168168

169169
// Set blocks in a single batch
170170
editor.set_block(groundlayer_block, x, max_y, z, None, None);
171-
editor.set_block(DIRT, x, max_y - 1, z, None, None);
172-
editor.set_block(DIRT, x, max_y - 2, z, None, None);
171+
editor.set_block(BLOCKS.by_name("dirt").unwrap(), x, max_y - 1, z, None, None);
172+
editor.set_block(BLOCKS.by_name("dirt").unwrap(), x, max_y - 2, z, None, None);
173173

174174
block_counter += 1;
175175
if block_counter % batch_size == 0 {
@@ -195,7 +195,7 @@ pub fn generate_world(
195195
for z in 0..=(scale_factor_z as i32) {
196196
let ground_level = ground.level(XZPoint::new(x, z));
197197
editor.set_block(groundlayer_block, x, ground_level, z, None, None);
198-
editor.set_block(DIRT, x, ground_level - 1, z, None, None);
198+
editor.set_block(BLOCKS.by_name("dirt").unwrap(), x, ground_level - 1, z, None, None);
199199

200200
block_counter += 1;
201201
if block_counter % batch_size == 0 {

src/element_processing/amenities.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::args::Args;
2-
use crate::block_definitions::*;
2+
use crate::block_definitions::BLOCKS;
33
use crate::bresenham::bresenham_line;
44
use crate::cartesian::XZPoint;
55
use crate::floodfill::flood_fill_area;
@@ -35,20 +35,20 @@ pub fn generate_amenities(
3535
"waste_disposal" | "waste_basket" => {
3636
// Place a cauldron for waste disposal or waste basket
3737
if let Some(pt) = first_node {
38-
editor.set_block(CAULDRON, pt.x, ground.level(pt) + 1, pt.z, None, None);
38+
editor.set_block(BLOCKS.by_name("cauldron").unwrap(), pt.x, ground.level(pt) + 1, pt.z, None, None);
3939
}
4040
}
4141
"vending_machine" | "atm" => {
4242
if let Some(pt) = first_node {
4343
let y = ground.level(pt);
4444

45-
editor.set_block(IRON_BLOCK, pt.x, y + 1, pt.z, None, None);
46-
editor.set_block(IRON_BLOCK, pt.x, y + 2, pt.z, None, None);
45+
editor.set_block(BLOCKS.by_name("iron_block").unwrap(), pt.x, y + 1, pt.z, None, None);
46+
editor.set_block(BLOCKS.by_name("iron_block").unwrap(), pt.x, y + 2, pt.z, None, None);
4747
}
4848
}
4949
"bicycle_parking" => {
50-
let ground_block: Block = OAK_PLANKS;
51-
let roof_block: Block = STONE_BLOCK_SLAB;
50+
let ground_block = BLOCKS.by_name("oak_planks").unwrap();
51+
let roof_block = BLOCKS.by_name("stone_block_slab").unwrap();
5252

5353
let polygon_coords: Vec<(i32, i32)> = element
5454
.nodes()
@@ -82,7 +82,7 @@ pub fn generate_amenities(
8282
editor.set_block(ground_block, x, y, z, None, None);
8383

8484
for cur_y in (y_min + 1)..roof_y {
85-
editor.set_block(OAK_FENCE, x, cur_y, z, None, None);
85+
editor.set_block(BLOCKS.by_name("oak_fence").unwrap(), x, cur_y, z, None, None);
8686
}
8787
editor.set_block(roof_block, x, roof_y, z, None, None);
8888
}
@@ -97,22 +97,22 @@ pub fn generate_amenities(
9797
if let Some(pt) = first_node {
9898
let y = ground.level(pt) + 1;
9999

100-
editor.set_block(SMOOTH_STONE, pt.x, y, pt.z, None, None);
101-
editor.set_block(OAK_LOG, pt.x + 1, y, pt.z, None, None);
102-
editor.set_block(OAK_LOG, pt.x - 1, y, pt.z, None, None);
100+
editor.set_block(BLOCKS.by_name("smooth_stone").unwrap(), pt.x, y, pt.z, None, None);
101+
editor.set_block(BLOCKS.by_name("oak_log").unwrap(), pt.x + 1, y, pt.z, None, None);
102+
editor.set_block(BLOCKS.by_name("oak_log").unwrap(), pt.x - 1, y, pt.z, None, None);
103103
}
104104
}
105105
"vending" => {
106106
// Place vending machine blocks
107107
if let Some(pt) = first_node {
108108
let y = ground.level(pt);
109109

110-
editor.set_block(IRON_BLOCK, pt.x, y + 1, pt.z, None, None);
111-
editor.set_block(IRON_BLOCK, pt.x, y + 2, pt.z, None, None);
110+
editor.set_block(BLOCKS.by_name("iron_block").unwrap(), pt.x, y + 1, pt.z, None, None);
111+
editor.set_block(BLOCKS.by_name("iron_block").unwrap(), pt.x, y + 2, pt.z, None, None);
112112
}
113113
}
114114
"shelter" => {
115-
let roof_block: Block = STONE_BRICK_SLAB;
115+
let roof_block = BLOCKS.by_name("stone_brick_slab").unwrap();
116116

117117
let polygon_coords: Vec<(i32, i32)> = element
118118
.nodes()
@@ -131,7 +131,7 @@ pub fn generate_amenities(
131131
};
132132

133133
for fence_height in 1..=4 {
134-
editor.set_block(OAK_FENCE, x, y + fence_height, z, None, None);
134+
editor.set_block(BLOCKS.by_name("oak_fence").unwrap(), x, y + fence_height, z, None, None);
135135
}
136136
editor.set_block(roof_block, x, y + 5, z, None, None);
137137
}
@@ -153,9 +153,9 @@ pub fn generate_amenities(
153153
let mut current_amenity: Vec<(i32, i32)> = vec![];
154154

155155
let block_type = match amenity_type.as_str() {
156-
"fountain" => WATER,
157-
"parking" => GRAY_CONCRETE,
158-
_ => GRAY_CONCRETE,
156+
"fountain" => BLOCKS.by_name("water").unwrap(),
157+
"parking" => BLOCKS.by_name("gray_concrete").unwrap(),
158+
_ => BLOCKS.by_name("gray_concrete").unwrap(),
159159
};
160160

161161
for node in element.nodes() {
@@ -168,15 +168,15 @@ pub fn generate_amenities(
168168
let bresenham_points: Vec<(i32, i32, i32)> =
169169
bresenham_line(prev.x, prev_y, prev.z, pt.x, y, pt.z);
170170
for (bx, by, bz) in bresenham_points {
171-
editor.set_block(block_type, bx, by, bz, Some(&[BLACK_CONCRETE]), None);
171+
editor.set_block(block_type, bx, by, bz, Some(&[BLOCKS.by_name("black_concrete").unwrap()]), None);
172172

173173
// Decorative border around fountains
174174
if amenity_type == "fountain" {
175175
for dx in [-1, 0, 1].iter() {
176176
for dz in [-1, 0, 1].iter() {
177177
if (*dx, *dz) != (0, 0) {
178178
editor.set_block(
179-
LIGHT_GRAY_CONCRETE,
179+
BLOCKS.by_name("light_gray_concrete").unwrap(),
180180
bx + dx,
181181
by,
182182
bz + dz,
@@ -211,18 +211,18 @@ pub fn generate_amenities(
211211
x,
212212
y,
213213
z,
214-
Some(&[BLACK_CONCRETE, GRAY_CONCRETE]),
214+
Some(&[BLOCKS.by_name("black_concrete").unwrap(), BLOCKS.by_name("gray_concrete").unwrap()]),
215215
None,
216216
);
217217

218218
// Add parking spot markings
219219
if amenity_type == "parking" && (x + z) % 8 == 0 && (x * z) % 32 != 0 {
220220
editor.set_block(
221-
LIGHT_GRAY_CONCRETE,
221+
BLOCKS.by_name("light_gray_concrete").unwrap(),
222222
x,
223223
y,
224224
z,
225-
Some(&[BLACK_CONCRETE, GRAY_CONCRETE]),
225+
Some(&[BLOCKS.by_name("black_concrete").unwrap(), BLOCKS.by_name("gray_concrete").unwrap()]),
226226
None,
227227
);
228228
}

src/element_processing/barriers.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use crate::world_editor::WorldEditor;
77

88
pub fn generate_barriers(editor: &mut WorldEditor, element: &ProcessedElement, ground: &Ground) {
99
// Default values
10-
let mut barrier_material: Block = COBBLESTONE_WALL;
10+
let mut barrier_material = BLOCKS.by_name("cobblestone_wall").unwrap();
1111
let mut barrier_height: i32 = 2;
1212

1313
match element.tags().get("barrier").map(|s| s.as_str()) {
1414
Some("bollard") => {
1515
if let ProcessedElement::Node(node) = element {
1616
editor.set_block(
17-
COBBLESTONE_WALL,
17+
BLOCKS.by_name("cobblestone_wall").unwrap(),
1818
node.x,
1919
ground.level(node.xz()) + 1,
2020
node.z,
@@ -30,34 +30,34 @@ pub fn generate_barriers(editor: &mut WorldEditor, element: &ProcessedElement, g
3030
return;
3131
}
3232
Some("hedge") => {
33-
barrier_material = OAK_LEAVES;
33+
barrier_material = BLOCKS.by_name("oak_leaves").unwrap();
3434
barrier_height = 2;
3535
}
3636
Some("fence") => {
3737
// Handle fence sub-types
3838
match element.tags().get("fence_type").map(|s| s.as_str()) {
3939
Some("railing" | "bars" | "krest") => {
40-
barrier_material = STONE_BRICK_WALL;
40+
barrier_material = BLOCKS.by_name("stone_brick_wall").unwrap();
4141
barrier_height = 1;
4242
}
4343
Some("chain_link" | "metal" | "wire" | "barbed_wire" | "corrugated_metal") => {
44-
barrier_material = STONE_BRICK_WALL;
44+
barrier_material = BLOCKS.by_name("stone_brick_wall").unwrap();
4545
barrier_height = 2;
4646
}
4747
Some("slatted" | "paling") => {
48-
barrier_material = OAK_FENCE;
48+
barrier_material = BLOCKS.by_name("oak_fence").unwrap();
4949
barrier_height = 1;
5050
}
5151
Some("wood" | "split_rail" | "panel" | "pole") => {
52-
barrier_material = OAK_FENCE;
52+
barrier_material = BLOCKS.by_name("oak_fence").unwrap();
5353
barrier_height = 2;
5454
}
5555
Some("concrete") => {
56-
barrier_material = ANDESITE_WALL;
56+
barrier_material = BLOCKS.by_name("andesite_wall").unwrap();
5757
barrier_height = 2;
5858
}
5959
Some("glass") => {
60-
barrier_material = GLASS;
60+
barrier_material = BLOCKS.by_name("glass").unwrap();
6161
barrier_height = 1;
6262
}
6363
_ => {}
@@ -68,7 +68,7 @@ pub fn generate_barriers(editor: &mut WorldEditor, element: &ProcessedElement, g
6868
// Tagged material takes priority over inferred
6969
if let Some(barrier_mat) = element.tags().get("material") {
7070
if barrier_mat == "brick" {
71-
barrier_material = BRICK;
71+
barrier_material = BLOCKS.by_name("brick").unwrap();
7272
}
7373
}
7474

@@ -105,7 +105,7 @@ pub fn generate_barriers(editor: &mut WorldEditor, element: &ProcessedElement, g
105105
// Add an optional top to the barrier if the height is more than 1
106106
if wall_height > 1 {
107107
editor.set_block(
108-
STONE_BRICK_SLAB,
108+
BLOCKS.by_name("stone_brick_slab").unwrap(),
109109
bx,
110110
ground_level + wall_height + 1,
111111
bz,

src/element_processing/bridges.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn generate_bridges(editor: &mut WorldEditor, element: &ProcessedWay, ground
3434

3535
// Place bridge blocks
3636
for dx in -2..=2 {
37-
editor.set_block(LIGHT_GRAY_CONCRETE, *x + dx, bridge_y, *z, None, None);
37+
editor.set_block(BLOCKS.by_name("light_gray_concrete").unwrap(), *x + dx, bridge_y, *z, None, None);
3838
}
3939
}
4040
}

0 commit comments

Comments
 (0)