This commit is contained in:
1 parent
8cf50cb393
commit
7ccb0c237f
4 files changed
+84
-10
No files matched your search
@@ -3,6 +3,8 @@ use pumpkin_macros::java_packet;
|
|||||||
use pumpkin_util::math::position::BlockPos;
|
use pumpkin_util::math::position::BlockPos;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
use crate::codec::var_int::VarInt;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[java_packet(PLAY_PICK_ITEM_FROM_BLOCK)]
|
#[java_packet(PLAY_PICK_ITEM_FROM_BLOCK)]
|
||||||
pub struct SPickItemFromBlock {
|
pub struct SPickItemFromBlock {
|
||||||
@@ -13,6 +15,6 @@ pub struct SPickItemFromBlock {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[java_packet(PLAY_PICK_ITEM_FROM_ENTITY)]
|
#[java_packet(PLAY_PICK_ITEM_FROM_ENTITY)]
|
||||||
pub struct SPickItemFromEntity {
|
pub struct SPickItemFromEntity {
|
||||||
pub id: i32,
|
pub id: VarInt,
|
||||||
pub include_data: bool,
|
pub include_data: bool,
|
||||||
}
|
}
|
||||||
@@ -996,6 +996,17 @@ impl JavaClient {
|
|||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
id if id
|
||||||
|
== pumpkin_protocol::java::server::play::SPickItemFromEntity::to_id(version) =>
|
||||||
|
{
|
||||||
|
self.handle_pick_item_from_entity(
|
||||||
|
player,
|
||||||
|
pumpkin_protocol::java::server::play::SPickItemFromEntity::read(
|
||||||
|
payload, &version,
|
||||||
|
)?,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
id if id == SPlayerAbilities::to_id(version) => {
|
id if id == SPlayerAbilities::to_id(version) => {
|
||||||
self.handle_player_abilities(
|
self.handle_player_abilities(
|
||||||
player,
|
player,
|
||||||
|
|||||||
@@ -66,11 +66,11 @@ use pumpkin_protocol::java::server::play::{
|
|||||||
SChangeGameMode, SChatCommand, SChatMessage, SChunkBatch, SClientCommand,
|
SChangeGameMode, SChatCommand, SChatMessage, SChunkBatch, SClientCommand,
|
||||||
SClientInformationPlay, SCloseContainer, SCommandSuggestion, SConfirmTeleport,
|
SClientInformationPlay, SCloseContainer, SCommandSuggestion, SConfirmTeleport,
|
||||||
SCookieResponse as SPCookieResponse, SInteract, SJigsawGenerate, SKeepAlive, SMoveVehicle,
|
SCookieResponse as SPCookieResponse, SInteract, SJigsawGenerate, SKeepAlive, SMoveVehicle,
|
||||||
SPaddleBoat, SPickItemFromBlock, SPlaceRecipe, SPlayPingRequest, SPlayerAbilities,
|
SPaddleBoat, SPickItemFromBlock, SPickItemFromEntity, SPlaceRecipe, SPlayPingRequest,
|
||||||
SPlayerAction, SPlayerCommand, SPlayerInput, SPlayerPosition, SPlayerPositionRotation,
|
SPlayerAbilities, SPlayerAction, SPlayerCommand, SPlayerInput, SPlayerPosition,
|
||||||
SPlayerRotation, SPlayerSession, SRecipeBookChangeSettings, SRecipeBookSeenRecipe,
|
SPlayerPositionRotation, SPlayerRotation, SPlayerSession, SRecipeBookChangeSettings,
|
||||||
SSeenAdvancement, SSelectTrade, SSetCommandBlock, SSetCreativeSlot, SSetHeldItem,
|
SRecipeBookSeenRecipe, SSeenAdvancement, SSelectTrade, SSetCommandBlock, SSetCreativeSlot,
|
||||||
SSetJigsawBlock, SSetPlayerGround, SSetTestBlock, SSwingArm, STeleportToEntity,
|
SSetHeldItem, SSetJigsawBlock, SSetPlayerGround, SSetTestBlock, SSwingArm, STeleportToEntity,
|
||||||
STestInstanceBlockAction, SUpdateSign, SUseItem, SUseItemOn, Status,
|
STestInstanceBlockAction, SUpdateSign, SUseItem, SUseItemOn, Status,
|
||||||
};
|
};
|
||||||
use pumpkin_util::math::vector3::Vector3;
|
use pumpkin_util::math::vector3::Vector3;
|
||||||
@@ -770,9 +770,70 @@ impl JavaClient {
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn handle_pick_item_from_entity(&self, _pick_item: SPickItemFromEntity) {
|
pub async fn handle_pick_item_from_entity(
|
||||||
// // TODO: Implement and merge any redundant code with pick_item_from_block
|
&self,
|
||||||
// }
|
player: &Arc<Player>,
|
||||||
|
pick_item: SPickItemFromEntity,
|
||||||
|
) {
|
||||||
|
use pumpkin_data::entity::{entity_from_egg, spawn_egg_ids};
|
||||||
|
|
||||||
|
let world = player.world();
|
||||||
|
let Some(target) = world.get_entity_by_id(pick_item.id.0) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let p_eye = player.get_entity().get_eye_pos();
|
||||||
|
let t_eye = target.get_eye_pos();
|
||||||
|
let dx = p_eye.x - t_eye.x;
|
||||||
|
let dy = p_eye.y - t_eye.y;
|
||||||
|
let dz = p_eye.z - t_eye.z;
|
||||||
|
if dx * dx + dy * dy + dz * dz > 64.0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let target_type_id = target.get_entity().entity_type.id;
|
||||||
|
let mut found_egg: Option<u16> = None;
|
||||||
|
for &egg_id in &spawn_egg_ids() {
|
||||||
|
if let Some(et) = entity_from_egg(egg_id)
|
||||||
|
&& et.id == target_type_id
|
||||||
|
{
|
||||||
|
found_egg = Some(egg_id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(egg_item_id) = found_egg {
|
||||||
|
let stack = ItemStack::new(1, Item::from_id(egg_item_id).unwrap());
|
||||||
|
|
||||||
|
let slot_with_stack = player.inventory().get_slot_with_stack(&stack).await;
|
||||||
|
|
||||||
|
if slot_with_stack != -1 {
|
||||||
|
if PlayerInventory::is_valid_hotbar_index(slot_with_stack as usize) {
|
||||||
|
player.inventory.set_selected_slot(slot_with_stack as u8);
|
||||||
|
} else {
|
||||||
|
player
|
||||||
|
.inventory
|
||||||
|
.swap_slot_with_hotbar(slot_with_stack as usize)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
} else if player.gamemode.load() == GameMode::Creative {
|
||||||
|
player.inventory.swap_stack_with_hotbar(stack).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
player
|
||||||
|
.client
|
||||||
|
.enqueue_packet(&CSetSelectedSlot::new(
|
||||||
|
player.inventory.get_selected_slot() as i8
|
||||||
|
))
|
||||||
|
.await;
|
||||||
|
player
|
||||||
|
.player_screen_handler
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.send_content_updates()
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn handle_set_command_block(
|
pub async fn handle_set_command_block(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -911,7 +911,7 @@ pub fn deserialize_java_serverbound_packet(
|
|||||||
use pumpkin_protocol::ServerPacket;
|
use pumpkin_protocol::ServerPacket;
|
||||||
let p = <pumpkin_protocol::java::server::play::SPickItemFromEntity as pumpkin_protocol::ServerPacket>::read(&mut Cursor::new(payload), &version).ok()?;
|
let p = <pumpkin_protocol::java::server::play::SPickItemFromEntity as pumpkin_protocol::ServerPacket>::read(&mut Cursor::new(payload), &version).ok()?;
|
||||||
Some(ServerboundPacket::SPickItemFromEntity(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SPickItemFromEntity {
|
Some(ServerboundPacket::SPickItemFromEntity(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SPickItemFromEntity {
|
||||||
id: p.id.try_into().unwrap(),
|
id: p.id.0,
|
||||||
include_data: p.include_data.try_into().unwrap(),
|
include_data: p.include_data.try_into().unwrap(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user