diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index a9d089163..65040a5af 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -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; } diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index be8acf7bc..90a42eb1f 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -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; } } diff --git a/src/classes/Player.php b/src/classes/Player.php index d356274c4..0ecfdfbc2 100644 --- a/src/classes/Player.php +++ b/src/classes/Player.php @@ -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; } diff --git a/src/classes/material/Block.php b/src/classes/material/Block.php index 14f189343..e93df91a3 100644 --- a/src/classes/material/Block.php +++ b/src/classes/material/Block.php @@ -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"); diff --git a/src/classes/material/IDs.php b/src/classes/material/IDs.php index 53a4c7533..509389b7f 100644 --- a/src/classes/material/IDs.php +++ b/src/classes/material/IDs.php @@ -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); diff --git a/src/classes/material/Item.php b/src/classes/material/Item.php index af45370fd..b5a1e9f27 100644 --- a/src/classes/material/Item.php +++ b/src/classes/material/Item.php @@ -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; } diff --git a/src/classes/material/block/GenericBlock.php b/src/classes/material/block/GenericBlock.php index e09d48202..bddb14430 100644 --- a/src/classes/material/block/GenericBlock.php +++ b/src/classes/material/block/GenericBlock.php @@ -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; } } \ No newline at end of file diff --git a/src/classes/material/block/LiquidBlock.php b/src/classes/material/block/LiquidBlock.php index 14529b2ae..f11bbcf2b 100644 --- a/src/classes/material/block/LiquidBlock.php +++ b/src/classes/material/block/LiquidBlock.php @@ -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; } } \ No newline at end of file diff --git a/src/classes/material/block/misc/Fire.php b/src/classes/material/block/misc/Fire.php index 5013a55d1..756cd8032 100644 --- a/src/classes/material/block/misc/Fire.php +++ b/src/classes/material/block/misc/Fire.php @@ -29,6 +29,7 @@ class FireBlock extends FlowableBlock{ public function __construct($meta = 0){ parent::__construct(FIRE, $meta, "Fire"); $this->isReplaceable = true; + $this->isBreakable = false; } } \ No newline at end of file diff --git a/src/classes/material/block/misc/TNT.php b/src/classes/material/block/misc/TNT.php index 3b6a3a8f0..f4974e0fe 100644 --- a/src/classes/material/block/misc/TNT.php +++ b/src/classes/material/block/misc/TNT.php @@ -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), + ); + } } \ No newline at end of file diff --git a/src/classes/material/block/ore/CoalOre.php b/src/classes/material/block/ore/CoalOre.php index ec13e6302..adbad8053 100644 --- a/src/classes/material/block/ore/CoalOre.php +++ b/src/classes/material/block/ore/CoalOre.php @@ -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(); + } } } \ No newline at end of file diff --git a/src/classes/material/block/ore/DiamondOre.php b/src/classes/material/block/ore/DiamondOre.php index b4d664d87..5178c1244 100644 --- a/src/classes/material/block/ore/DiamondOre.php +++ b/src/classes/material/block/ore/DiamondOre.php @@ -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(); + } + } } \ No newline at end of file diff --git a/src/classes/material/block/ore/LapisOre.php b/src/classes/material/block/ore/LapisOre.php index d9229a651..fa32e9549 100644 --- a/src/classes/material/block/ore/LapisOre.php +++ b/src/classes/material/block/ore/LapisOre.php @@ -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(); + } } } \ No newline at end of file diff --git a/src/classes/material/block/ore/RedstoneOre.php b/src/classes/material/block/ore/RedstoneOre.php index fdaf8b601..796198aad 100644 --- a/src/classes/material/block/ore/RedstoneOre.php +++ b/src/classes/material/block/ore/RedstoneOre.php @@ -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(); + } + } } \ No newline at end of file diff --git a/src/classes/material/block/plant/Sapling.php b/src/classes/material/block/plant/Sapling.php index c98a6e335..61f5d6aab 100644 --- a/src/classes/material/block/plant/Sapling.php +++ b/src/classes/material/block/plant/Sapling.php @@ -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; } diff --git a/src/classes/material/block/plant/TallGrass.php b/src/classes/material/block/plant/TallGrass.php index 3abc14aea..dd3cc1f37 100644 --- a/src/classes/material/block/plant/TallGrass.php +++ b/src/classes/material/block/plant/TallGrass.php @@ -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; + } + } \ No newline at end of file diff --git a/src/classes/material/block/plant/Wheat.php b/src/classes/material/block/plant/Wheat.php index 1e9265f44..c901ec748 100644 --- a/src/classes/material/block/plant/Wheat.php +++ b/src/classes/material/block/plant/Wheat.php @@ -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; + } } \ No newline at end of file diff --git a/src/classes/material/block/solid/BurningFurnace.php b/src/classes/material/block/solid/BurningFurnace.php index 63a48e67c..cb20a093f 100644 --- a/src/classes/material/block/solid/BurningFurnace.php +++ b/src/classes/material/block/solid/BurningFurnace.php @@ -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(); + } + } + } \ No newline at end of file diff --git a/src/classes/material/block/solid/Cobweb.php b/src/classes/material/block/solid/Cobweb.php index d191bb8e0..7e29a61de 100644 --- a/src/classes/material/block/solid/Cobweb.php +++ b/src/classes/material/block/solid/Cobweb.php @@ -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(); + } } \ No newline at end of file diff --git a/src/classes/material/block/solid/DoubleSlab.php b/src/classes/material/block/solid/DoubleSlab.php index 51ea72dba..136ba9224 100644 --- a/src/classes/material/block/solid/DoubleSlab.php +++ b/src/classes/material/block/solid/DoubleSlab.php @@ -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), + ); + } } \ No newline at end of file diff --git a/src/classes/material/block/solid/Farmland.php b/src/classes/material/block/solid/Farmland.php index c50e94e2f..1b78e55f2 100644 --- a/src/classes/material/block/solid/Farmland.php +++ b/src/classes/material/block/solid/Farmland.php @@ -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), + ); + } } \ No newline at end of file diff --git a/src/classes/material/block/solid/Furnace.php b/src/classes/material/block/solid/Furnace.php index 7a64dae4d..6cd1b1492 100644 --- a/src/classes/material/block/solid/Furnace.php +++ b/src/classes/material/block/solid/Furnace.php @@ -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(); + } + } } \ No newline at end of file diff --git a/src/classes/material/block/solid/Glass.php b/src/classes/material/block/solid/Glass.php index 20ef6174c..f88f757a5 100644 --- a/src/classes/material/block/solid/Glass.php +++ b/src/classes/material/block/solid/Glass.php @@ -30,4 +30,7 @@ class GlassBlock extends TransparentBlock{ parent::__construct(GLASS, 0, "Glass"); } + public function getDrops(Item $item, Player $player){ + return array(); + } } \ No newline at end of file diff --git a/src/classes/material/block/solid/Grass.php b/src/classes/material/block/solid/Grass.php index 163537e0f..82c5b9add 100644 --- a/src/classes/material/block/solid/Grass.php +++ b/src/classes/material/block/solid/Grass.php @@ -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), + ); + } } \ No newline at end of file diff --git a/src/classes/material/block/solid/IronDoor.php b/src/classes/material/block/solid/IronDoor.php index b0b3e5a29..71d47e324 100644 --- a/src/classes/material/block/solid/IronDoor.php +++ b/src/classes/material/block/solid/IronDoor.php @@ -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), + ); + } } \ No newline at end of file diff --git a/src/classes/material/block/solid/Leaves.php b/src/classes/material/block/solid/Leaves.php index 9af56ea07..92f009066 100644 --- a/src/classes/material/block/solid/Leaves.php +++ b/src/classes/material/block/solid/Leaves.php @@ -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; + } } \ No newline at end of file diff --git a/src/classes/material/block/solid/Netherrack.php b/src/classes/material/block/solid/Netherrack.php index e78fc9290..062d563aa 100644 --- a/src/classes/material/block/solid/Netherrack.php +++ b/src/classes/material/block/solid/Netherrack.php @@ -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"); } } \ No newline at end of file diff --git a/src/classes/material/block/solid/SignPost.php b/src/classes/material/block/solid/SignPost.php index 84a55f877..fa0d3a2b0 100644 --- a/src/classes/material/block/solid/SignPost.php +++ b/src/classes/material/block/solid/SignPost.php @@ -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), + ); + } } \ No newline at end of file diff --git a/src/classes/material/block/solid/Stone.php b/src/classes/material/block/solid/Stone.php index d45b72b36..d789babf6 100644 --- a/src/classes/material/block/solid/Stone.php +++ b/src/classes/material/block/solid/Stone.php @@ -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(); + } + } + } \ No newline at end of file diff --git a/src/classes/material/block/solid/WallSign.php b/src/classes/material/block/solid/WallSign.php index 47f2be412..2d13b60ea 100644 --- a/src/classes/material/block/solid/WallSign.php +++ b/src/classes/material/block/solid/WallSign.php @@ -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), + ); + } } \ No newline at end of file diff --git a/src/classes/material/block/solid/Wood.php b/src/classes/material/block/solid/Wood.php index 45a499087..a87c3b360 100644 --- a/src/classes/material/block/solid/Wood.php +++ b/src/classes/material/block/solid/Wood.php @@ -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]; } diff --git a/src/classes/material/block/solid/WoodDoor.php b/src/classes/material/block/solid/WoodDoor.php index 9b0988b6b..24fe88c50 100644 --- a/src/classes/material/block/solid/WoodDoor.php +++ b/src/classes/material/block/solid/WoodDoor.php @@ -31,4 +31,9 @@ class WoodDoorBlock extends TransparentBlock{ $this->isActivable = true; } + public function getDrops(Item $item, Player $player){ + return array( + array(324, 0, 1), + ); + } } \ No newline at end of file diff --git a/src/classes/world/generator/object/tree/BigTreeObject.php b/src/classes/world/generator/object/tree/BigTreeObject.php index 4402acb08..e32a111b3 100644 --- a/src/classes/world/generator/object/tree/BigTreeObject.php +++ b/src/classes/world/generator/object/tree/BigTreeObject.php @@ -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); diff --git a/src/classes/world/generator/object/tree/PineTreeObject.php b/src/classes/world/generator/object/tree/PineTreeObject.php index 0c89c2cf1..1fd86cb86 100644 --- a/src/classes/world/generator/object/tree/PineTreeObject.php +++ b/src/classes/world/generator/object/tree/PineTreeObject.php @@ -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); } } diff --git a/src/classes/world/generator/object/tree/SmallTreeObject.php b/src/classes/world/generator/object/tree/SmallTreeObject.php index d393b8823..3a49aa905 100644 --- a/src/classes/world/generator/object/tree/SmallTreeObject.php +++ b/src/classes/world/generator/object/tree/SmallTreeObject.php @@ -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); } } diff --git a/src/classes/world/generator/object/tree/SpruceTreeObject.php b/src/classes/world/generator/object/tree/SpruceTreeObject.php index 7472ff2a8..ea620361a 100644 --- a/src/classes/world/generator/object/tree/SpruceTreeObject.php +++ b/src/classes/world/generator/object/tree/SpruceTreeObject.php @@ -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); } } diff --git a/src/classes/world/generator/object/tree/TreeObject.php b/src/classes/world/generator/object/tree/TreeObject.php index 9bdb42511..3ebd4586d 100644 --- a/src/classes/world/generator/object/tree/TreeObject.php +++ b/src/classes/world/generator/object/tree/TreeObject.php @@ -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); } } } \ No newline at end of file