Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

whiteout314
Copy link

Description

Currently signs cannot be edited. Added the following:

  • Clientbound packet to open the screen editor when client places a sign block or interacts with a sign block.
  • Added serverbound packet that is sent after clicking done on the open screen editor window.
  • Added an interactive folder in blocks to hold interactive blocks such as signs, chests, etc...
  • Implemented a file that holds sign structure for NBT data and enums associated with valid sign blocks.
  • Added get_block_by_state_id function.
  • Fixed structure world's get_block function to search for state ids.

Testing

  • Tested using Minecraft version 1.21.3 placing signs and tested placing sign and able to see the sign editor and tested as well that an already placed sign can modified (front and back).

Checklist

Things need to be done before this Pull Request can be merged.

  • Code is well-formatted and adheres to project style guidelines: cargo fmt
  • Code does not produce any clippy warnings cargo clippy

Comment on lines 6 to 59
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,
}
Copy link
Owner

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

Copy link
Author

@whiteout314 whiteout314 Nov 13, 2024

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.

Copy link
Author

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.

@@ -871,6 +873,9 @@ impl Player {
SSwingArm::PACKET_ID => {
self.handle_swing_arm(SSwingArm::read(bytebuf)?).await;
}
SUpdateSign::PACKET_ID => {
//TODO
Copy link
Owner

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

Copy link
Author

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.

Copy link
Author

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.

@whiteout314 whiteout314 marked this pull request as draft November 13, 2024 23:53
@whiteout314
Copy link
Author

demo

@whiteout314 whiteout314 marked this pull request as ready for review November 14, 2024 04:35
Comment on lines 18 to 25
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()
});
Copy link
Owner

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

Copy link
Owner

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

Comment on lines +10 to +18
pub line_1: String,
pub line_2: String,
pub line_3: String,
pub line_4: String,
Copy link
Owner

@Snowiiii Snowiiii Nov 14, 2024

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)

Copy link
Contributor

@DataM0del DataM0del Nov 14, 2024

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

Suggested change
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],

?

Copy link
Contributor

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... 💀

Copy link
Owner

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.

Copy link
Contributor

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.

@Snowiiii Snowiiii mentioned this pull request Nov 16, 2024
2 tasks
let location = WorldPosition(Vector3::new(
bytebuf.get_i32()?,
bytebuf.get_i32()?,
bytebuf.get_i32()?,
Copy link
Contributor

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()?);

Copy link
Author

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!

@leobeg
Copy link
Contributor

leobeg commented Nov 16, 2024

There is also an error when the block gets updatet trough the CAcknowledgeBlockChange packet. Then the popup instantly goes away

@leobeg
Copy link
Contributor

leobeg commented Nov 17, 2024

@whiteout314 why was this PR closed?

@DataM0del
Copy link
Contributor

oof

@whiteout314
Copy link
Author

Sorry about that looks like I had an issue last night updating and pushing to my branch

@whiteout314 whiteout314 reopened this Nov 17, 2024
let block_entity_name = input_string.trim_matches('"');

quote! {
pumpkin_world::block::block_registry::BLOCKS
Copy link
Author

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

@leobeg
Copy link
Contributor

leobeg commented Nov 22, 2024

Will this be merged soon? It would be a base for following block entities.

@OfficialKris
Copy link
Contributor

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.

@leobeg
Copy link
Contributor

leobeg commented Nov 25, 2024

I think it would be best to fit this PR to the new Block system in #333

@leobeg
Copy link
Contributor

leobeg commented Nov 29, 2024

@whiteout314 Do you want to do this or should I implement this?

@whiteout314
Copy link
Author

@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.

@Snowiiii
Copy link
Owner

Snowiiii commented Dec 7, 2024

@whiteout314 #333 just got merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants