-
-
Notifications
You must be signed in to change notification settings - Fork 136
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
Implemented Sign Editing Functionalities #262
base: master
Are you sure you want to change the base?
Conversation
pub enum SignType { | ||
OakSign = 194, | ||
SpruceSign = 195, | ||
BirchSign = 196, | ||
AcaciaSign = 197, | ||
CherrySign = 198, | ||
JungleSign = 199, | ||
DarkOakSign = 200, | ||
PaleOakSign = 201, | ||
MangroveSign = 202, | ||
BambooSign = 203, | ||
|
||
OakWallSign = 208, | ||
SpruceWallSign = 209, | ||
BirchWallSign = 210, | ||
AcaciaWallSign = 211, | ||
CherryWallSign = 212, | ||
JungleWallSign = 213, | ||
DarkOakWallSign = 214, | ||
PaleOakWallSign = 215, | ||
MangroveWallSign = 216, | ||
BambooWallSign = 217, | ||
|
||
OakHangingSign = 218, | ||
SpruceHangingSign = 219, | ||
BirchHangingSign = 220, | ||
AcaciaHangingSign = 221, | ||
CherryHangingSign = 222, | ||
JungleHangingSign = 223, | ||
DarkOakHangingSign = 224, | ||
PaleOakHangingSign = 225, | ||
CrimsonHangingSign = 226, | ||
WarpedHangingSign = 227, | ||
MangroveHangingSign = 228, | ||
BambooHangingSign = 229, | ||
|
||
OakWallHangingSign = 230, | ||
SprucWalleHangingSign = 231, | ||
BirchWallHangingSign = 232, | ||
AcaciaWallHangingSign = 233, | ||
CherryWallHangingSign = 234, | ||
JungleWallHangingSign = 235, | ||
DarkOakWallHangingSign = 236, | ||
PaleOakWallHangingSign = 237, | ||
CrimsonWallHangingSign = 238, | ||
WarpedWallHangingSign = 239, | ||
MangroveWallHangingSign = 240, | ||
BambooWallHangingSign = 241, | ||
|
||
CrimsonSign = 849, | ||
WarpedSign = 850, | ||
CrimsonWallSign = 851, | ||
WarpedWallSign = 852, | ||
} |
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.
This looks horrible, Also the the ID's will change with every Update
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.
Now looking at it again, it is. I will make sure to fix this.
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.
Added a macro that looks up the block entity id instead of the actual id and eliminated the mess.
pumpkin/src/entity/player.rs
Outdated
@@ -871,6 +873,9 @@ impl Player { | |||
SSwingArm::PACKET_ID => { | |||
self.handle_swing_arm(SSwingArm::read(bytebuf)?).await; | |||
} | |||
SUpdateSign::PACKET_ID => { | |||
//TODO |
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.
So this is empty, So Im predicting that Signs currently do not work right ?.
I recommend to make this a draft PR then when its still WIP
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.
In the game the sign updates with the text. I believe that this packet is suppose to update the server's nbt file--from what I have been reading. Couldn't test to see if another client sees the modified sign since I don't have another account.
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.
Figured it out, my bad. My latest commit implements the function that changes the sign for all clients by sending a client bound Block Entity Data packet.
pumpkin-macros/src/block_entity.rs
Outdated
static BLOCK_ENTITIES: LazyLock<HashMap<String, u32>> = LazyLock::new(|| { | ||
serde_json::from_str::<TopLevel>(include_str!("../../assets/blocks.json")) | ||
.expect("Could not parse blocks.json registry.") | ||
.block_entity_types | ||
.into_iter() | ||
.map(|value| (value.ident, value.id)) | ||
.collect() | ||
}); |
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.
Now blocks.json
is loaded twice. Here and in pumpkin-world
. We want to avoid this, Its an Performance and Resource Waste. Most JSON's are currently being loaded from pumpkin-macros
. We free to move some methods from the block_registry
to here
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.
I also would love to have the BlockState::new(<name>).unwrap()
replaced with a macro. We had a macro for this before i moved the JSON's to our own Extractor. Feel free to add this to this PR, But you not forced
pub line_1: String, | ||
pub line_2: String, | ||
pub line_3: String, | ||
pub line_4: String, |
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.
Every line has the max length of 384. We currently have no way of automatically Deserializing the length. You would need to have to implement the Packet manually and use buf.read_string_len(384)
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.
If it's 384 characters per line, then why not
pub line_1: String, | |
pub line_2: String, | |
pub line_3: String, | |
pub line_4: String, | |
pub line_1: [char; 384], | |
pub line_2: [char; 384], | |
pub line_3: [char; 384], | |
pub line_4: [char; 384], |
?
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.
I forgot that the client is probably going to try and send something more than 384 characters and crash the server... 💀
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.
If it's 384 characters per line, then why not
?
That's the wrong approche, It will be also a pain to actually get the lines.
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.
If it's 384 characters per line, then why not
?That's the wrong approche, It will be also a pain to actually get the lines.
You do save some memory by storing it as a slice though. Also, what do you mean "get the lines"? If you're using it like it's a String
then you just use String::from_slice
or line_n.into()
. Although I do think that we probably shouldn't trust that the client is going to send 384 characters or below for a line.
let location = WorldPosition(Vector3::new( | ||
bytebuf.get_i32()?, | ||
bytebuf.get_i32()?, | ||
bytebuf.get_i32()?, |
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.
This won't work. Look at https://wiki.vg/Protocol#Position. My solution:
pumpkin-core/src/math/position impl WorldPosition add
pub fn from_i64(encoded_position: i64) -> Self {
WorldPosition(Vector3 {
x: (encoded_position >> 38) as i32,
y: (encoded_position << 52 >> 52) as i32,
z: (encoded_position << 26 >> 38) as i32,
})
}
And in your SUpdateSign you just do:
let location = WorldPosition::from_i64(bytebuf.get_i64()?);
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.
Added this, thanks for the solution!
There is also an error when the block gets updatet trough the CAcknowledgeBlockChange packet. Then the popup instantly goes away |
1662038
to
00af2b9
Compare
@whiteout314 why was this PR closed? |
oof |
Sorry about that looks like I had an issue last night updating and pushing to my branch |
let block_entity_name = input_string.trim_matches('"'); | ||
|
||
quote! { | ||
pumpkin_world::block::block_registry::BLOCKS |
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.
@Snowiiii I was wondering if this is fine and in another PR, I could do all the changes to bring the methods from block_registry into this macro
Will this be merged soon? It would be a base for following block entities. |
Block entities are also required for many things. I wanted to add jukebox support and even that requires it (storing disc). Will this be merged soon? I tested and it works for me. |
I think it would be best to fit this PR to the new Block system in #333 |
@whiteout314 Do you want to do this or should I implement this? |
@leobeg Go ahead and implement it since you are already working on blocks that can be interacted with and plus is up to date. |
@whiteout314 #333 just got merged |
Description
Currently signs cannot be edited. Added the following:
Testing
Checklist
Things need to be done before this Pull Request can be merged.
cargo fmt
cargo clippy