mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 03:59:43 +00:00
Place/Breaking/Activation logic separated from BlockAPI
This commit is contained in:
parent
6156baab85
commit
d9c87161ba
37 changed files with 387 additions and 216 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,7 @@ class FireBlock extends FlowableBlock{
|
|||
public function __construct($meta = 0){
|
||||
parent::__construct(FIRE, $meta, "Fire");
|
||||
$this->isReplaceable = true;
|
||||
$this->isBreakable = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -30,4 +30,7 @@ class GlassBlock extends TransparentBlock{
|
|||
parent::__construct(GLASS, 0, "Glass");
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
|
@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,4 +31,9 @@ class WoodDoorBlock extends TransparentBlock{
|
|||
$this->isActivable = true;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
array(324, 0, 1),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue