mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
Entities despawning, half item pickup
This commit is contained in:
parent
8d9f9ed9ed
commit
a64f0c8bbe
@ -136,14 +136,14 @@ class BlockAPI{
|
||||
if($down[0] === 64){
|
||||
$data2 = $data;
|
||||
--$data2["y"];
|
||||
$this->server->event("player.block.break", $data2);
|
||||
$this->server->trigger("player.block.break", $data2);
|
||||
}
|
||||
}else{
|
||||
$up = $this->server->api->level->getBlock($data["x"], $data["y"] + 1, $data["z"]);
|
||||
if($up[0] === 64){
|
||||
$data2 = $data;
|
||||
++$data2["y"];
|
||||
$this->server->event("player.block.break", $data2);
|
||||
$this->server->trigger("player.block.break", $data2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -151,7 +151,7 @@ class BlockAPI{
|
||||
if($drop !== false and $drop[0] !== 0 and $drop[2] > 0){
|
||||
$this->drop($data["x"], $data["y"], $data["z"], $drop[0], $drop[1] & 0x0F, $drop[2] & 0xFF);
|
||||
}
|
||||
$this->server->event("player.block.break", $data);
|
||||
$this->server->trigger("player.block.break", $data);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,8 @@ class EntityAPI{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function commandHandler($cmd, $params){
|
||||
switch($cmd){
|
||||
case "give":
|
||||
|
@ -47,13 +47,13 @@ class LevelAPI{
|
||||
$this->setBlock($data["x"], $data["y"], $data["z"], $data["block"], $data["meta"]);
|
||||
break;
|
||||
case "player.block.break":
|
||||
$block = $this->getBlock($data["x"], $data["y"], $data["z"]);
|
||||
console("[DEBUG] EID ".$data["eid"]." broke ".$block[0].":".$block[1]." at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2);
|
||||
|
||||
if($block[0] === 0){
|
||||
break;
|
||||
}
|
||||
$this->setBlock($data["x"], $data["y"], $data["z"], 0, 0);
|
||||
$block = $this->getBlock($data["x"], $data["y"], $data["z"]);
|
||||
console("[DEBUG] EID ".$data["eid"]." broke ".$block[0].":".$block[1]." at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2);
|
||||
|
||||
if($block[0] === 0){
|
||||
break;
|
||||
}
|
||||
$this->setBlock($data["x"], $data["y"], $data["z"], 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
console("[NOTICE] A new STABLE version of PocketMine-MP has been released");
|
||||
console("[NOTICE] Version \"".$info["name"]."\" [".substr($info["commit"]["sha"], 0, 10)."]");
|
||||
console("[NOTICE] Download it at ".$info["zipball_url"]);
|
||||
console("[NOTICE] This message will dissapear as soon as you update\"");
|
||||
console("[NOTICE] This message will dissapear as soon as you update");
|
||||
sleep(5);
|
||||
}else{
|
||||
$this->setProperty("last-update", time());
|
||||
|
@ -288,6 +288,15 @@ class CustomPacketHandler{
|
||||
$this->raw .= Utils::writeByte($this->data["roll"]);
|
||||
}
|
||||
break;
|
||||
case MC_TAKE_ITEM_ENTITY:
|
||||
if($this->c === false){
|
||||
$this->data["target"] = Utils::readInt($this->get(4));
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["target"]);
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
}
|
||||
break;
|
||||
case MC_MOVE_ENTITY:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
|
@ -49,7 +49,7 @@ class Entity extends stdClass{
|
||||
$this->closed = false;
|
||||
$this->name = "";
|
||||
$this->server->query("INSERT OR REPLACE INTO entities (EID, type, class, health) VALUES (".$this->eid.", ".$this->type.", ".$this->class.", ".$this->health.");");
|
||||
$this->ev = $this->server->event("server.tick", array($this, "update"));
|
||||
$this->server->schedule(20, array($this, "update"), array(), true);
|
||||
$this->metadata = array();
|
||||
$this->x = isset($this->data["x"]) ? $this->data["x"]:0;
|
||||
$this->y = isset($this->data["y"]) ? $this->data["y"]:0;
|
||||
@ -76,7 +76,17 @@ class Entity extends stdClass{
|
||||
}
|
||||
|
||||
public function update(){
|
||||
|
||||
if($this->class === ENTITY_ITEM){
|
||||
$player = $this->server->query("SELECT EID FROM entities WHERE class == ".ENTITY_PLAYER." AND abs(x - {$this->x}) <= 1.5 AND abs(y - {$this->y}) <= 1.5 AND abs(z - {$this->z}) <= 1.5 LIMIT 1;", true);
|
||||
if($player !== true and $player !== false){
|
||||
if($this->server->api->dhandle("player.item.pick", array(
|
||||
"eid" => $player["EID"],
|
||||
"target" => $this->eid
|
||||
)) !== false){
|
||||
$this->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getDirection(){
|
||||
@ -152,7 +162,6 @@ class Entity extends stdClass{
|
||||
if($this->closed === false){
|
||||
$this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";");
|
||||
$this->server->api->dhandle("entity.remove", $this->eid);
|
||||
$this->server->deleteEvent($this->ev);
|
||||
$this->closed = true;
|
||||
}
|
||||
}
|
||||
|
@ -113,6 +113,9 @@ class Player{
|
||||
|
||||
public function eventHandler($data, $event){
|
||||
switch($event){
|
||||
case "player.item.pick":
|
||||
$this->dataPacket(MC_TAKE_ITEM_ENTITY, $data);
|
||||
break;
|
||||
case "player.equipment.change":
|
||||
if($data["eid"] === $this->eid){
|
||||
break;
|
||||
@ -140,7 +143,7 @@ class Player{
|
||||
if($data === $this->eid){
|
||||
break;
|
||||
}
|
||||
$this->dataPacket(MC_ENTITY_REMOVE, array(
|
||||
$this->dataPacket(MC_REMOVE_ENTITY, array(
|
||||
"eid" => $data,
|
||||
));
|
||||
break;
|
||||
@ -292,6 +295,7 @@ class Player{
|
||||
$this->evid[] = $this->server->event("entity.move", array($this, "eventHandler"));
|
||||
$this->evid[] = $this->server->event("entity.animate", array($this, "eventHandler"));
|
||||
$this->evid[] = $this->server->event("player.equipment.change", array($this, "eventHandler"));
|
||||
$this->evid[] = $this->server->event("player.item.pick", array($this, "eventHandler"));
|
||||
$this->evid[] = $this->server->event("world.block.change", array($this, "eventHandler"));
|
||||
console("[DEBUG] Player with EID ".$this->eid." \"".$this->username."\" spawned!", true, true, 2);
|
||||
|
||||
|
@ -494,7 +494,7 @@ class PocketMinecraftServer extends stdClass{
|
||||
$add = ' unset($this->schedule['.$this->scheduleCnt.']);';
|
||||
}
|
||||
$this->schedule[$this->scheduleCnt] = array($callback, $data, $eventName);
|
||||
$this->action(50000 * $ticks, '$schedule = $this->schedule['.$this->scheduleCnt.'];'.$add.' call_user_func($schedule[0], $schedule[1], $schedule[2]);', (bool) $repeat);
|
||||
$this->action(50000 * $ticks, '$schedule = $this->schedule['.$this->scheduleCnt.'];'.$add.'if(!is_callable($schedule[0])){unset($this->schedule['.$this->scheduleCnt.']);return;} call_user_func($schedule[0], $schedule[1], $schedule[2]);', (bool) $repeat);
|
||||
return $this->scheduleCnt++;
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,7 @@ $dataName = array(
|
||||
MC_ADD_ENTITY => "AddEntity",
|
||||
MC_REMOVE_ENTITY => "RemoveEntity",
|
||||
MC_ADD_ITEM_ENTITY => "AddItemEntity",
|
||||
MC_TAKE_ITEM_ENTITY => "TakeItemEntity",
|
||||
|
||||
MC_MOVE_ENTITY => "MoveEntity",
|
||||
|
||||
|
@ -52,6 +52,7 @@ define("MC_ADD_PLAYER", 0x89);
|
||||
define("MC_ADD_ENTITY", 0x8c);
|
||||
define("MC_REMOVE_ENTITY", 0x8d);
|
||||
define("MC_ADD_ITEM_ENTITY", 0x8e);
|
||||
define("MC_TAKE_ITEM_ENTITY", 0x8f);
|
||||
|
||||
define("MC_MOVE_ENTITY", 0x90);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user