mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-24 06:51:30 +11:00
Make replaceable blocks place correctly in the building example. (#129)
Closes #114 Note that this is a band-aid solution to a more general problem. In the future, there should be a function in the `block` module to handle all these placement rules.
This commit is contained in:
parent
ce457a3d20
commit
f4d36554d7
|
@ -200,13 +200,22 @@ impl Config for Game {
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
if hand == Hand::Main {
|
if hand == Hand::Main {
|
||||||
let place_at = location.get_in_direction(face);
|
|
||||||
if let Some(stack) = client.held_item() {
|
if let Some(stack) = client.held_item() {
|
||||||
if let Some(block_kind) = stack.item.to_block_kind() {
|
if let Some(held_block_kind) = stack.item.to_block_kind() {
|
||||||
world.chunks.set_block_state(
|
let block_to_place = BlockState::from_kind(held_block_kind);
|
||||||
place_at,
|
|
||||||
BlockState::from_kind(block_kind),
|
if world
|
||||||
);
|
.chunks
|
||||||
|
.block_state(location)
|
||||||
|
.map(|s| s.is_replaceable())
|
||||||
|
.unwrap_or(false)
|
||||||
|
{
|
||||||
|
world.chunks.set_block_state(location, block_to_place);
|
||||||
|
} else {
|
||||||
|
let place_at = location.get_in_direction(face);
|
||||||
|
world.chunks.set_block_state(place_at, block_to_place);
|
||||||
|
}
|
||||||
|
|
||||||
if client.game_mode() != GameMode::Creative {
|
if client.game_mode() != GameMode::Creative {
|
||||||
client.consume_one_held_item();
|
client.consume_one_held_item();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue