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

Create Item Entities and make them interactable #103

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Bryntet
Copy link
Contributor

@Bryntet Bryntet commented Sep 20, 2024

This PR aims to add the following:

  • ItemEntities
  • Player Dropping of items
  • Entity collision checking
  • Block breaking drops item
  • Player able to pick up item

@Bryntet Bryntet force-pushed the item-dropping branch 2 times, most recently from 4f4c723 to cd61b4c Compare September 22, 2024 12:26
@Bryntet
Copy link
Contributor Author

Bryntet commented Sep 22, 2024

To clarify, collisions kinda work. They work fully with the ground, but they cancel out velocity, and don't act exactly as they should.

Dropped Items also do not merge into one yet.

@Snowiiii
Copy link
Owner

Hey @Bryntet any updates on this?

@Bryntet
Copy link
Contributor Author

Bryntet commented Oct 11, 2024

Currently stuck on getting collisions to work exactly like vanilla. Chunks saving to ram changes is also blocking the Block-breaking drops items.

Edit: I'd love any help I can get with doing collisions, as I've never really worked with collisions before, and the decompiled Mojang code is a big mess :(

@Bryntet
Copy link
Contributor Author

Bryntet commented Oct 22, 2024

Block dropping now partially works.

I'd be happy to receive an initial review now, as well as maybe discussing whether this should be polished more, or merged so that we can branch of and work on the more fine implementation details on this separately.

Comment on lines 8 to 12
pub struct CSetEntityMetadata<T: Serialize> {
pub entity_id: VarInt,
pub metadata: Metadata<T>,
pub end: u8,
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you like to make the fields public, But its more of an "interal convention" in pumpkin to use the new function


let entity = Arc::new(Entity {
entity_id: server.new_entity_id(),
uuid: Uuid::new_v4(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a check if the UUID is not matching any existing player UUID on the server, I also wonder what to do if a new player join which has the same UUID as an entity

Comment on lines +290 to +286
fn toss_velocity(player: &Entity) -> Vector3<f64> {
use std::f64::consts::PI;
let pitch_sin = f64::sin(f64::from(player.pitch.load()) * (PI / 180.0));
let pitch_cos = f64::cos(f64::from(player.pitch.load()) * (PI / 180.0));
let yaw_sin = f64::sin(f64::from(player.yaw.load()) * (PI / 180.0));
let yaw_cos = f64::cos(f64::from(player.yaw.load()) * (PI / 180.0));
let random_angle = random_float() * (2.0 * PI);
let random_offset = 0.02 * random_float();

Vector3 {
x: (-yaw_sin * pitch_cos).mul_add(0.3, f64::cos(random_angle) * random_offset),
y: (-pitch_sin).mul_add(0.3, (random_float() - random_float()).mul_add(0.1, 0.1)),
z: (yaw_cos * pitch_cos).mul_add(0.3, f64::sin(random_angle) * random_offset),
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this from vanilla ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes these are the same mathematical functions as those run by vanilla when an item is dropped by a player

@@ -47,6 +55,9 @@ pub struct Entity {
/// Indicates whether the entity is on the ground (may not always be accurate).
pub on_ground: AtomicBool,

/// Indicates whether the entity is inside of ground, and needs to be pushed out.
pub in_ground: AtomicBool,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this generally checks if a Entity is in blocks not only ground, right?, Then a better name would be maybe inside_block

Comment on lines 4 to 28
pub fn spawn_entity_with_data(entity: &Entity, data: Option<i32>) -> CSpawnEntity {
let pos = entity.pos.load();
let velocity = entity.velocity.load();
CSpawnEntity::new(
entity.entity_id.into(),
entity.uuid,
(entity.entity_type as i32).into(),
pos.x,
pos.y,
pos.z,
entity.pitch.load(),
entity.yaw.load(),
entity.head_yaw.load(),
data.unwrap_or(0).into(),
velocity.x,
velocity.y,
velocity.z,
)
}

impl From<&Entity> for CSpawnEntity {
fn from(entity: &Entity) -> Self {
spawn_entity_with_data(entity, None)
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like this, First you have a whole new file for only wrapping around some values, Also i don't think its that hard to write this every time, If you think this is really necessary i would much more prefer this in the entity file

@Bryntet Bryntet force-pushed the item-dropping branch 2 times, most recently from 0313adb to 0e43d63 Compare October 23, 2024 17:04
@user622628252416 user622628252416 mentioned this pull request Nov 6, 2024
4 tasks
# Conflicts:
#	pumpkin-core/src/math/boundingbox.rs
#	pumpkin-inventory/src/player.rs
#	pumpkin-protocol/src/client/play/c_entity_metadata.rs
#	pumpkin-protocol/src/client/play/c_entity_velocity.rs
#	pumpkin-protocol/src/client/play/mod.rs
#	pumpkin-world/src/block/block_registry.rs
#	pumpkin-world/src/item/item_registry.rs
#	pumpkin-world/src/item/mod.rs
#	pumpkin/src/client/container.rs
#	pumpkin/src/client/player_packet.rs
#	pumpkin/src/entity/mod.rs
#	pumpkin/src/entity/player.rs
#	pumpkin/src/world/mod.rs
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.

2 participants