Throw leftover items from the eyes, and creative players keep their stack on an armor stand
This commit is contained in:
@@ -2222,11 +2222,13 @@ impl Game<'_> {
|
||||
// Player.drop: the drop statistics.
|
||||
self.stats.add("dropped", &thrown.item, thrown.count as i32);
|
||||
self.stats.custom("drop", 1);
|
||||
self.throw_from_eyes(thrown, eye);
|
||||
self.throw_from_eyes(thrown, eye, true);
|
||||
}
|
||||
/// `Player.createItemStackToDrop`: an item entity thrown from the eyes
|
||||
/// along the view direction.
|
||||
fn throw_from_eyes(&mut self, thrown: ItemStack, eye: [f64; 3]) {
|
||||
/// along the view direction. `thrown_from_hand` (`drop(stack, true)`, the
|
||||
/// drop key) names the player as the thrower; `drop(stack, false)`, for
|
||||
/// what no longer fits in the inventory, does not.
|
||||
fn throw_from_eyes(&mut self, thrown: ItemStack, eye: [f64; 3], thrown_from_hand: bool) {
|
||||
let (yaw, pitch) = (
|
||||
f64::from(self.yaw).to_radians(),
|
||||
f64::from(self.pitch).to_radians(),
|
||||
@@ -2240,7 +2242,7 @@ impl Game<'_> {
|
||||
yaw.cos() * pitch.cos() * 0.3 + spread.sin() * strength,
|
||||
];
|
||||
self.spawn_item(thrown, [eye[0], eye[1] - 0.3, eye[2]], v, 40);
|
||||
if self.lan_acting.is_none() {
|
||||
if thrown_from_hand && self.lan_acting.is_none() {
|
||||
let uuid = self.level.ensure_player_uuid();
|
||||
self.dropped.last_mut().unwrap().thrower = Some(uuid);
|
||||
}
|
||||
@@ -4517,7 +4519,7 @@ impl Game<'_> {
|
||||
&& let Some(stack) = self.carried.take()
|
||||
&& let Some(eye) = self.eye_position()
|
||||
{
|
||||
self.throw_from_eyes(stack, eye);
|
||||
self.throw_from_eyes(stack, eye, false);
|
||||
}
|
||||
}
|
||||
self.tick_world(running)
|
||||
@@ -5606,7 +5608,8 @@ impl Game<'_> {
|
||||
if let Some(rest) = self.give(stack)
|
||||
&& let Some(eye) = self.eye_position()
|
||||
{
|
||||
self.spawn_item(rest, [eye[0], eye[1] - 0.3, eye[2]], [0.0, 0.1, 0.0], 40);
|
||||
// AbstractContainerMenu.dropOrPlaceInInventory: `drop(stack, false)`.
|
||||
self.throw_from_eyes(rest, eye, false);
|
||||
}
|
||||
}
|
||||
self.craft_size = 2;
|
||||
@@ -8437,7 +8440,8 @@ impl Game<'_> {
|
||||
}
|
||||
fn drop_stack(&mut self, stack: ItemStack) {
|
||||
if let Some(eye) = self.0.eye_position() {
|
||||
self.0.spawn_item(stack, eye, [0.0, 0.1, 0.0], 40);
|
||||
// ItemUtils.createFilledResult: `player.drop(stack, false)`.
|
||||
self.0.throw_from_eyes(stack, eye, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8755,7 +8759,8 @@ impl Game<'_> {
|
||||
} else if let Some(rest) = self.give(filled)
|
||||
&& let Some(eye) = self.eye_position()
|
||||
{
|
||||
self.spawn_item(rest, eye, [0.0, 0.1, 0.0], 40);
|
||||
// ItemUtils.createFilledResult: `player.drop(stack, false)`.
|
||||
self.throw_from_eyes(rest, eye, false);
|
||||
}
|
||||
}
|
||||
return Ok(UseResult::Success { swing: true });
|
||||
|
||||
@@ -453,6 +453,11 @@ impl Game<'_> {
|
||||
}
|
||||
// ArmorStand.swapItem.
|
||||
match held {
|
||||
// A player with infinite materials puts a copy of one on an empty
|
||||
// slot and keeps the stack.
|
||||
Some(h) if self.creative && current.is_none() => {
|
||||
self.armor_stands[i].equipment[slot] = Some(ItemStack { count: 1, ..h });
|
||||
}
|
||||
Some(h) if h.count > 1 => {
|
||||
if current.is_some() {
|
||||
return true;
|
||||
|
||||
@@ -266,7 +266,8 @@ impl Game<'_> {
|
||||
} else if let Some(rest) = self.give(filled)
|
||||
&& let Some(eye) = self.eye_position()
|
||||
{
|
||||
self.spawn_item(rest, eye, [0.0, 0.1, 0.0], 40);
|
||||
// `player.drop(stack, false)`.
|
||||
self.throw_from_eyes(rest, eye, false);
|
||||
}
|
||||
}
|
||||
/// Drinking a potion while right-click is held; true when handled.
|
||||
|
||||
@@ -713,7 +713,8 @@ impl Game<'_> {
|
||||
if let Some(rest) = self.give(stack)
|
||||
&& let Some(eye) = self.eye_position()
|
||||
{
|
||||
self.spawn_item(rest, [eye[0], eye[1] - 0.3, eye[2]], [0.0, 0.1, 0.0], 40);
|
||||
// Inventory.placeItemBackInInventory: `player.drop(stack, false)`.
|
||||
self.throw_from_eyes(rest, eye, false);
|
||||
}
|
||||
}
|
||||
/// `Player.giveExperienceLevels`.
|
||||
|
||||
Reference in New Issue
Block a user