-
-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue #574 "All torches place in a wall state" #618
Closed
Closed
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
12cee7d
add a vertical attachment type and register a torch block
lwalton101 129eac0
remove unused imports
lwalton101 403eb02
added redstone torch to manager
lwalton101 b344532
register soul torches as a vertical attachment block
lwalton101 c38ba61
fix redstone torch facing by adding lit block state
lwalton101 c852053
remove unused import
lwalton101 2e31ca1
remove debug statement
lwalton101 b8eea0b
remove unused import again
lwalton101 23ccd5a
use clippy too many arguments for on_place
lwalton101 7472a0b
actually allow clippy too many arguments for on_place
lwalton101 b859565
cargo fmt
lwalton101 f6ace1d
Merge remote-tracking branch 'origin/master' into torch-direction-fix
lwalton101 c0bbb13
fix torches, but only torches
lwalton101 6eb2f67
remove unused imports
lwalton101 c2007ef
remove old lit component
lwalton101 a94adb0
all torches work
lwalton101 e135241
remove unused imports
lwalton101 c065a7e
cargo fmt
lwalton101 1de8ad2
Update branch to be up to date with main on Pumpkin-MC/Pumpkin
lwalton101 ed5b03f
remove leftover file from before property revamp
lwalton101 6b2be44
Merge remote-tracking branch 'origin/torch-direction-fix' into torch-…
lwalton101 c41dd94
fix clippy
lwalton101 c33c53b
fix clippy
lwalton101 db80634
remove as much duplication as possible
lwalton101 4adce4c
cargo fmt
lwalton101 2e2d2e2
remove underscore from _face
lwalton101 6d696ce
cargo fmt
lwalton101 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
use async_trait::async_trait; | ||
use log::error; | ||
use pumpkin_data::block::{ | ||
Block, BlockProperties, EnumVariants, FurnaceLikeProperties, HorizontalFacing, | ||
WallTorchLikeProperties, | ||
}; | ||
use pumpkin_macros::pumpkin_block; | ||
use pumpkin_protocol::server::play::SUseItemOn; | ||
use pumpkin_util::math::position::BlockPos; | ||
use pumpkin_world::block::BlockDirection; | ||
|
||
use crate::{block::pumpkin_block::PumpkinBlock, server::Server, world::World}; | ||
|
||
#[pumpkin_block("minecraft:torch")] | ||
pub struct TorchBlock; | ||
#[pumpkin_block("minecraft:redstone_torch")] | ||
pub struct RedstoneTorchBlock; | ||
#[pumpkin_block("minecraft:soul_torch")] | ||
pub struct SoulTorchBlock; | ||
#[async_trait] | ||
impl PumpkinBlock for TorchBlock { | ||
async fn on_place( | ||
&self, | ||
_server: &Server, | ||
world: &World, | ||
block: &Block, | ||
face: &BlockDirection, | ||
block_pos: &BlockPos, | ||
_use_item_on: &SUseItemOn, | ||
player_direction: &HorizontalFacing, | ||
_other: bool, | ||
) -> u16 { | ||
if face == &BlockDirection::Down { | ||
block.default_state_id | ||
} else { | ||
let props = get_wall_block_props( | ||
world, | ||
block, | ||
block_pos, | ||
face, | ||
player_direction, | ||
WallTorchLikeProperties::default(&Block::WALL_TORCH).to_props(), | ||
) | ||
.await; | ||
WallTorchLikeProperties::from_props(props, &Block::WALL_TORCH) | ||
.to_state_id(&Block::WALL_TORCH) | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl PumpkinBlock for RedstoneTorchBlock { | ||
async fn on_place( | ||
&self, | ||
_server: &Server, | ||
world: &World, | ||
block: &Block, | ||
face: &BlockDirection, | ||
block_pos: &BlockPos, | ||
_use_item_on: &SUseItemOn, | ||
player_direction: &HorizontalFacing, | ||
_other: bool, | ||
) -> u16 { | ||
if face == &BlockDirection::Down { | ||
block.default_state_id | ||
} else { | ||
let props = get_wall_block_props( | ||
world, | ||
block, | ||
block_pos, | ||
face, | ||
player_direction, | ||
FurnaceLikeProperties::default(&Block::REDSTONE_WALL_TORCH).to_props(), | ||
) | ||
.await; | ||
FurnaceLikeProperties::from_props(props, &Block::REDSTONE_WALL_TORCH) | ||
.to_state_id(&Block::REDSTONE_WALL_TORCH) | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl PumpkinBlock for SoulTorchBlock { | ||
async fn on_place( | ||
&self, | ||
_server: &Server, | ||
world: &World, | ||
block: &Block, | ||
face: &BlockDirection, | ||
block_pos: &BlockPos, | ||
_use_item_on: &SUseItemOn, | ||
player_direction: &HorizontalFacing, | ||
_other: bool, | ||
) -> u16 { | ||
if face == &BlockDirection::Down { | ||
block.default_state_id | ||
} else { | ||
let props = get_wall_block_props( | ||
world, | ||
block, | ||
block_pos, | ||
face, | ||
player_direction, | ||
WallTorchLikeProperties::default(&Block::SOUL_WALL_TORCH).to_props(), | ||
) | ||
.await; | ||
WallTorchLikeProperties::from_props(props, &Block::SOUL_WALL_TORCH) | ||
.to_state_id(&Block::SOUL_WALL_TORCH) | ||
} | ||
} | ||
} | ||
async fn get_wall_block_props( | ||
world: &World, | ||
block: &Block, | ||
block_pos: &BlockPos, | ||
face: &BlockDirection, | ||
player_direction: &HorizontalFacing, | ||
mut block_properties: Vec<(String, String)>, | ||
) -> Vec<(String, String)> { | ||
let contains_facing = block_properties.iter().any(|(key, _)| key == "facing"); | ||
|
||
if !contains_facing { | ||
error!("Cannot find facing property in block {}", block.name); | ||
return Block::AIR | ||
.properties(Block::AIR.default_state_id) | ||
.unwrap() | ||
.to_props(); | ||
} | ||
|
||
let facing_index = block_properties | ||
.iter() | ||
.position(|(key, _)| key == "facing") | ||
.unwrap(); | ||
|
||
match face { | ||
BlockDirection::North | ||
| BlockDirection::South | ||
| BlockDirection::West | ||
| BlockDirection::East => { | ||
block_properties[facing_index].1 = face | ||
.to_cardinal_direction() | ||
.opposite() | ||
.to_value() | ||
.to_string(); | ||
return block_properties; | ||
} | ||
BlockDirection::Up => { | ||
let mut possible_directions = vec![]; | ||
for bd in BlockDirection::horizontal() { | ||
let block_offset = bd.to_offset(); | ||
let base_block_pos = block_pos.offset(block_offset); | ||
let base_block = world.get_block(&base_block_pos).await.unwrap(); | ||
if base_block.id != 0 { | ||
possible_directions.push(bd.to_cardinal_direction()); | ||
} | ||
} | ||
|
||
return if possible_directions.contains(player_direction) { | ||
block_properties[facing_index].1 = | ||
player_direction.opposite().to_value().to_string(); | ||
block_properties | ||
} else if possible_directions.is_empty() { | ||
block_properties[facing_index].1 = | ||
possible_directions[0].opposite().to_value().to_string(); | ||
block_properties | ||
} else { | ||
Block::AIR | ||
.properties(Block::AIR.default_state_id) | ||
.unwrap() | ||
.to_props() | ||
}; | ||
} | ||
BlockDirection::Down => {} | ||
} | ||
|
||
block_properties | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of serializing the block properties, you should mutate the
LikeProperties
struct itself, which contains enums of valid states.