99 broken blocks in the world, 99 brocken blocks. Track one down, patch it around, 100 broken blocks in the world.

This commit is contained in:
Scetch 2016-03-30 09:22:52 -04:00
parent bb1f10dd1b
commit 35d9a2aefa
2 changed files with 389 additions and 272 deletions

View File

@ -176,7 +176,7 @@ impl Server {
for z in -7*16 .. 7*16 {
let h = rng.gen_range(3, 10);
for y in 0 .. h {
server.world.set_block(x, y, z, block::Dirt{});
server.world.set_block(x, y, z, block::Dirt{ snowy: false, variant: block::DirtVariant::Normal });
}
}
}

View File

@ -1,3 +1,14 @@
// TODO: Multipart blocks
// TODO: Tile entities
// TODO: Redstone
// TODO: Skulls
// TODO: FlowerPot
// TODO: Repeater lock state update
// TODO: DoublePlants don't face the right direction?
// TODO: Pumpkin and Melon stem tint
// TODO: Tripwire
// TODO: Portal Axis
use std::fmt::{Display, Formatter, Error};
use collision::{Aabb, Aabb3};
use cgmath::Point3;
@ -327,9 +338,25 @@ define_blocks! {
model { ("minecraft", "grass") },
variant format!("snowy={}", snowy),
tint TintType::Grass,
update_state (world, x, y, z) => {
Block::Grass{
snowy: match world.get_block(x, y + 1, z) {
Block::Snow { .. } | Block::SnowLayer { .. } => true,
_ => false,
}
}
},
}
Dirt {
props {},
props {
snowy: bool = [false, true],
variant: DirtVariant = [
DirtVariant::Normal,
DirtVariant::Coarse,
DirtVariant::Podzol
],
},
data if !snowy { Some(variant.data()) } else { None },
material Material {
renderable: true,
never_cull: false,
@ -337,7 +364,25 @@ define_blocks! {
force_shade: false,
transparent: false,
},
model { ("minecraft", "dirt" ) },
model { ("minecraft", variant.as_string()) },
variant {
if variant == DirtVariant::Podzol {
format!("snowy={}", snowy)
} else {
"normal".to_owned()
}
},
update_state (world, x, y, z) => if variant == DirtVariant::Podzol {
Block::Dirt{
snowy: match world.get_block(x, y + 1, z) {
Block::Snow{ .. } | Block::SnowLayer { .. } => true,
_ => false,
},
variant: variant
}
} else {
Block::Dirt{snowy: snowy, variant: variant}
},
}
Cobblestone {
props {},
@ -392,6 +437,7 @@ define_blocks! {
transparent: false,
},
model { ("minecraft", format!("{}_sapling", variant.as_string()) ) },
variant format!("stage={}", stage),
}
Bedrock {
props {},
@ -893,7 +939,9 @@ define_blocks! {
Direction::East => 0x5,
_ => unreachable!(),
} | if variant == PistonType::Sticky { 0x8 } else { 0x0 }
)} else { None },
)} else {
None
},
material Material {
renderable: true,
never_cull: false,
@ -948,8 +996,7 @@ define_blocks! {
model { ("minecraft", "piston_extension") },
}
YellowFlower {
props { // TODO: Define dandelion? Condense all flower types into one enum?
},
props {},
material Material {
renderable: true,
never_cull: false,
@ -957,8 +1004,7 @@ define_blocks! {
force_shade: false,
transparent: false,
},
model { ("minecraft", "yellow_flower" ) },
variant "type=dandelion",
model { ("minecraft", "dandelion") },
}
RedFlower {
props {
@ -982,8 +1028,7 @@ define_blocks! {
force_shade: false,
transparent: false,
},
model { ("minecraft", "red_flower" ) },
variant format!("type={}", variant.as_string()),
model { ("minecraft", variant.as_string()) },
}
BrownMushroom {
props {},
@ -1198,7 +1243,6 @@ define_blocks! {
transparent: false,
},
model { ("minecraft", "fire") },
variant format!("age={},up={},north={},south={},east={},west={}", age, up, north, south, east, west),
}
MobSpawner {
props {},
@ -1219,7 +1263,7 @@ define_blocks! {
Direction::East,
Direction::West
],
half: StairHalf = [StairHalf::Top, StairHalf::Bottom],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
shape: StairShape = [
StairShape::Straight,
StairShape::InnerLeft, StairShape::InnerRight,
@ -1264,7 +1308,6 @@ define_blocks! {
transparent: false,
},
model { ("minecraft", "chest") },
variant format!("facing={}", facing.as_string()),
}
RedstoneWire {
props {
@ -1440,7 +1483,6 @@ define_blocks! {
transparent: false,
},
model { ("minecraft", "standing_sign") },
variant format!("rotation={}", rotation.as_string()),
}
WoodenDoor {
props {
@ -1473,17 +1515,17 @@ define_blocks! {
Ladder {
props {
facing: Direction = [
Direction::North,
Direction::South,
Direction::East,
Direction::West
Direction::West,
Direction::North,
Direction::East
],
},
data {
Some(match facing {
Direction::North => 2,
Direction::South => 3,
Direction::West => 4,
Direction::South => 2,
Direction::West => 3,
Direction::North => 4,
Direction::East => 5,
_ => 2,
})
@ -1532,7 +1574,7 @@ define_blocks! {
Direction::East,
Direction::West
],
half: StairHalf = [StairHalf::Top, StairHalf::Bottom],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
shape: StairShape = [
StairShape::Straight,
StairShape::InnerLeft, StairShape::InnerRight,
@ -1854,6 +1896,7 @@ define_blocks! {
transparent: false,
},
model { ("minecraft", "reeds") },
tint TintType::Foliage,
}
Jukebox {
props {
@ -1868,7 +1911,6 @@ define_blocks! {
transparent: false,
},
model { ("minecraft", "jukebox") },
variant format!("has_record={}", has_record),
}
Fence {
props {
@ -1965,6 +2007,16 @@ define_blocks! {
},
model { ("minecraft", "portal") },
variant format!("axis={}", axis.as_string()),
update_state (world, x, y, z) => {
let axis = match (world.get_block(x - 1, y, z), world.get_block(x + 1, y, z),
world.get_block(x, y, z - 1), world.get_block(x, y, z + 1)) {
(Block::Portal{ .. }, _, _, _) | (_, Block::Portal{ .. }, _, _) => Axis::X,
(_, _, Block::Portal{ .. }, _) | (_, _, _, Block::Portal{ .. }) => Axis::Z,
_ => Axis::X,
};
Block::Portal{axis: axis}
},
}
PumpkinLit {
props {
@ -2014,7 +2066,7 @@ define_blocks! {
}
RepeaterUnpowered {
props {
delay: i32 = [0, 1, 2, 3],
delay: i32 = [1, 2, 3, 4],
facing: Direction = [
Direction::North,
Direction::East,
@ -2032,7 +2084,7 @@ define_blocks! {
_ => unreachable!(),
};
Some(data | (delay as usize) << 2)
Some(data | (delay as usize - 1) << 2)
} else {
None
},
@ -2048,7 +2100,7 @@ define_blocks! {
}
RepeaterPowered {
props {
delay: i32 = [0, 1, 2, 3],
delay: i32 = [1, 2, 3, 4],
facing: Direction = [
Direction::North,
Direction::South,
@ -2066,7 +2118,7 @@ define_blocks! {
_ => unreachable!(),
};
Some(data | (delay as usize) << 2)
Some(data | (delay as usize - 1) << 2)
} else {
None
},
@ -2116,8 +2168,8 @@ define_blocks! {
facing: Direction = [
Direction::North,
Direction::South,
Direction::East,
Direction::West
Direction::West,
Direction::East
],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
open: bool = [false, true],
@ -2286,14 +2338,14 @@ define_blocks! {
props {
age: i32 = [0, 1, 2, 3, 4, 5, 6, 7],
facing: Direction = [
Direction::Up,
Direction::North,
Direction::South,
Direction::East,
Direction::West,
Direction::Up
Direction::West
],
},
data if facing == Direction::North { Some(age as usize) } else { None },
data if facing == Direction::Up { Some(age as usize) } else { None },
material Material {
renderable: true,
never_cull: false,
@ -2302,7 +2354,26 @@ define_blocks! {
transparent: false,
},
model { ("minecraft", "pumpkin_stem") },
variant format!("age={},facing={}", age, facing.as_string()),
variant {
if facing == Direction::Up {
format!("age={},facing={}", age, facing.as_string())
} else {
format!("facing={}", facing.as_string())
}
},
tint TintType::Foliage,
update_state (world, x, y, z) => {
let facing = match (world.get_block(x - 1, y, z), world.get_block(x + 1, y, z),
world.get_block(x, y, z - 1), world.get_block(x, y, z + 1)) {
(Block::Pumpkin{ .. }, _, _, _) => Direction::East,
(_, Block::Pumpkin{ .. }, _, _) => Direction::West,
(_, _, Block::Pumpkin{ .. }, _) => Direction::North,
(_, _, _, Block::Pumpkin{ .. }) => Direction::South,
_ => Direction::Up,
};
Block::PumpkinStem{age: age, facing: facing}
},
}
MelonStem {
props {
@ -2324,7 +2395,26 @@ define_blocks! {
transparent: false,
},
model { ("minecraft", "melon_stem") },
variant format!("age={},facing={}", age, facing.as_string()),
variant {
if facing == Direction::Up {
format!("age={},facing={}", age, facing.as_string())
} else {
format!("facing={}", facing.as_string())
}
},
tint TintType::Foliage,
update_state (world, x, y, z) => {
let facing = match (world.get_block(x - 1, y, z), world.get_block(x + 1, y, z),
world.get_block(x, y, z - 1), world.get_block(x, y, z + 1)) {
(Block::MelonBlock{ .. }, _, _, _) => Direction::East,
(_, Block::MelonBlock{ .. }, _, _) => Direction::West,
(_, _, Block::MelonBlock{ .. }, _) => Direction::North,
(_, _, _, Block::MelonBlock{ .. }) => Direction::South,
_ => Direction::Up,
};
Block::MelonStem{age: age, facing: facing}
},
}
Vine {
props {
@ -2384,7 +2474,7 @@ define_blocks! {
Direction::East,
Direction::West
],
half: StairHalf = [StairHalf::Top, StairHalf::Bottom],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
shape: StairShape = [
StairShape::Straight,
StairShape::InnerLeft, StairShape::InnerRight,
@ -2411,7 +2501,7 @@ define_blocks! {
Direction::East,
Direction::West
],
half: StairHalf = [StairHalf::Top, StairHalf::Bottom],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
shape: StairShape = [
StairShape::Straight,
StairShape::InnerLeft, StairShape::InnerRight,
@ -2493,7 +2583,7 @@ define_blocks! {
Direction::East,
Direction::West
],
half: StairHalf = [StairHalf::Top, StairHalf::Bottom],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
shape: StairShape = [
StairShape::Straight,
StairShape::InnerLeft, StairShape::InnerRight,
@ -2741,7 +2831,7 @@ define_blocks! {
Direction::East,
Direction::West
],
half: StairHalf = [StairHalf::Top, StairHalf::Bottom],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
shape: StairShape = [
StairShape::Straight,
StairShape::InnerLeft, StairShape::InnerRight,
@ -2837,9 +2927,9 @@ define_blocks! {
props {
attached: bool = [false, true],
disarmed: bool = [false, true],
east: bool = [false, true],
north: bool = [false, true],
south: bool = [false, true],
east: bool = [false, true],
west: bool = [false, true],
powered: bool = [false, true],
},
@ -2860,7 +2950,7 @@ define_blocks! {
transparent: false,
},
model { ("minecraft", "tripwire") },
variant format!("attached={},disarmed={},north={},south={},east={},west={},powered={}", attached, disarmed, north, south, east, west, powered),
variant format!("attached={},east={},north={},south={},west={}", attached, east, north, south, west),
}
EmeraldBlock {
props {},
@ -2881,7 +2971,7 @@ define_blocks! {
Direction::East,
Direction::West
],
half: StairHalf = [StairHalf::Top, StairHalf::Bottom],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
shape: StairShape = [
StairShape::Straight,
StairShape::InnerLeft, StairShape::InnerRight,
@ -2908,7 +2998,7 @@ define_blocks! {
Direction::East,
Direction::West
],
half: StairHalf = [StairHalf::Top, StairHalf::Bottom],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
shape: StairShape = [
StairShape::Straight,
StairShape::InnerLeft, StairShape::InnerRight,
@ -2935,7 +3025,7 @@ define_blocks! {
Direction::East,
Direction::West
],
half: StairHalf = [StairHalf::Top, StairHalf::Bottom],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
shape: StairShape = [
StairShape::Straight,
StairShape::InnerLeft, StairShape::InnerRight,
@ -3375,7 +3465,7 @@ define_blocks! {
transparent: false,
},
model { ("minecraft", "hopper") },
variant format!("enabled={},facing={}", enabled, facing.as_string()),
variant format!("facing={}", facing.as_string()),
}
QuartzBlock {
props {
@ -3418,7 +3508,7 @@ define_blocks! {
Direction::East,
Direction::West
],
half: StairHalf = [StairHalf::Top, StairHalf::Bottom],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
shape: StairShape = [
StairShape::Straight,
StairShape::InnerLeft, StairShape::InnerRight,
@ -3493,7 +3583,7 @@ define_blocks! {
transparent: false,
},
model { ("minecraft", "dropper") },
variant format!("facing={},triggered={}", facing.as_string(), triggered),
variant format!("facing={}", facing.as_string()),
}
StainedHardenedClay {
props {
@ -3606,7 +3696,7 @@ define_blocks! {
Direction::East,
Direction::West
],
half: StairHalf = [StairHalf::Top, StairHalf::Bottom],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
shape: StairShape = [
StairShape::Straight,
StairShape::InnerLeft, StairShape::InnerRight,
@ -3633,7 +3723,7 @@ define_blocks! {
Direction::East,
Direction::West
],
half: StairHalf = [StairHalf::Top, StairHalf::Bottom],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
shape: StairShape = [
StairShape::Straight,
StairShape::InnerLeft, StairShape::InnerRight,
@ -3679,8 +3769,8 @@ define_blocks! {
facing: Direction = [
Direction::North,
Direction::South,
Direction::East,
Direction::West
Direction::West,
Direction::East
],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
open: bool = [false, true],
@ -3701,7 +3791,7 @@ define_blocks! {
material Material {
renderable: true,
never_cull: false,
should_cull_against: true,
should_cull_against: false,
force_shade: false,
transparent: false,
},
@ -3739,9 +3829,9 @@ define_blocks! {
}
HayBlock {
props {
axis: Axis = [Axis::X, Axis::Y, Axis::Z],
axis: Axis = [Axis::Y, Axis::Z, Axis::X],
},
data if axis == Axis::X { Some(0) } else { None },
data if axis == Axis::Y { Some(0) } else { None },
material Material {
renderable: true,
never_cull: false,
@ -3750,6 +3840,7 @@ define_blocks! {
transparent: false,
},
model { ("minecraft", "hay_block") },
variant format!("axis={}", axis.as_string()),
}
Carpet {
props {
@ -3817,24 +3908,21 @@ define_blocks! {
}
DoublePlant {
props {
half: DoorHalf = [DoorHalf::Upper, DoorHalf::Lower],
half: BlockHalf = [BlockHalf::Lower, BlockHalf::Upper],
variant: DoublePlantVariant = [
DoublePlantVariant::Sunflower,
DoublePlantVariant::Lilac,
DoublePlantVariant::DoubleTallgrass,
DoublePlantVariant::LargeFern,
DoublePlantVariant::RoseBush,
DoublePlantVariant::Peony
],
facing: Direction = [
Direction::North,
Direction::South,
Direction::East,
Direction::West
],
},
data if facing == Direction::North {
Some((if half == DoorHalf::Upper { 0x8 } else { 0x0 }) | variant.data())
} else { None },
data if half == BlockHalf::Lower || variant == DoublePlantVariant::Sunflower {
Some(variant.data() | (if half == BlockHalf::Upper { 0x8 } else { 0x0 }))
} else {
None
},
material Material {
renderable: true,
never_cull: false,
@ -3842,8 +3930,13 @@ define_blocks! {
force_shade: false,
transparent: false,
},
model { ("minecraft", "double_plant" ) },
variant format!("half={},variant={},facing={}", half.as_string(), variant.as_string(), facing.as_string()),
model { ("minecraft", variant.as_string()) },
variant format!("half={}", half.as_string()),
tint TintType::Foliage,
update_state (world, x, y, z) => {
let (half, variant) = update_double_plant_state(world, x, y, z, half, variant);
Block::DoublePlant{half: half, variant: variant}
},
}
StandingBanner {
props {
@ -3934,8 +4027,7 @@ define_blocks! {
force_shade: false,
transparent: false,
},
model { ("minecraft", "red_sandstone" ) },
variant format!("type={}", variant.as_string()),
model { ("minecraft", variant.as_string()) },
}
RedSandstoneStairs {
props {
@ -3945,7 +4037,7 @@ define_blocks! {
Direction::East,
Direction::West
],
half: StairHalf = [StairHalf::Top, StairHalf::Bottom],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
shape: StairShape = [
StairShape::Straight,
StairShape::InnerLeft, StairShape::InnerRight,
@ -4438,7 +4530,7 @@ define_blocks! {
Direction::East,
Direction::West
],
half: StairHalf = [StairHalf::Top, StairHalf::Bottom],
half: BlockHalf = [BlockHalf::Top, BlockHalf::Bottom],
shape: StairShape = [
StairShape::Straight,
StairShape::InnerLeft, StairShape::InnerRight,
@ -4490,7 +4582,7 @@ define_blocks! {
transparent: false,
},
model { ("minecraft", format!("{}_slab", variant.as_string()) ) },
variant format!("half={}", half.as_string()),
variant format!("half={},variant=default", half.as_string()),
}
EndBricks {
props {},
@ -4656,14 +4748,13 @@ fn door_data(facing: Direction, half: DoorHalf, hinge: Side, open: bool, powered
}
}
fn update_door_state(world: &super::World, x: i32, y: i32, z: i32, ohalf: DoorHalf, ofacing: Direction, ohinge: Side, oopen: bool, opowered: bool) -> (Direction, Side, bool, bool) {
let oy = if ohalf == DoorHalf::Upper {
-1
} else {
1
};
match world.get_block(x, y + oy, z) {
Block::WoodenDoor{half, facing, hinge, open, powered} |
Block::SpruceDoor{half, facing, hinge, open, powered} |
@ -4682,9 +4773,21 @@ fn update_door_state(world: &super::World, x: i32, y: i32, z: i32, ohalf: DoorHa
},
_ => {},
}
(ofacing, ohinge, oopen, opowered)
}
fn update_double_plant_state(world: &super::World, x: i32, y: i32, z: i32, ohalf: BlockHalf, ovariant: DoublePlantVariant) -> (BlockHalf, DoublePlantVariant) {
if ohalf != BlockHalf::Upper {
return (ohalf, ovariant);
}
match world.get_block(x, y - 1, z) {
Block::DoublePlant{half, variant} => (ohalf, variant),
_ => (ohalf, ovariant),
}
}
fn command_block_data(conditional: bool, facing: Direction) -> Option<usize> {
let data = match facing {
Direction::Down => 0,
@ -4717,7 +4820,7 @@ impl Display for StoneVariant {
}
impl StoneVariant {
fn as_string(&self) -> &'static str {
pub fn as_string(&self) -> &'static str {
match *self {
StoneVariant::Normal => "stone",
StoneVariant::Granite => "granite",
@ -4741,6 +4844,31 @@ impl StoneVariant {
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum DirtVariant {
Normal,
Coarse,
Podzol,
}
impl DirtVariant {
pub fn as_string(&self) -> &'static str {
match *self {
DirtVariant::Normal => "dirt",
DirtVariant::Coarse => "coarse_dirt",
DirtVariant::Podzol => "podzol",
}
}
fn data(&self) -> usize {
match *self {
DirtVariant::Normal => 0,
DirtVariant::Coarse => 1,
DirtVariant::Podzol => 2,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum BedPart {
Head,
@ -5333,6 +5461,8 @@ impl WoodSlabVariant {
pub enum BlockHalf {
Top,
Bottom,
Upper,
Lower,
}
impl BlockHalf {
@ -5340,6 +5470,8 @@ impl BlockHalf {
match *self {
BlockHalf::Top => "top",
BlockHalf::Bottom => "bottom",
BlockHalf::Upper => "upper",
BlockHalf::Lower => "lower",
}
}
}
@ -5458,21 +5590,6 @@ impl Axis {
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum StairHalf {
Top,
Bottom,
}
impl StairHalf {
pub fn as_string(&self) -> &'static str {
match *self {
StairHalf::Top => "top",
StairHalf::Bottom => "bottom",
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum StairShape {
Straight,
@ -5494,7 +5611,7 @@ impl StairShape {
}
}
fn get_stair_info(world: &super::World, x: i32, y: i32, z: i32) -> Option<(Direction, StairHalf)> {
fn get_stair_info(world: &super::World, x: i32, y: i32, z: i32) -> Option<(Direction, BlockHalf)> {
use self::Block::*;
match world.get_block(x, y, z) {
OakStairs{facing, half, ..} |
@ -5541,7 +5658,7 @@ fn update_stair_shape(world: &super::World, x: i32, y: i32, z: i32, facing: Dire
StairShape::Straight
}
fn stair_data(facing: Direction, half: StairHalf, shape: StairShape) -> Option<usize> {
fn stair_data(facing: Direction, half: BlockHalf, shape: StairShape) -> Option<usize> {
if shape != StairShape::Straight {
return None;
}
@ -5554,7 +5671,7 @@ fn stair_data(facing: Direction, half: StairHalf, shape: StairShape) -> Option<u
_ => unreachable!(),
};
Some(data | (if half == StairHalf::Top { 0x4 } else { 0x0 }))
Some(data | (if half == BlockHalf::Top { 0x4 } else { 0x0 }))
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]