mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 02:09:42 +00:00
Added item drop
This commit is contained in:
parent
99a0117a33
commit
2877f026ec
@ -30,6 +30,7 @@ use pocketmine\event\inventory\InventoryPickupItemEvent;
|
||||
use pocketmine\event\player\PlayerAchievementAwardedEvent;
|
||||
use pocketmine\event\player\PlayerChatEvent;
|
||||
use pocketmine\event\player\PlayerCommandPreprocessEvent;
|
||||
use pocketmine\event\player\PlayerDropItemEvent;
|
||||
use pocketmine\event\player\PlayerGameModeChangeEvent;
|
||||
use pocketmine\event\player\PlayerJoinEvent;
|
||||
use pocketmine\event\player\PlayerKickEvent;
|
||||
@ -919,7 +920,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
return true;
|
||||
}
|
||||
$hasUpdate = $this->entityBaseTick();
|
||||
foreach($this->getLevel()->getNearbyEntities($this->boundingBox->expand(1.5, 1, 1.5), $this) as $entity){
|
||||
foreach($this->getLevel()->getNearbyEntities($this->boundingBox->expand(1, 1, 1), $this) as $entity){
|
||||
if($entity instanceof DroppedItem){
|
||||
if($entity->dead !== true and $entity->getPickupDelay() <= 0){
|
||||
$item = $entity->getItem();
|
||||
@ -1643,26 +1644,32 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
break;
|
||||
}
|
||||
break;*/
|
||||
/*case ProtocolInfo::DROP_ITEM_PACKET:
|
||||
case ProtocolInfo::DROP_ITEM_PACKET:
|
||||
if($this->spawned === false or $this->blocked === true){
|
||||
break;
|
||||
}
|
||||
$packet->eid = $this->id;
|
||||
$packet->item = $this->getSlot($this->getCurrentEquipment());
|
||||
$data = [];
|
||||
$data["eid"] = $packet->eid;
|
||||
$data["unknown"] = $packet->unknown;
|
||||
$data["item"] = $packet->item;
|
||||
$data["player"] = $this;
|
||||
if($this->blocked === false and $this->server->handle("player.drop", $data) !== false){
|
||||
$this->server->api->entity->drop(new Position($this->entity->x - 0.5, $this->entity->y, $this->entity->z - 0.5, $this->getLevel()), $packet->item);
|
||||
$this->setSlot($this->getCurrentEquipment(), Item::get(AIR, 0, 0), false);
|
||||
$item = $this->inventory->getItemInHand();
|
||||
$ev = new PlayerDropItemEvent($this, $item);
|
||||
if($this->blocked === true){
|
||||
$ev->setCancelled(true);
|
||||
}
|
||||
if($this->entity->inAction === true){
|
||||
$this->entity->inAction = false;
|
||||
$this->entity->updateMetadata();
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
if($ev->isCancelled()){
|
||||
$this->inventory->sendContents($this);
|
||||
break;
|
||||
}
|
||||
break;*/
|
||||
|
||||
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 0));
|
||||
$motion = $this->getDirectionVector()->multiply(10);
|
||||
|
||||
$this->getLevel()->dropItem($this->add(0, 1, 0), $item, $motion);
|
||||
|
||||
if($this->inAction === true){
|
||||
$this->inAction = false;
|
||||
//$this->updateMetadata();
|
||||
}
|
||||
break;
|
||||
case ProtocolInfo::MESSAGE_PACKET:
|
||||
if($this->spawned === false){
|
||||
break;
|
||||
|
@ -1762,12 +1762,6 @@ class Server{
|
||||
}
|
||||
}
|
||||
|
||||
public function handlePacket(Packet $packet){
|
||||
if($packet instanceof QueryPacket and isset($this->queryHandler)){
|
||||
$this->queryHandler->handle($packet);
|
||||
}
|
||||
}
|
||||
|
||||
public function addPlayer($identifier, Player $player){
|
||||
$this->players[$identifier] = $player;
|
||||
}
|
||||
|
@ -460,6 +460,21 @@ abstract class Entity extends Position implements Metadatable{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Vector3
|
||||
*/
|
||||
public function getDirectionVector(){
|
||||
$pitch = ($this->pitch * M_PI) / 180;
|
||||
$yaw = (($this->yaw + 90) * M_PI) / 180;
|
||||
|
||||
$y = -sin(deg2rad($this->pitch));
|
||||
$xz = cos(deg2rad($this->pitch));
|
||||
$x = -$xz * sin(deg2rad($this->yaw));
|
||||
$z = $xz * cos(deg2rad($this->yaw));
|
||||
|
||||
return new Vector3($x, $y, $z);
|
||||
}
|
||||
|
||||
public function onUpdate(){
|
||||
if($this->closed !== false){
|
||||
return false;
|
||||
|
53
src/pocketmine/event/player/PlayerDropItemEvent.php
Normal file
53
src/pocketmine/event/player/PlayerDropItemEvent.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\Player;
|
||||
|
||||
/**
|
||||
* Called when a player tries to drop an item from its hotbar
|
||||
*/
|
||||
class PlayerDropItemEvent extends PlayerEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var Item */
|
||||
private $drop;
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param Item $drop
|
||||
*/
|
||||
public function __construct(Player $player, Item $drop){
|
||||
$this->player = $player;
|
||||
$this->drop = $drop;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getItem(){
|
||||
return $this->drop;
|
||||
}
|
||||
|
||||
}
|
@ -679,9 +679,10 @@ class Level{
|
||||
/**
|
||||
* @param Vector3 $source
|
||||
* @param Item $item
|
||||
* @param float $force
|
||||
* @param Vector3 $motion
|
||||
*/
|
||||
public function dropItem(Vector3 $source, Item $item, $force = 1.0){
|
||||
public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null){
|
||||
$motion = $motion === null ? new Vector3(0, 0, 0) : $motion;
|
||||
if($item->getID() !== Item::AIR and $item->getCount() > 0){
|
||||
$itemEntity = new DroppedItem($this, new Compound("", [
|
||||
"Pos" => new Enum("Pos", [
|
||||
@ -691,9 +692,9 @@ class Level{
|
||||
]),
|
||||
//TODO: add random motion with physics
|
||||
"Motion" => new Enum("Motion", [
|
||||
new Double("", (lcg_value() * 0.2 - 0.1) * $force),
|
||||
new Double("", 0.2 * $force),
|
||||
new Double("", (lcg_value() * 0.2 - 0.1) * $force)
|
||||
new Double("", $motion->x + (lcg_value() * 0.2 - 0.1)),
|
||||
new Double("", $motion->y + 0.2),
|
||||
new Double("", $motion->z + (lcg_value() * 0.2 - 0.1))
|
||||
]),
|
||||
"Rotation" => new Enum("Rotation", [
|
||||
new Float("", lcg_value() * 360),
|
||||
@ -705,7 +706,7 @@ class Level{
|
||||
"Damage" => new Short("Damage", $item->getDamage()),
|
||||
"Count" => new Byte("Count", $item->getCount())
|
||||
]),
|
||||
"PickupDelay" => new Short("PickupDelay", 10)
|
||||
"PickupDelay" => new Short("PickupDelay", 25)
|
||||
]));
|
||||
|
||||
$itemEntity->spawnToAll();
|
||||
@ -768,7 +769,7 @@ class Level{
|
||||
if(!($player instanceof Player) or ($player->getGamemode() & 0x01) === 0){
|
||||
foreach($drops as $drop){
|
||||
if($drop[2] > 0){
|
||||
$this->dropItem($vector->add(0.5, 0.5, 0.5), Item::get($drop[0], $drop[1], $drop[2]), 1);
|
||||
$this->dropItem($vector->add(0.5, 0.5, 0.5), Item::get($drop[0], $drop[1], $drop[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -199,10 +199,6 @@ class Chest extends Spawnable implements InventoryHolder, Container{
|
||||
$tile->spawnToAll();
|
||||
$this->checkPairing();
|
||||
|
||||
//TODO: Update to new events
|
||||
//$this->server->handle("tile.update", $this);
|
||||
//$this->server->handle("tile.update", $tile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -216,11 +212,9 @@ class Chest extends Spawnable implements InventoryHolder, Container{
|
||||
|
||||
$this->spawnToAll();
|
||||
$this->checkPairing();
|
||||
//TODO: tile update event
|
||||
//$this->server->handle("tile.update", $this);
|
||||
|
||||
if($tile instanceof Chest){
|
||||
$tile->spawnToAll();
|
||||
//$this->server->handle("tile.update", $tile);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user