mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Updated the BlockAPI::drop method
This commit is contained in:
parent
326864f889
commit
287fa7e551
@ -127,15 +127,13 @@ class BlockAPI{
|
||||
$item = BlockAPI::fromString($params[1]);
|
||||
|
||||
if(!isset($params[2])){
|
||||
$amount = 64;
|
||||
$item->count = $item->getMaxStackSize();
|
||||
}else{
|
||||
$amount = (int) $params[2];
|
||||
}
|
||||
if(isset($params[3])){
|
||||
$meta = ((int) $params[3]) & 0xFFFF;
|
||||
$item->count = (int) $params[2];
|
||||
}
|
||||
|
||||
if(($player = $this->server->api->player->get($username)) !== false){
|
||||
$this->drop($player->entity->x - 0.5, $player->entity->y, $player->entity->z - 0.5, $item->getID(), $item->getMetadata(), $amount);
|
||||
$this->drop(new Vector3($player->entity->x - 0.5, $player->entity->y, $player->entity->z - 0.5), $item, true);
|
||||
$output .= "Giving ".$amount." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$username."\n";
|
||||
}else{
|
||||
$output .= "Unknown player\n";
|
||||
@ -177,32 +175,28 @@ class BlockAPI{
|
||||
|
||||
if(count($drops) > 0){
|
||||
foreach($drops as $drop){
|
||||
$this->drop($target->x, $target->y, $target->z, $drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF);
|
||||
$this->drop($target, BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function drop($x, $y, $z, $block, $meta, $stack = 1){
|
||||
if($block === AIR or $stack <= 0 or $this->server->gamemode === CREATIVE){
|
||||
public function drop(Vector3 $pos, Item $item, $force = false){
|
||||
if($item->getID() === AIR or $item->count <= 0 or ($this->server->gamemode === CREATIVE and $force !== true)){
|
||||
return;
|
||||
}
|
||||
$data = array(
|
||||
"x" => $x,
|
||||
"y" => $y,
|
||||
"z" => $z,
|
||||
"meta" => $meta,
|
||||
"stack" => $stack,
|
||||
"x" => $pos->x + mt_rand(2, 8) / 10,
|
||||
"y" => $pos->y + 0.19,
|
||||
"z" => $pos->z + mt_rand(2, 8) / 10,
|
||||
"item" => $item,
|
||||
);
|
||||
$data["x"] += mt_rand(2, 8) / 10;
|
||||
$data["y"] += 0.19;
|
||||
$data["z"] += mt_rand(2, 8) / 10;
|
||||
if($this->server->api->handle("block.drop", $data) !== false){
|
||||
for($count = $stack; $count > 0; ){
|
||||
$data["stack"] = min(64, $count);
|
||||
$count -= $data["stack"];
|
||||
for($count = $item->count; $count > 0; ){
|
||||
$item->count = min($item->getMaxStackSize(), $count);
|
||||
$count -= $item->count;
|
||||
$server = ServerAPI::request();
|
||||
$e = $server->api->entity->add(ENTITY_ITEM, $block, $data);
|
||||
$e = $server->api->entity->add(ENTITY_ITEM, $item->getID(), $data);
|
||||
//$e->speedX = mt_rand(-10, 10) / 100;
|
||||
//$e->speedY = mt_rand(0, 5) / 100;
|
||||
//$e->speedZ = mt_rand(-10, 10) / 100;
|
||||
|
@ -747,7 +747,7 @@ class Player{
|
||||
break;
|
||||
}
|
||||
if($this->server->handle("player.drop", $data) !== false){
|
||||
$this->server->api->block->drop($this->entity->x, $this->entity->y, $this->entity->z, $data["block"], $data["meta"], $data["stack"]);
|
||||
$this->server->api->block->drop(new Vector3($this->entity->x, $this->entity->y, $this->entity->z), BlockAPI::getItem($data["block"], $data["meta"], $data["stack"]));
|
||||
}
|
||||
break;
|
||||
case MC_SIGN_UPDATE:
|
||||
|
@ -42,5 +42,5 @@ define("MAJOR_VERSION", "Alpha_1.2dev");
|
||||
define("CURRENT_STRUCTURE", 5);
|
||||
define("CURRENT_PROTOCOL", 9);
|
||||
define("CURRENT_MINECRAFT_VERSION", "v0.6.1 alpha");
|
||||
define("CURRENT_API_VERSION", 2);
|
||||
define("CURRENT_API_VERSION", 3);
|
||||
define("CURRENT_PHP_VERSION", "5.4.12");
|
@ -25,7 +25,7 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
abstract class Block{
|
||||
abstract class Block extends Vector3{
|
||||
public static $class = array(
|
||||
AIR => "AirBlock",
|
||||
STONE => "StoneBlock",
|
||||
@ -183,7 +183,7 @@ abstract class Block{
|
||||
}
|
||||
|
||||
final public function __toString(){
|
||||
return $this->name ." (".$this->id.":".$this->meta.")";
|
||||
return "Block ". $this->name ." (".$this->id.":".$this->meta.")";
|
||||
}
|
||||
|
||||
abstract function isBreakable(Item $item, Player $player);
|
||||
|
@ -128,7 +128,7 @@ class Item{
|
||||
}
|
||||
|
||||
final public function __toString(){
|
||||
return $this->name ." (".$this->id.":".$this->meta.")";
|
||||
return "Item ". $this->name ." (".$this->id.":".$this->meta.")";
|
||||
}
|
||||
|
||||
public function getDestroySpeed(Block $block, Player $player){
|
||||
|
@ -114,8 +114,13 @@ class Entity extends stdClass{
|
||||
$this->server->schedule(5, array($this, "update"), array(), true);
|
||||
break;
|
||||
case ENTITY_ITEM:
|
||||
$this->meta = (int) $this->data["meta"];
|
||||
$this->stack = (int) $this->data["stack"];
|
||||
if($data["item"] instanceof Item){
|
||||
$this->meta = $this->data["item"]->getMetadata();
|
||||
$this->stack = $this->data["item"]->count;
|
||||
}else{
|
||||
$this->meta = (int) $this->data["meta"];
|
||||
$this->stack = (int) $this->data["stack"];
|
||||
}
|
||||
$this->setHealth(5, "generic");
|
||||
$this->server->schedule(5, array($this, "update"), array(), true);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user