Weird Painting spawn (WiP)

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-05 23:25:40 +01:00
parent 0be3379720
commit 1c05455514
8 changed files with 103 additions and 10 deletions

View File

@ -194,11 +194,12 @@ class BlockAPI{
for($count = $stack; $count > 0; ){
$data["stack"] = min(64, $count);
$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->speedY = mt_rand(0, 5) / 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){
return false;
}
if($item->isActivable === true and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)){
return $this->cancelAction($block);
}
if($item->isPlaceable()){
$hand = $item->getBlock();

View File

@ -27,10 +27,15 @@ the Free Software Foundation, either version 3 of the License, or
class ServerAPI{
var $restart = false;
private static $serverRequest = false;
private $server;
private $config;
private $apiList = array();
public static function request(){
return self::$serverRequest;
}
public function run(){
$this->load();
return $this->init();
@ -107,6 +112,7 @@ class ServerAPI{
$this->parseProperties();
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"));
self::$serverRequest = $this->server;
$this->setProperty("server-id", $this->server->serverID);
$this->server->api = $this;
if($this->getProperty("upnp-forwarding") === true){

View File

@ -36,6 +36,7 @@ class Item{
WOODEN_DOOR => "WoodenDoorItem",
IRON_DOOR => "IronDoorItem",
BED => "BedItem",
PAINTING => "PaintingItem",
);
protected $block;
protected $id;
@ -44,6 +45,7 @@ class Item{
protected $maxStackSize = 64;
protected $durability = 0;
protected $name;
public $isActivable = false;
public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){
$this->id = (int) $id;
@ -118,4 +120,8 @@ class Item{
return 1;
}
public function onActivate(BlockAPI $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
return false;
}
}

View 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;
}
}

View File

@ -226,7 +226,7 @@ class CustomPacketHandler{
$this->raw .= Utils::writeMetadata($this->data["metadata"]);
}
break;
case MC_ADD_ENTITY:
case MC_ADD_ENTITY: //Not used?
if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4));
$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["z"]);
$this->raw .= Utils::hexToStr("000000020000ffd30000");//Utils::writeInt(0);
/*$this->raw .= Utils::writeShort(0);
$this->raw .= Utils::writeShort(0);
$this->raw .= Utils::writeShort(0);*/
}
break;
case MC_REMOVE_ENTITY:
@ -380,6 +377,23 @@ class CustomPacketHandler{
$this->raw .= chr($this->data["meta"]);
}
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:
if($this->c === false){
$this->data["x"] = Utils::readFloat($this->get(4));

View File

@ -123,6 +123,7 @@ class Entity extends stdClass{
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
break;
case ENTITY_OBJECT:
$this->setHealth(1, "generic");
//$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
break;
case ENTITY_PAINTING:
@ -392,7 +393,16 @@ class Entity extends stdClass{
));
break;
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;
}
}
@ -540,10 +550,12 @@ class Entity extends stdClass{
$this->crouched = false;
$this->updateMetadata();
$this->dead = true;
$this->server->api->dhandle("entity.event", array("entity" => $this, "event" => 3)); //Entity dead
if($this->player instanceof Player){
$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){
$this->dead = false;
}

View File

@ -56,7 +56,7 @@ define("MC_MOVE_PLAYER", 0x94);
define("MC_PLACE_BLOCK", 0x95);
define("MC_REMOVE_BLOCK", 0x96);
define("MC_UPDATE_BLOCK", 0x97);
//define("MC_ADD_PAINTING", 0x98);
define("MC_ADD_PAINTING", 0x98);
define("MC_EXPLOSION", 0x99);
define("MC_LEVEL_EVENT", 0x9a);
//define("MC_TILE_EVENT", 0x9b);

View File

@ -59,7 +59,7 @@ $dataName = array(
MC_PLACE_BLOCK => "PlaceBlock",
MC_REMOVE_BLOCK => "RemoveBlock",
MC_UPDATE_BLOCK => "UpdateBlock",
MC_ADD_PAINTING => "AddPainting",
MC_EXPLOSION => "Explosion",
MC_LEVEL_EVENT => "LevelEvent",