Place/Breaking/Activation logic separated from BlockAPI

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-03 18:55:59 +01:00
parent 6156baab85
commit d9c87161ba
37 changed files with 387 additions and 216 deletions

View File

@ -38,13 +38,42 @@ class BlockAPI{
public static $class = array();
private $server;
public static function get($id, $meta = 0){
public static function get($id, $meta = 0, $v = false){
$id = (int) $id;
if(isset(BlockAPI::$class[$id])){
$classname = BlockAPI::$class[$id];
return new $classname($meta);
$b = new $classname($meta);
}else{
$b = new GenericBlock($id, $meta, "");
}
return (new GenericBlock($id, $meta, ""));
if($v instanceof Vector3){
$b->position($v);
}
return $b;
}
public function setBlock($block, $id, $meta){
if(($block instanceof Vector3) or (($block instanceof Block) and $block->inWorld === true)){
$this->server->api->level->setBlock($block->x, $block->y, $block->z, (int) $id, (int) $meta);
return true;
}
return false;
}
public function getBlock($x, $y = 0, $z = 0){
if($x instanceof Vector3){
$y = $x->y;
$z = $x->z;
$x = $x->x;
}
$b = $this->server->api->level->getBlock($x, $y, $z);
return BlockAPI::get($b[0], $b[1], new Vector3($b[2][0], $b[2][1], $b[2][2]));
}
public function getBlockFace(Block $block, $face){
$data = array("x" => $block->x, "y" => $block->y, "z" => $block->z);
BlockFace::setPosition($data, $face);
return $this->getBlock($data["x"], $data["y"], $data["z"]);
}
function __construct(PocketMinecraftServer $server){
@ -198,13 +227,13 @@ class BlockAPI{
}
}
private function cancelAction($block){
private function cancelAction(Block $block){
$this->server->api->dhandle("block.change", array(
"x" => $block[2][0],
"y" => $block[2][1],
"z" => $block[2][2],
"block" => $block[0],
"meta" => $block[1],
"x" => $block->x,
"y" => $block->y,
"z" => $block->z,
"block" => $block->getID(),
"meta" => $block->getMetadata(),
"fake" => true,
));
return false;
@ -215,30 +244,19 @@ class BlockAPI{
return;
}
$target = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
$entity = $this->server->api->entity->get($data["eid"]);
if(($entity instanceof Entity) !== true){
return $this->cancelAction($block); //No Entity WTF?
$target = $this->getBlock($data["x"], $data["y"], $data["z"]);
$player = $this->server->api->player->getByEID($data["eid"]);
if(($player instanceof Player) !== true){
return $this->cancelAction($target); //No Entity WTF?
}
$data["entity"] = $entity;
if(isset(Material::$unbreakable[$target[0]]) or $this->server->gamemode === 2){
$data["player"] = $player;
if($target->isBreakable === false or $this->server->gamemode === 2){
return $this->cancelAction($target);
}
$drop = array(
$target[0], //Block
$target[1], //Meta
1, //Count
);
switch($target[0]){
case 1:
$drop[0] = 4;
break;
case 16:
$drop = array(263, 0, 1);
break;
case 21:
$drop = array(351, 4, mt_rand(4, 8));
break;
$item = $player->equipment;
$drops = $target->getDrops($item, $player);
/*switch($target->getID()){
case 62:
$drop[0] = 61;
case 50: //Drop without metadata
@ -256,103 +274,40 @@ class BlockAPI{
case 156:
$drop[1] = 0;
break;
case 56:
$drop = array(264, 0, 1);
break;
case 63:
case 68:
$drop = array(323, 0, 1);
break;
case 73:
case 74:
$drop = array(351, 4, mt_rand(4, 5));
break;
case 18:
$drop = false;
if(mt_rand(1,20) === 1){ //Saplings
$drop = array(6, $target[1], 1);
}
if($target[1] === 0 and mt_rand(1,200) === 1){ //Apples
$this->drop($data["x"], $data["y"], $data["z"], 260, 0, 1);
}
break;
case 59:
if($target[1] >= 0x07){ //Seeds
$drop = array(296, 0, 1);
$this->drop($data["x"], $data["y"], $data["z"], 295, 0, mt_rand(0,3));
}else{
$drop = array(295, 0, 1);
}
break;
case 31:
$drop = false;
if(mt_rand(1,10) === 1){ //Seeds
$drop = array(295, 0, 1);
}
break;
case 20:
$drop = false;
break;
case 30:
$drop = false;
break;
case 51:
$drop = false;
break;
case 52:
$drop = false;
break;
case 43:
$drop = array(
44,
$target[1],
2,
);
break;
case 46: //TNT
if(($player = $this->server->api->player->getByEID($data["eid"])) !== false){
$player->dataPacket(MC_EXPLOSION, array(
"x" => $data["x"],
"y" => $data["y"],
"z" => $data["z"],
"radius" => 2,
"records" => array(),
));
}
break;
case 60:
case 2:
$drop = array(3, 0, 1);
break;
case 64: //Wood Door
case 71: //Iron Door
$drop = array(($target[0] === 64 ? 324:330), 0, 1);
if(($target[1] & 0x08) === 0x08){
$down = $this->server->api->level->getBlock($data["x"], $data["y"] - 1, $data["z"]);
if($down[0] === $target[0]){
if(($target->getMetadata() & 0x08) === 0x08){
$down = $this->getBlock($target->x, $target->y - 1, $target->z);
if($down->getID() === $target->getID()){
$data2 = $data;
--$data2["y"];
$this->server->trigger("player.block.break", $data2);
}
}else{
$up = $this->server->api->level->getBlock($data["x"], $data["y"] + 1, $data["z"]);
if($up[0] === $target[0]){
$up = $this->getBlock($target->x, $target->y + 1, $target->z);
if($up->getID() === $target->getID()){
$data2 = $data;
++$data2["y"];
$this->server->trigger("player.block.break", $data2);
}
}
break;
}*/
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);
}
}
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->trigger("player.block.break", $data);
$this->server->trigger("player.block.break", array(
"block" => $target,
"player" => $player,
"item" => $item,
));
return false;
}
public function drop($x, $y, $z, $block, $meta, $stack = 1){
if($block === 0 or $stack <= 0 or $this->server->gamemode === 1){
if($block === AIR or $stack <= 0 or $this->server->gamemode === 1){
return;
}
$data = array(
@ -385,21 +340,32 @@ class BlockAPI{
if($data["face"] < 0 or $data["face"] > 5){
return false;
}
$data["original"] = array($data["block"], $data["meta"]);
$target = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
$entity = $this->server->api->entity->get($data["eid"]);
if(($entity instanceof Entity) !== true){
return $this->cancelAction($block); //No Entity WTF?
$data["original"] = BlockAPI::get($data["block"], $data["meta"]);
$target = $this->getBlock(new Vector3($data["x"], $data["y"], $data["z"]));
$player = $this->server->api->player->getByEID($data["eid"]);
if(($player instanceof Player) !== true){
return $this->cancelAction($target); //No Entity WTF?
}
$data["entity"] = $entity;
if($target[0] === 0){ //If no block exists
$data["player"] = $player;
$block = $this->getBlockFace($target, $data["face"]);
$item = $player->equipment;
if($target->getID() === AIR){ //If no block exists
$this->cancelAction($target);
$block = $this->server->api->level->getBlockFace($target, $data["face"]);
return $this->cancelAction($block);
}
$cancelPlace = false;
if(isset(Material::$activable[$target[0]])){
if($target->isActivable === true){
if($target->onActivate($this, $item, $player) === true){
return false;
}
}
if($this->server->gamemode === 2){ //Adventure mode!!
return $this->cancelAction($block);
}
/*if(isset(Material::$activable[$target[0]])){
switch($target[0]){
case 54:
$cancelPlace = true;
@ -519,16 +485,11 @@ class BlockAPI{
$cancelPlace = true;
break;
}
}
}*/
if($cancelPlace === true){
return false;
}
if($this->server->gamemode === 2){
return $this->cancelAction($block);
}
/*
$replace = false;
switch($data["block"]){
case 44: //Slabs
@ -564,34 +525,29 @@ class BlockAPI{
}
break;
}
*/
if($replace === false){
BlockFace::setPosition($data, $data["face"]);
}
if($data["y"] >= 127){
if($block->y > 127 or $block->y < 0){
return false;
}
$block = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
if($replace === false and !isset(Material::$replaceable[$block[0]])){
return $this->cancelAction($block);
}
if(isset(Material::$placeable[$data["block"]])){
$data["block"] = Material::$placeable[$data["block"]] === true ? $data["block"]:Material::$placeable[$data["block"]];
if($block->isReplaceable === true and $item->isPlaceable()){
$hand = $item->getBlock();
}else{
return $this->cancelAction($block);
}
if(!isset(Material::$transparent[$data["block"]]) and $entity->inBlock($block[2][0], $block[2][1], $block[2][2])){
if($hand->isTransparent === false and $player->entity->inBlock($block->x, $block->y, $block->z)){
return $this->cancelAction($block); //Entity in block
}
$direction = $entity->getDirection();
//$direction = $player->entity->getDirection();
switch($data["block"]){
if($hand->place($this, $item, $player, $block, $target, $data["face"]) === false){
return false;
}
/*switch($data["block"]){
case 6:
if($target[0] === 60){
break;
@ -800,7 +756,9 @@ class BlockAPI{
}
break;
}
$this->server->handle("player.block.place", $data);
*/
//$this->server->handle("player.block.place", $data);
return false;
}

View File

@ -48,13 +48,12 @@ 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"]);
if($block[0] === 0){
if($data["block"]->getID() === 0){
break;
}
$b = BlockAPI::get($block[0], $block[1]);
console("[DEBUG] Player ".$data["entity"]->player->username." broke ".$b->getName()." (".$block[0].":".$block[1].") at (".$data["x"].", ".$data["y"].", ".$data["z"].")", true, true, 2);
$this->setBlock($data["x"], $data["y"], $data["z"], 0, 0, true, true);
console("[DEBUG] Player ".$data["player"]->username." broke ".$data["block"]->getName()." (".$data["block"]->getID().":".$data["block"]->getMetadata().") at (".$data["block"]->x.", ".$data["block"]->y.", ".$data["block"]->z.")", true, true, 2);
$this->setBlock($data["block"]->x, $data["block"]->y, $data["block"]->z, 0, 0, true, true);
break;
}
}

View File

@ -46,7 +46,7 @@ class Player{
var $MTU;
var $spawned = false;
var $inventory;
var $equipment = array(1, 0);
public $equipment;
var $armor = array(0, 0, 0, 0);
var $loggedIn = false;
function __construct(PocketMinecraftServer $server, $clientID, $ip, $port, $MTU){
@ -57,7 +57,12 @@ class Player{
$this->ip = $ip;
$this->port = $port;
$this->timeout = microtime(true) + 20;
$this->inventory = array_fill(0, 36, array(0, 0, 0));
$this->inventory = array_fill(0, 36, array(AIR, 0, 0));
if($this->server->gamemode === 0 or $this->server->gamemode === 2){
$this->equipment = new Item(AIR);
}else{
$this->equipment = new Item(STONE);
}
$this->evid[] = $this->server->event("server.tick", array($this, "onTick"));
$this->evid[] = $this->server->event("server.close", array($this, "close"));
console("[DEBUG] New Session started with ".$ip.":".$port.". MTU ".$this->MTU.", Client ID ".$this->clientID, true, true, 2);
@ -199,7 +204,7 @@ class Player{
break;
case "player.block.place":
if($data["eid"] === $this->eid and ($this->server->gamemode === 0 or $this->server->gamemode === 2)){
$this->removeItem($data["original"][0], $data["original"][1], 1);
$this->removeItem($data["original"]->getID(), $data["original"]->getMetadata(), 1);
}
break;
case "player.pickup":
@ -547,10 +552,8 @@ class Player{
case MC_PLAYER_EQUIPMENT:
$data["eid"] = $this->eid;
if($this->server->handle("player.equipment.change", $data) !== false){
$this->equipment[0] = $data["block"];
$this->equipment[1] = $data["meta"];
$b = BlockAPI::get($data["block"], $data["meta"]);
console("[DEBUG] Player ".$this->username." has now ".$b->getName()." (".$data["block"].":".$data["meta"].") in their hands!", true, true, 2);
$this->equipment = new Item($data["block"], $data["meta"]);
console("[DEBUG] Player ".$this->username." has now ".$this->equipment->getName()." (".$this->equipment->getID().":".$this->equipment->getMetadata().") in their hands!", true, true, 2);
}
break;
case MC_REQUEST_CHUNK:
@ -639,13 +642,13 @@ class Player{
363 => 3,
364 => 8,
);
if(isset($items[$this->equipment[0]])){
if(isset($items[$this->equipment->getID()])){
$this->removeItem($this->equipment[0], 0, 1);
$this->dataPacket(MC_ENTITY_EVENT, array(
"eid" => 0,
"event" => 9,
));
$this->entity->heal($items[$this->equipment[0]], "eating");
$this->entity->heal($items[$this->equipment->getID()], "eating");
}
break;
}

View File

@ -41,7 +41,9 @@ abstract class Block{
public $inWorld = false;
public $hasPhysics = false;
public $isLiquid = false;
public $v = false;
public $x;
public $y;
public $z;
public function __construct($id, $meta = 0, $name = "Unknown"){
$this->id = (int) $id;
@ -55,7 +57,7 @@ abstract class Block{
}
final public function getID(){
return $id;
return $this->id;
}
final public function getMetadata(){
@ -64,7 +66,9 @@ abstract class Block{
final public function position(Vector3 $v){
$this->inWorld = true;
$this->v = new Vector3((int) $v->x, (int) $v->y, (int) $v->z);
$this->x = (int) $v->x;
$this->y = (int) $v->y;
$this->z = (int) $v->z;
}
public function getDrops(Item $item, Player $player){
@ -73,9 +77,11 @@ abstract class Block{
);
}
abstract function onActivate(LevelAPI $level, Item $item, Player $player);
abstract function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face);
abstract function onUpdate(LevelAPI $level, $type);
abstract function onActivate(BlockAPI $level, Item $item, Player $player);
abstract function onUpdate(BlockAPI $level, $type);
}
require_once("block/GenericBlock.php");

View File

@ -35,6 +35,7 @@ define("PLANK", 5);
define("PLANKS", 5);
define("WOODEN_PLANK", 5);
define("SAPLING", 6);
define("SAPLINGS", 6);
define("BEDROCK", 7);
define("WATER", 8);
define("STILL_WATER", 9);

View File

@ -26,24 +26,70 @@ the Free Software Foundation, either version 3 of the License, or
*/
class Item{
protected $block = false;
protected $id;
protected $meta;
protected $count;
protected $maxStackSize = 64;
protected $durability = 0;
protected $name = "Unknown";
public function __construct($id, $meta = 0){
public function __construct($id, $meta = 0, $count = 1){
$this->id = (int) $id;
$this->meta = (int) $meta;
$this->count = (int) $count;
if(isset(BlockAPI::$class[$this->id])){
$this->block = BlockAPI::get($this->id, $this->meta);
$this->name = $this->block->getName();
}
}
public function getName(){
return $this->name;
}
public function isPlaceable(){
return (($this->block instanceof Block) and $this->block->isPlaceable === true);
}
public function getBlock(){
if($this->block instanceof Block){
return $this->block;
}else{
return BlockAPI::get(AIR);
}
}
public function getID(){
return $this->id;
}
public function getMetadata(){
return $this->meta;
}
public function getMaxStackSize(){
return $this->maxStackSize;
}
public function getDestroySpeed(Item $item, Player $player){
public function isPickaxe(){ //Returns false or level of the pickaxe
switch($this->id){
case IRON_PICKAXE:
return 3;
case 270: //Wood
return 1;
case 274: //Stone
return 2;
case 278: //Diamond
return 4;
case 285: //Gold
return 3;
default:
return false;
}
}
public function getDestroySpeed(Block $block, Player $player){
return 1;
}

View File

@ -29,11 +29,19 @@ the Free Software Foundation, either version 3 of the License, or
class GenericBlock extends Block{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
}
public function onUpdate(LevelAPI $level, $type){
}
public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face){
if($block->inWorld === true){
$level->setBlock($block, $this->id, $this->getMetadata());
return true;
}
return false;
}
public function onActivate(LevelAPI $level, Item $item, Player $player){
public function onUpdate(BlockAPI $level, $type){
return false;
}
public function onActivate(BlockAPI $level, Item $item, Player $player){
return false;
}
}

View File

@ -29,5 +29,6 @@ class LiquidBlock extends TransparentBlock{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isLiquid = true;
$this->isBreakable = false;
}
}

View File

@ -29,6 +29,7 @@ class FireBlock extends FlowableBlock{
public function __construct($meta = 0){
parent::__construct(FIRE, $meta, "Fire");
$this->isReplaceable = true;
$this->isBreakable = false;
}
}

View File

@ -29,5 +29,18 @@ class TNTBlock extends SolidBlock{
public function __construct(){
parent::__construct(TNT, 0, "TNT");
}
public function getDrops(Item $item, Player $player){
if($this->inWorld === true){
$player->dataPacket(MC_EXPLOSION, array(
"x" => $this->x,
"y" => $this->y,
"z" => $this->z,
"radius" => 2,
"records" => array(),
));
}
return array(
array(TNT, 0, 1),
);
}
}

View File

@ -31,9 +31,13 @@ class CoalOreBlock extends SolidBlock{
}
public function getDrops(Item $item, Player $player){
return array(
array(263, 0, 1),
);
if($item->isPickaxe() >= 1){
return array(
array(263, 0, 1), //Coal
);
}else{
return array();
}
}
}

View File

@ -30,4 +30,13 @@ class DiamondOreBlock extends SolidBlock{
parent::__construct(DIAMOND_ORE, 0, "Diamond Ore");
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 3){
return array(
array(264, 0, 1),
);
}else{
return array();
}
}
}

View File

@ -31,9 +31,13 @@ class LapisOreBlock extends SolidBlock{
}
public function getDrops(Item $item, Player $player){
return array(
array(351, 4, 1),
);
if($item->isPickaxe() >= 2){
return array(
array(351, 4, mt_rand(4, 8)),
);
}else{
return array();
}
}
}

View File

@ -29,5 +29,13 @@ class RedstoneOreBlock extends SolidBlock{
public function __construct(){
parent::__construct(REDSTONE_ORE, 0, "Redstone Ore");
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 2){
return array(
//array(331, 4, mt_rand(4, 5)),
);
}else{
return array();
}
}
}

View File

@ -43,11 +43,26 @@ class SaplingBlock extends TransparentBlock{
$this->name = $names[$this->meta & 0x03];
}
public function onActivate(LevelAPI $level, Item $item, Player $player){
TreeObject::growTree($level, $this);
public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face){
if($block->inWorld === true){
$down = $level->getBlockFace($block, 0);
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
$level->setBlock($block, $this->id, $this->getMetadata());
return true;
}
}
return false;
}
public function onUpdate(LevelAPI $level, $type){
public function onActivate(BlockAPI $level, Item $item, Player $player){
if($item->getID() === 351 and $item->getMetadata() === 0x0F){ //Bonemeal
TreeObject::growTree($level, $this);
return true;
}
return false;
}
public function onUpdate(BlockAPI $level, $type){
if($this->inWorld !== true){
return false;
}

View File

@ -38,4 +38,12 @@ class TallGrassBlock extends FlowableBlock{
$this->name = $names[$this->meta & 0x03];
}
public function getDrops(Item $item, Player $player){
$drops = array();
if(mt_rand(1,10) === 1){//Seeds
$drops[] = array(295, 0, 1);
}
return $drops;
}
}

View File

@ -29,5 +29,15 @@ class WheatBlock extends FlowableBlock{
public function __construct($meta = 0){
parent::__construct(WHEAT, $meta, "Wheat");
}
public function getDrops(Item $item, Player $player){
$drops = array();
if($this->meta >= 0x07){
$drops[] = array(296, 0, 1);
$drops[] = array(295, 0, mt_rand(0, 3));
}else{
$drops[] = array(295, 0, 1);
}
return $drops;
}
}

View File

@ -31,4 +31,14 @@ class BurningFurnaceBlock extends SolidBlock{
$this->isActivable = true;
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(FURNACE, 0, 1),
);
}else{
return array();
}
}
}

View File

@ -30,5 +30,7 @@ class CobwebBlock extends FlowableBlock{
parent::__construct(COBWEB, 0, "Cobweb");
$this->isFlowable = true;
}
public function getDrops(Item $item, Player $player){
return array();
}
}

View File

@ -40,5 +40,10 @@ class DoubleSlabBlock extends SolidBlock{
);
$this->name = "Double " . $names[$this->meta & 0x07] . " Slab";
}
public function getDrops(Item $item, Player $player){
return array(
array(SLAB, $this->meta & 0x07, 2),
);
}
}

View File

@ -29,5 +29,9 @@ class FarmlandBlock extends SolidBlock{
public function __construct($meta = 0){
parent::__construct(FARMLAND, $meta, "Farmland");
}
public function getDrops(Item $item, Player $player){
return array(
array(DIRT, 0, 1),
);
}
}

View File

@ -31,4 +31,13 @@ class FurnaceBlock extends SolidBlock{
$this->isActivable = true;
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(FURNACE, 0, 1),
);
}else{
return array();
}
}
}

View File

@ -30,4 +30,7 @@ class GlassBlock extends TransparentBlock{
parent::__construct(GLASS, 0, "Glass");
}
public function getDrops(Item $item, Player $player){
return array();
}
}

View File

@ -29,5 +29,9 @@ class GrassBlock extends SolidBlock{
public function __construct(){
parent::__construct(GRASS, 0, "Grass");
}
public function getDrops(Item $item, Player $player){
return array(
array(DIRT, 0, 1),
);
}
}

View File

@ -30,5 +30,9 @@ class IronDoorBlock extends TransparentBlock{
parent::__construct(IRON_DOOR, $meta, "Iron Door");
$this->isActivable = true;
}
public function getDrops(Item $item, Player $player){
return array(
array(330, 0, 1),
);
}
}

View File

@ -26,14 +26,26 @@ the Free Software Foundation, either version 3 of the License, or
*/
class LeavesBlock extends TransparentBlock{
const OAK = 0;
const SPRUCE = 1;
const BIRCH = 2;
public function __construct($meta = 0){
parent::__construct(LEAVES, $meta, "Leaves");
$names = array(
0 => "Oak Leaves",
1 => "Spruce Leaves",
2 => "Birch Leaves",
LeavesBlock::OAK => "Oak Leaves",
LeavesBlock::SPRUCE => "Spruce Leaves",
LeavesBlock::BIRCH => "Birch Leaves",
);
$this->name = $names[$this->meta & 0x03];
}
public function getDrops(Item $item, Player $player){
$drops = array();
if(mt_rand(1,20) === 1){ //Saplings
$drops[] = array(SAPLING, $this->meta & 0x03, 1);
}
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
$drops[] = array(260, 0, 1);
}
return $drops;
}
}

View File

@ -27,7 +27,7 @@ the Free Software Foundation, either version 3 of the License, or
class NetherrackBlock extends SolidBlock{
public function __construct(){
parent::__construct(NETHERRACK, 0, "Netherrrack");
parent::__construct(NETHERRACK, 0, "Netherrack");
}
}

View File

@ -29,5 +29,9 @@ class SignPostBlock extends TransparentBlock{
public function __construct($meta = 0){
parent::__construct(SIGN_POST, $meta, "Sign Post");
}
public function getDrops(Item $item, Player $player){
return array(
array(323, 0, 1),
);
}
}

View File

@ -30,4 +30,14 @@ class StoneBlock extends SolidBlock{
parent::__construct(STONE, 0, "Stone");
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(COBBLESTONE, 0, 1),
);
}else{
return array();
}
}
}

View File

@ -29,5 +29,10 @@ class WallSignBlock extends TransparentBlock{
public function __construct($meta = 0){
parent::__construct(WALL_SIGN, $meta, "Wall Sign");
}
public function getDrops(Item $item, Player $player){
return array(
array(323, 0, 1),
);
}
}

View File

@ -32,9 +32,9 @@ class WoodBlock extends SolidBlock{
public function __construct($meta = 0){
parent::__construct(WOOD, $meta, "Wood");
$names = array(
0 => "Oak Wood",
1 => "Spruce Wood",
2 => "Birch Wood",
WoodBlock::OAK => "Oak Wood",
WoodBlock::SPRUCE => "Spruce Wood",
WoodBlock::BIRCH => "Birch Wood",
);
$this->name = $names[$this->meta & 0x03];
}

View File

@ -31,4 +31,9 @@ class WoodDoorBlock extends TransparentBlock{
$this->isActivable = true;
}
public function getDrops(Item $item, Player $player){
return array(
array(324, 0, 1),
);
}
}

View File

@ -43,11 +43,11 @@ class BigTreeObject extends TreeObject{
private $addLogVines = false;
private $addCocoaPlants = false;
public function canPlaceObject(LevelAPI $level, $x, $y, $z){
public function canPlaceObject(BlockAPI $level, $x, $y, $z){
return false;
}
public function placeObject(LevelAPI $level, $x, $y, $z, $type){
public function placeObject(BlockAPI $level, $x, $y, $z, $type){
$this->trunkHeight = (int) ($this->totalHeight * $this->trunkHeightMultiplier);
$leaves = $this->getLeafGroupPoints($level, $x, $y, $z);

View File

@ -34,7 +34,7 @@ class PineTreeObject extends TreeObject{
private $leavesSizeY = -1;
private $leavesAbsoluteMaxRadius = -1;
public function canPlaceObject(LevelAPI $level, $x, $y, $z){
public function canPlaceObject(BlockAPI $level, $x, $y, $z){
$this->findRandomLeavesSize();
$checkRadius = 0;
for($yy = 0; $yy < $this->totalHeight; ++$yy) {
@ -44,7 +44,7 @@ class PineTreeObject extends TreeObject{
for($xx = -$checkRadius; $xx < ($checkRadius + 1); ++$xx){
for($zz = -$checkRadius; $zz < ($checkRadius + 1); ++$zz){
$block = $level->getBlock($x + $xx, $y + $yy, $z + $zz);
if(!isset($this->overridable[$block[0]])){
if(!isset($this->overridable[$block->getID()])){
return false;
}
}
@ -59,11 +59,11 @@ class PineTreeObject extends TreeObject{
$this->leavesAbsoluteMaxRadius = 2 + mt_rand(0, 2);
}
public function placeObject(LevelAPI $level, $x, $y, $z){
public function placeObject(BlockAPI $level, $x, $y, $z){
if($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1) {
$this->findRandomLeavesSize();
}
$level->setBlock($x, $y - 1, $z, 3, 0);
$level->setBlock(new Vector3($x, $y - 1, $z), 3, 0);
$leavesRadius = mt_rand(0,2);
$leavesMaxRadius = 1;
$leavesBottomY = $this->totalHeight - $this->leavesSizeY;
@ -73,7 +73,7 @@ class PineTreeObject extends TreeObject{
for ($xx = -$leavesRadius; $xx < ($leavesRadius + 1); ++$xx) {
for ($zz = -$leavesRadius; $zz < ($leavesRadius + 1); ++$zz) {
if (abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) {
$level->setBlock($x + $xx, $y + $yy, $z + $zz, 18, $this->type);
$level->setBlock(New Vector3($x + $xx, $y + $yy, $z + $zz), 18, $this->type);
}
}
}
@ -89,7 +89,7 @@ class PineTreeObject extends TreeObject{
}
$trunkHeightReducer = mt_rand(0,3);
for($yy = 0; $yy < ($this->totalHeight - $trunkHeightReducer); ++$yy){
$level->setBlock($x, $y + $yy, $z, 17, $this->type);
$level->setBlock(new Vector3($x, $y + $yy, $z), 17, $this->type);
}
}

View File

@ -37,7 +37,7 @@ class SmallTreeObject extends TreeObject{
private $addLogVines = false;
private $addCocoaPlants = false;
public function canPlaceObject(LevelAPI $level, $x, $y, $z){
public function canPlaceObject(BlockAPI $level, $x, $y, $z){
$radiusToCheck = $this->radiusIncrease;
for ($yy = 0; $yy < $this->totalHeight + 2; ++$yy) {
if ($yy == 1 or $yy === $this->totalHeight - 1) {
@ -45,8 +45,8 @@ class SmallTreeObject extends TreeObject{
}
for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){
for($zz = -$radiusToCheck; $zz < ($radiusToCheck + 1); ++$zz){
$block = $level->getBlock($x + $xx, $y + $yy, $z + $zz);
if(!isset($this->overridable[$block[0]])){
$block = $level->getBlock(new Vector3($x + $xx, $y + $yy, $z + $zz));
if(!isset($this->overridable[$block->getID()])){
return false;
}
}
@ -55,8 +55,8 @@ class SmallTreeObject extends TreeObject{
return true;
}
public function placeObject(LevelAPI $level, $x, $y, $z){
$level->setBlock($x, $y - 1, $z, 3, 0);
public function placeObject(BlockAPI $level, $x, $y, $z){
$level->setBlock(new Vector3($x, $y - 1, $z), 3, 0);
$this->totalHeight += mt_rand(-1, 3);
$this->leavesHeight += mt_rand(0, 1);
for($yy = ($this->totalHeight - $this->leavesHeight); $yy < ($this->totalHeight + 1); ++$yy){
@ -65,13 +65,13 @@ class SmallTreeObject extends TreeObject{
for($xx = -$xzRadius; $xx < ($xzRadius + 1); ++$xx){
for($zz = -$xzRadius; $zz < ($xzRadius + 1); ++$zz){
if((abs($xx) != $xzRadius or abs($zz) != $xzRadius) and $yRadius != 0){
$level->setBlock($x + $xx, $y + $yy, $z + $zz, 18, $this->type);
$level->setBlock(new Vector3($x + $xx, $y + $yy, $z + $zz), 18, $this->type);
}
}
}
}
for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){
$level->setBlock($x, $y + $yy, $z, 17, $this->type);
$level->setBlock(new Vector3($x, $y + $yy, $z), 17, $this->type);
}
}

View File

@ -34,7 +34,7 @@ class SpruceTreeObject extends TreeObject{
private $leavesBottomY = -1;
private $leavesMaxRadius = -1;
public function canPlaceObject(LevelAPI $level, $x, $y, $z){
public function canPlaceObject(BlockAPI $level, $x, $y, $z){
$this->findRandomLeavesSize();
$checkRadius = 0;
for($yy = 0; $yy < $this->totalHeight + 2; ++$yy) {
@ -43,8 +43,8 @@ class SpruceTreeObject extends TreeObject{
}
for($xx = -$checkRadius; $xx < ($checkRadius + 1); ++$xx){
for($zz = -$checkRadius; $zz < ($checkRadius + 1); ++$zz){
$block = $level->getBlock($x + $xx, $y + $yy, $z + $zz);
if(!isset($this->overridable[$block[0]])){
$block = $level->getBlock(new Vector3($x + $xx, $y + $yy, $z + $zz));
if(!isset($this->overridable[$block->getID()])){
return false;
}
}
@ -59,17 +59,17 @@ class SpruceTreeObject extends TreeObject{
$this->leavesMaxRadius = 1 + mt_rand(0, 1);
}
public function placeObject(LevelAPI $level, $x, $y, $z){
public function placeObject(BlockAPI $level, $x, $y, $z){
if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) {
$this->findRandomLeavesSize();
}
$level->setBlock($x, $y - 1, $z, 3, 0);
$level->setBlock(new Vector3($x, $y - 1, $z), 3, 0);
$leavesRadius = 0;
for($yy = $this->totalHeight; $yy >= $this->leavesBottomY; --$yy){
for ($xx = -$leavesRadius; $xx < ($leavesRadius + 1); ++$xx) {
for ($zz = -$leavesRadius; $zz < ($leavesRadius + 1); ++$zz) {
if (abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) {
$level->setBlock($x + $xx, $y + $yy, $z + $zz, 18, $this->type);
$level->setBlock(new Vector3($x + $xx, $y + $yy, $z + $zz), 18, $this->type);
}
}
}
@ -80,7 +80,7 @@ class SpruceTreeObject extends TreeObject{
}
}
for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){
$level->setBlock($x, $y + $yy, $z, 17, $this->type);
$level->setBlock(new Vector3($x, $y + $yy, $z), 17, $this->type);
}
}

View File

@ -33,7 +33,7 @@ class TreeObject{
17 => true,
18 => true,
);
public static function growTree(LevelAPI $level, Block $block){
public static function growTree(BlockAPI $level, Block $block){
switch($block->getMetadata() & 0x03){
case SaplingBlock::SPRUCE:
if(mt_rand(0,1) == 1){
@ -55,8 +55,8 @@ class TreeObject{
}
break;
}
if($tree->canPlaceObject($level, $block->v->x, $block->v->y, $block->v->z)){
$tree->placeObject($level, $block->v->x, $block->v->y, $block->v->z);
if($tree->canPlaceObject($level, $block->x, $block->y, $block->z)){
$tree->placeObject($level, $block->x, $block->y, $block->z);
}
}
}