mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-05 01:16:15 +00:00
Weird Painting spawn (WiP)
This commit is contained in:
@ -194,11 +194,12 @@ class BlockAPI{
|
|||||||
for($count = $stack; $count > 0; ){
|
for($count = $stack; $count > 0; ){
|
||||||
$data["stack"] = min(64, $count);
|
$data["stack"] = min(64, $count);
|
||||||
$count -= $data["stack"];
|
$count -= $data["stack"];
|
||||||
$e = $this->server->api->entity->add(ENTITY_ITEM, $block, $data);
|
$server = ServerAPI::request();
|
||||||
|
$e = $server->api->entity->add(ENTITY_ITEM, $block, $data);
|
||||||
//$e->speedX = mt_rand(-10, 10) / 100;
|
//$e->speedX = mt_rand(-10, 10) / 100;
|
||||||
//$e->speedY = mt_rand(0, 5) / 100;
|
//$e->speedY = mt_rand(0, 5) / 100;
|
||||||
//$e->speedZ = mt_rand(-10, 10) / 100;
|
//$e->speedZ = mt_rand(-10, 10) / 100;
|
||||||
$this->server->api->entity->spawnToAll($e->eid);
|
$server->api->entity->spawnToAll($e->eid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,6 +263,10 @@ class BlockAPI{
|
|||||||
if($block->y > 127 or $block->y < 0){
|
if($block->y > 127 or $block->y < 0){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($item->isActivable === true and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)){
|
||||||
|
return $this->cancelAction($block);
|
||||||
|
}
|
||||||
|
|
||||||
if($item->isPlaceable()){
|
if($item->isPlaceable()){
|
||||||
$hand = $item->getBlock();
|
$hand = $item->getBlock();
|
||||||
|
@ -27,10 +27,15 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
|
|
||||||
class ServerAPI{
|
class ServerAPI{
|
||||||
var $restart = false;
|
var $restart = false;
|
||||||
|
private static $serverRequest = false;
|
||||||
private $server;
|
private $server;
|
||||||
private $config;
|
private $config;
|
||||||
private $apiList = array();
|
private $apiList = array();
|
||||||
|
|
||||||
|
public static function request(){
|
||||||
|
return self::$serverRequest;
|
||||||
|
}
|
||||||
|
|
||||||
public function run(){
|
public function run(){
|
||||||
$this->load();
|
$this->load();
|
||||||
return $this->init();
|
return $this->init();
|
||||||
@ -107,6 +112,7 @@ class ServerAPI{
|
|||||||
$this->parseProperties();
|
$this->parseProperties();
|
||||||
define("DEBUG", $this->getProperty("debug"));
|
define("DEBUG", $this->getProperty("debug"));
|
||||||
$this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), false, $this->getProperty("port"), $this->getProperty("server-id"), $this->getProperty("server-ip"));
|
$this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), false, $this->getProperty("port"), $this->getProperty("server-id"), $this->getProperty("server-ip"));
|
||||||
|
self::$serverRequest = $this->server;
|
||||||
$this->setProperty("server-id", $this->server->serverID);
|
$this->setProperty("server-id", $this->server->serverID);
|
||||||
$this->server->api = $this;
|
$this->server->api = $this;
|
||||||
if($this->getProperty("upnp-forwarding") === true){
|
if($this->getProperty("upnp-forwarding") === true){
|
||||||
|
@ -36,6 +36,7 @@ class Item{
|
|||||||
WOODEN_DOOR => "WoodenDoorItem",
|
WOODEN_DOOR => "WoodenDoorItem",
|
||||||
IRON_DOOR => "IronDoorItem",
|
IRON_DOOR => "IronDoorItem",
|
||||||
BED => "BedItem",
|
BED => "BedItem",
|
||||||
|
PAINTING => "PaintingItem",
|
||||||
);
|
);
|
||||||
protected $block;
|
protected $block;
|
||||||
protected $id;
|
protected $id;
|
||||||
@ -44,6 +45,7 @@ class Item{
|
|||||||
protected $maxStackSize = 64;
|
protected $maxStackSize = 64;
|
||||||
protected $durability = 0;
|
protected $durability = 0;
|
||||||
protected $name;
|
protected $name;
|
||||||
|
public $isActivable = false;
|
||||||
|
|
||||||
public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){
|
public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){
|
||||||
$this->id = (int) $id;
|
$this->id = (int) $id;
|
||||||
@ -118,4 +120,8 @@ class Item{
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onActivate(BlockAPI $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
50
src/classes/material/item/generic/Painting.php
Normal file
50
src/classes/material/item/generic/Painting.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
-
|
||||||
|
/ \
|
||||||
|
/ \
|
||||||
|
/ PocketMine \
|
||||||
|
/ MP \
|
||||||
|
|\ @shoghicp /|
|
||||||
|
|. \ / .|
|
||||||
|
| .. \ / .. |
|
||||||
|
| .. | .. |
|
||||||
|
| .. | .. |
|
||||||
|
\ | /
|
||||||
|
\ | /
|
||||||
|
\ | /
|
||||||
|
\ | /
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
class PaintingItem extends Item{
|
||||||
|
public function __construct($meta = 0, $count = 1){
|
||||||
|
parent::__construct(PAINTING, 0, $count, "Painting");
|
||||||
|
$this->isActivable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(BlockAPI $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
|
if($target->isTransparent === false and $face > 1){
|
||||||
|
$data = array(
|
||||||
|
"x" => $target->x,
|
||||||
|
"y" => $target->y,
|
||||||
|
"z" => $target->z,
|
||||||
|
"yaw" => ($face % 4) * 90,
|
||||||
|
);
|
||||||
|
$server = ServerAPI::request();
|
||||||
|
$e = $server->api->entity->add(ENTITY_OBJECT, OBJECT_PAINTING, $data);
|
||||||
|
$server->api->entity->spawnToAll($e->eid);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -226,7 +226,7 @@ class CustomPacketHandler{
|
|||||||
$this->raw .= Utils::writeMetadata($this->data["metadata"]);
|
$this->raw .= Utils::writeMetadata($this->data["metadata"]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MC_ADD_ENTITY:
|
case MC_ADD_ENTITY: //Not used?
|
||||||
if($this->c === false){
|
if($this->c === false){
|
||||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||||
$this->data["type"] = ord($this->get(1));
|
$this->data["type"] = ord($this->get(1));
|
||||||
@ -240,9 +240,6 @@ class CustomPacketHandler{
|
|||||||
$this->raw .= Utils::writeFloat($this->data["y"]);
|
$this->raw .= Utils::writeFloat($this->data["y"]);
|
||||||
$this->raw .= Utils::writeFloat($this->data["z"]);
|
$this->raw .= Utils::writeFloat($this->data["z"]);
|
||||||
$this->raw .= Utils::hexToStr("000000020000ffd30000");//Utils::writeInt(0);
|
$this->raw .= Utils::hexToStr("000000020000ffd30000");//Utils::writeInt(0);
|
||||||
/*$this->raw .= Utils::writeShort(0);
|
|
||||||
$this->raw .= Utils::writeShort(0);
|
|
||||||
$this->raw .= Utils::writeShort(0);*/
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MC_REMOVE_ENTITY:
|
case MC_REMOVE_ENTITY:
|
||||||
@ -380,6 +377,23 @@ class CustomPacketHandler{
|
|||||||
$this->raw .= chr($this->data["meta"]);
|
$this->raw .= chr($this->data["meta"]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case MC_ADD_PAINTING:
|
||||||
|
if($this->c === false){
|
||||||
|
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||||
|
$this->data["x"] = Utils::readInt($this->get(4));
|
||||||
|
$this->data["y"] = Utils::readInt($this->get(4));
|
||||||
|
$this->data["z"] = Utils::readInt($this->get(4));
|
||||||
|
$this->data["direction"] = Utils::readInt($this->get(4));
|
||||||
|
$this->data["title"] = $this->get(Utils::readShort($this->get(2), false));
|
||||||
|
}else{
|
||||||
|
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||||
|
$this->raw .= Utils::writeInt($this->data["x"]);
|
||||||
|
$this->raw .= Utils::writeInt($this->data["y"]);
|
||||||
|
$this->raw .= Utils::writeInt($this->data["z"]);
|
||||||
|
$this->raw .= Utils::writeInt($this->data["direction"]);
|
||||||
|
$this->raw .= Utils::writeShort(strlen($this->data["title"])).$this->data["title"];
|
||||||
|
}
|
||||||
|
break;
|
||||||
case MC_EXPLOSION:
|
case MC_EXPLOSION:
|
||||||
if($this->c === false){
|
if($this->c === false){
|
||||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||||
|
@ -123,6 +123,7 @@ class Entity extends stdClass{
|
|||||||
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
|
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
|
||||||
break;
|
break;
|
||||||
case ENTITY_OBJECT:
|
case ENTITY_OBJECT:
|
||||||
|
$this->setHealth(1, "generic");
|
||||||
//$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
|
//$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
|
||||||
break;
|
break;
|
||||||
case ENTITY_PAINTING:
|
case ENTITY_PAINTING:
|
||||||
@ -392,7 +393,16 @@ class Entity extends stdClass{
|
|||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
case ENTITY_OBJECT:
|
case ENTITY_OBJECT:
|
||||||
//$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
|
if($this->type === OBJECT_PAINTING){
|
||||||
|
$player->dataPacket(MC_ADD_PAINTING, array(
|
||||||
|
"eid" => $this->eid,
|
||||||
|
"x" => (int) $this->x,
|
||||||
|
"y" => (int) $this->y,
|
||||||
|
"z" => (int) $this->z,
|
||||||
|
"direction" => $this->getDirection(),
|
||||||
|
"title" => "Creepers",
|
||||||
|
));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -540,10 +550,12 @@ class Entity extends stdClass{
|
|||||||
$this->crouched = false;
|
$this->crouched = false;
|
||||||
$this->updateMetadata();
|
$this->updateMetadata();
|
||||||
$this->dead = true;
|
$this->dead = true;
|
||||||
|
$this->server->api->dhandle("entity.event", array("entity" => $this, "event" => 3)); //Entity dead
|
||||||
if($this->player instanceof Player){
|
if($this->player instanceof Player){
|
||||||
$this->server->api->dhandle("player.death", array("name" => $this->name, "cause" => $cause));
|
$this->server->api->dhandle("player.death", array("name" => $this->name, "cause" => $cause));
|
||||||
|
}else{
|
||||||
|
$this->close();
|
||||||
}
|
}
|
||||||
$this->server->api->dhandle("entity.event", array("entity" => $this, "event" => 3)); //Entity dead
|
|
||||||
}elseif($this->health > 0){
|
}elseif($this->health > 0){
|
||||||
$this->dead = false;
|
$this->dead = false;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ define("MC_MOVE_PLAYER", 0x94);
|
|||||||
define("MC_PLACE_BLOCK", 0x95);
|
define("MC_PLACE_BLOCK", 0x95);
|
||||||
define("MC_REMOVE_BLOCK", 0x96);
|
define("MC_REMOVE_BLOCK", 0x96);
|
||||||
define("MC_UPDATE_BLOCK", 0x97);
|
define("MC_UPDATE_BLOCK", 0x97);
|
||||||
//define("MC_ADD_PAINTING", 0x98);
|
define("MC_ADD_PAINTING", 0x98);
|
||||||
define("MC_EXPLOSION", 0x99);
|
define("MC_EXPLOSION", 0x99);
|
||||||
define("MC_LEVEL_EVENT", 0x9a);
|
define("MC_LEVEL_EVENT", 0x9a);
|
||||||
//define("MC_TILE_EVENT", 0x9b);
|
//define("MC_TILE_EVENT", 0x9b);
|
||||||
|
@ -59,7 +59,7 @@ $dataName = array(
|
|||||||
MC_PLACE_BLOCK => "PlaceBlock",
|
MC_PLACE_BLOCK => "PlaceBlock",
|
||||||
MC_REMOVE_BLOCK => "RemoveBlock",
|
MC_REMOVE_BLOCK => "RemoveBlock",
|
||||||
MC_UPDATE_BLOCK => "UpdateBlock",
|
MC_UPDATE_BLOCK => "UpdateBlock",
|
||||||
|
MC_ADD_PAINTING => "AddPainting",
|
||||||
MC_EXPLOSION => "Explosion",
|
MC_EXPLOSION => "Explosion",
|
||||||
|
|
||||||
MC_LEVEL_EVENT => "LevelEvent",
|
MC_LEVEL_EVENT => "LevelEvent",
|
||||||
|
Reference in New Issue
Block a user