Skip to content

Commit

Permalink
Update all calls to the new API
Browse files Browse the repository at this point in the history
Yeah... this is a mess. I don't know if I like this.
  • Loading branch information
benjamin051000 committed Jan 26, 2025
1 parent c1c9961 commit 8af2e3b
Show file tree
Hide file tree
Showing 17 changed files with 399 additions and 838 deletions.
505 changes: 33 additions & 472 deletions src/block_definitions.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/data_processing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::args::Args;
use crate::block_definitions::{DIRT, GRASS_BLOCK, SNOW_BLOCK};
use crate::block_definitions::BLOCKS;
use crate::cartesian::XZPoint;
use crate::element_processing::*;
use crate::ground::Ground;
Expand Down Expand Up @@ -141,7 +141,7 @@ pub fn generate_world(
let total_iterations_grnd: f64 = (scale_factor_x + 1.0) * (scale_factor_z + 1.0);
let progress_increment_grnd: f64 = 30.0 / total_iterations_grnd;

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

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

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

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

block_counter += 1;
if block_counter % batch_size == 0 {
Expand Down
44 changes: 22 additions & 22 deletions src/element_processing/amenities.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::args::Args;
use crate::block_definitions::*;
use crate::block_definitions::BLOCKS;
use crate::bresenham::bresenham_line;
use crate::cartesian::XZPoint;
use crate::floodfill::flood_fill_area;
Expand Down Expand Up @@ -35,20 +35,20 @@ pub fn generate_amenities(
"waste_disposal" | "waste_basket" => {
// Place a cauldron for waste disposal or waste basket
if let Some(pt) = first_node {
editor.set_block(CAULDRON, pt.x, ground.level(pt) + 1, pt.z, None, None);
editor.set_block(BLOCKS.by_name("cauldron").unwrap(), pt.x, ground.level(pt) + 1, pt.z, None, None);
}
}
"vending_machine" | "atm" => {
if let Some(pt) = first_node {
let y = ground.level(pt);

editor.set_block(IRON_BLOCK, pt.x, y + 1, pt.z, None, None);
editor.set_block(IRON_BLOCK, pt.x, y + 2, pt.z, None, None);
editor.set_block(BLOCKS.by_name("iron_block").unwrap(), pt.x, y + 1, pt.z, None, None);
editor.set_block(BLOCKS.by_name("iron_block").unwrap(), pt.x, y + 2, pt.z, None, None);
}
}
"bicycle_parking" => {
let ground_block: Block = OAK_PLANKS;
let roof_block: Block = STONE_BLOCK_SLAB;
let ground_block = BLOCKS.by_name("oak_planks").unwrap();
let roof_block = BLOCKS.by_name("stone_block_slab").unwrap();

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

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

editor.set_block(SMOOTH_STONE, pt.x, y, pt.z, None, None);
editor.set_block(OAK_LOG, pt.x + 1, y, pt.z, None, None);
editor.set_block(OAK_LOG, pt.x - 1, y, pt.z, None, None);
editor.set_block(BLOCKS.by_name("smooth_stone").unwrap(), pt.x, y, pt.z, None, None);
editor.set_block(BLOCKS.by_name("oak_log").unwrap(), pt.x + 1, y, pt.z, None, None);
editor.set_block(BLOCKS.by_name("oak_log").unwrap(), pt.x - 1, y, pt.z, None, None);
}
}
"vending" => {
// Place vending machine blocks
if let Some(pt) = first_node {
let y = ground.level(pt);

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

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

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

let block_type = match amenity_type.as_str() {
"fountain" => WATER,
"parking" => GRAY_CONCRETE,
_ => GRAY_CONCRETE,
"fountain" => BLOCKS.by_name("water").unwrap(),
"parking" => BLOCKS.by_name("gray_concrete").unwrap(),
_ => BLOCKS.by_name("gray_concrete").unwrap(),
};

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

// Decorative border around fountains
if amenity_type == "fountain" {
for dx in [-1, 0, 1].iter() {
for dz in [-1, 0, 1].iter() {
if (*dx, *dz) != (0, 0) {
editor.set_block(
LIGHT_GRAY_CONCRETE,
BLOCKS.by_name("light_gray_concrete").unwrap(),
bx + dx,
by,
bz + dz,
Expand Down Expand Up @@ -211,18 +211,18 @@ pub fn generate_amenities(
x,
y,
z,
Some(&[BLACK_CONCRETE, GRAY_CONCRETE]),
Some(&[BLOCKS.by_name("black_concrete").unwrap(), BLOCKS.by_name("gray_concrete").unwrap()]),
None,
);

// Add parking spot markings
if amenity_type == "parking" && (x + z) % 8 == 0 && (x * z) % 32 != 0 {
editor.set_block(
LIGHT_GRAY_CONCRETE,
BLOCKS.by_name("light_gray_concrete").unwrap(),
x,
y,
z,
Some(&[BLACK_CONCRETE, GRAY_CONCRETE]),
Some(&[BLOCKS.by_name("black_concrete").unwrap(), BLOCKS.by_name("gray_concrete").unwrap()]),
None,
);
}
Expand Down
22 changes: 11 additions & 11 deletions src/element_processing/barriers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use crate::world_editor::WorldEditor;

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

match element.tags().get("barrier").map(|s| s.as_str()) {
Some("bollard") => {
if let ProcessedElement::Node(node) = element {
editor.set_block(
COBBLESTONE_WALL,
BLOCKS.by_name("cobblestone_wall").unwrap(),
node.x,
ground.level(node.xz()) + 1,
node.z,
Expand All @@ -30,34 +30,34 @@ pub fn generate_barriers(editor: &mut WorldEditor, element: &ProcessedElement, g
return;
}
Some("hedge") => {
barrier_material = OAK_LEAVES;
barrier_material = BLOCKS.by_name("oak_leaves").unwrap();
barrier_height = 2;
}
Some("fence") => {
// Handle fence sub-types
match element.tags().get("fence_type").map(|s| s.as_str()) {
Some("railing" | "bars" | "krest") => {
barrier_material = STONE_BRICK_WALL;
barrier_material = BLOCKS.by_name("stone_brick_wall").unwrap();
barrier_height = 1;
}
Some("chain_link" | "metal" | "wire" | "barbed_wire" | "corrugated_metal") => {
barrier_material = STONE_BRICK_WALL;
barrier_material = BLOCKS.by_name("stone_brick_wall").unwrap();
barrier_height = 2;
}
Some("slatted" | "paling") => {
barrier_material = OAK_FENCE;
barrier_material = BLOCKS.by_name("oak_fence").unwrap();
barrier_height = 1;
}
Some("wood" | "split_rail" | "panel" | "pole") => {
barrier_material = OAK_FENCE;
barrier_material = BLOCKS.by_name("oak_fence").unwrap();
barrier_height = 2;
}
Some("concrete") => {
barrier_material = ANDESITE_WALL;
barrier_material = BLOCKS.by_name("andesite_wall").unwrap();
barrier_height = 2;
}
Some("glass") => {
barrier_material = GLASS;
barrier_material = BLOCKS.by_name("glass").unwrap();
barrier_height = 1;
}
_ => {}
Expand All @@ -68,7 +68,7 @@ pub fn generate_barriers(editor: &mut WorldEditor, element: &ProcessedElement, g
// Tagged material takes priority over inferred
if let Some(barrier_mat) = element.tags().get("material") {
if barrier_mat == "brick" {
barrier_material = BRICK;
barrier_material = BLOCKS.by_name("brick").unwrap();
}
}

Expand Down Expand Up @@ -105,7 +105,7 @@ pub fn generate_barriers(editor: &mut WorldEditor, element: &ProcessedElement, g
// Add an optional top to the barrier if the height is more than 1
if wall_height > 1 {
editor.set_block(
STONE_BRICK_SLAB,
BLOCKS.by_name("stone_brick_slab").unwrap(),
bx,
ground_level + wall_height + 1,
bz,
Expand Down
2 changes: 1 addition & 1 deletion src/element_processing/bridges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn generate_bridges(editor: &mut WorldEditor, element: &ProcessedWay, ground

// Place bridge blocks
for dx in -2..=2 {
editor.set_block(LIGHT_GRAY_CONCRETE, *x + dx, bridge_y, *z, None, None);
editor.set_block(BLOCKS.by_name("light_gray_concrete").unwrap(), *x + dx, bridge_y, *z, None, None);
}
}
}
Expand Down
Loading

0 comments on commit 8af2e3b

Please sign in to comment.