From 2976db25c3dbc2bd7722087b06b5a16915689826 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 9 Jun 2013 14:59:02 +0200 Subject: [PATCH] Basic implementation of Fire --- src/Player.php | 4 +- src/constants/ItemIDs.php | 1 + src/material/Item.php | 6 ++- src/material/block/misc/Fire.php | 20 ++++++++- src/material/item/generic/Bucket.php | 3 +- src/material/item/tool/FlintSteel.php | 44 +++++++++++++++++++ .../item/{generic => tool}/IronAxe.php | 0 .../item/{generic => tool}/IronHoe.php | 0 .../item/{generic => tool}/IronPickaxe.php | 0 .../item/{generic => tool}/IronShovel.php | 0 .../item/{generic => tool}/WoodenAxe.php | 0 .../item/{generic => tool}/WoodenPickaxe.php | 0 .../item/{generic => tool}/WoodenShovel.php | 0 .../item/{generic => tool}/WoodenSword.php | 0 14 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 src/material/item/tool/FlintSteel.php rename src/material/item/{generic => tool}/IronAxe.php (100%) rename src/material/item/{generic => tool}/IronHoe.php (100%) rename src/material/item/{generic => tool}/IronPickaxe.php (100%) rename src/material/item/{generic => tool}/IronShovel.php (100%) rename src/material/item/{generic => tool}/WoodenAxe.php (100%) rename src/material/item/{generic => tool}/WoodenPickaxe.php (100%) rename src/material/item/{generic => tool}/WoodenShovel.php (100%) rename src/material/item/{generic => tool}/WoodenSword.php (100%) diff --git a/src/Player.php b/src/Player.php index bb94f9447..4e87092fa 100644 --- a/src/Player.php +++ b/src/Player.php @@ -210,7 +210,9 @@ class Player{ )); $inv = array(); foreach($this->inventory as $slot => $item){ - $inv[$slot] = array($item->getID(), $item->getMetadata(), $item->count); + if($slot < (($this->gamemode & 0x01) === 0 ? PLAYER_SURVIVAL_SLOTS:PLAYER_CREATIVE_SLOTS)){ + $inv[$slot] = array($item->getID(), $item->getMetadata(), $item->count); + } } $this->data->set("inventory", $inv); diff --git a/src/constants/ItemIDs.php b/src/constants/ItemIDs.php index ca8e3a476..dc3636e45 100644 --- a/src/constants/ItemIDs.php +++ b/src/constants/ItemIDs.php @@ -29,6 +29,7 @@ define("IRON_SHOVEL", 256);//Implemented define("IRON_PICKAXE", 257);//Implemented define("IRON_AXE", 258);//Implemented define("FLINT_STEEL", 259); +define("FLINT_AND_STEEL", 259); define("APPLE", 260);//Implemented define("BOW", 261); define("ARROW", 262); diff --git a/src/material/Item.php b/src/material/Item.php index a0ff0cc89..f6d0a8729 100644 --- a/src/material/Item.php +++ b/src/material/Item.php @@ -55,6 +55,7 @@ class Item{ WOODEN_SHOVEL => "WoodenShovelItem", WOODEN_PICKAXE => "WoodenPickaxeItem", WOODEN_AXE => "WoodenAxeItem", + FLINT_STEEL => "FlintSteelItem", ); protected $block; protected $id; @@ -74,6 +75,9 @@ class Item{ $this->block = BlockAPI::get($this->id, $this->meta); $this->name = $this->block->getName(); } + if($this->isTool() !== false){ + $this->maxStackSize = 1; + } } final public function getName(){ @@ -138,7 +142,7 @@ class Item{ } final public function isTool(){ - return ($this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false or $this->isSword() !== false or $this->isHoe() !== false); + return ($this->id === FLINT_STEEL or $this->id === SHEARS or $this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false or $this->isSword() !== false or $this->isHoe() !== false); } final public function isPickaxe(){ //Returns false or level of the pickaxe diff --git a/src/material/block/misc/Fire.php b/src/material/block/misc/Fire.php index 14f798ea9..7deaaad94 100644 --- a/src/material/block/misc/Fire.php +++ b/src/material/block/misc/Fire.php @@ -31,7 +31,25 @@ class FireBlock extends FlowableBlock{ $this->isReplaceable = true; $this->breakable = false; $this->isFullBlock = true; - + } + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + for($s = 0; $s <= 5; ++$s){ + $side = $this->getSide($s); + if($side->getID() !== AIR and !($side instanceof LiquidBlock)){ + return false; + } + } + $this->level->setBlock($this, new AirBlock(), false); + return BLOCK_UPDATE_NORMAL; + }elseif($type === BLOCK_UPDATE_RANDOM){ + if($this->getSide(0)->getID() !== NETHERRACK){ + $this->level->setBlock($this, new AirBlock(), false); + return BLOCK_UPDATE_NORMAL; + } + } + return false; } } \ No newline at end of file diff --git a/src/material/item/generic/Bucket.php b/src/material/item/generic/Bucket.php index e100d713a..e2433d50d 100644 --- a/src/material/item/generic/Bucket.php +++ b/src/material/item/generic/Bucket.php @@ -27,8 +27,7 @@ the Free Software Foundation, either version 3 of the License, or class BucketItem extends Item{ public function __construct($meta = 0, $count = 1){ - parent::__construct(BUCKET, 0, $count, "Bucket"); - $this->meta = $meta; + parent::__construct(BUCKET, $meta, $count, "Bucket"); $this->isActivable = true; $this->maxStackSize = 1; } diff --git a/src/material/item/tool/FlintSteel.php b/src/material/item/tool/FlintSteel.php new file mode 100644 index 000000000..58b5c2e8b --- /dev/null +++ b/src/material/item/tool/FlintSteel.php @@ -0,0 +1,44 @@ +isActivable = true; + $this->maxStackSize = 1; + } + + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + if($block->getID() === AIR){ + $level->setBlock($block, new FireBlock(), true, false, true); + $block->level->scheduleBlockUpdate(new Position($block, 0, 0, $block->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); + return true; + } + $this->useOn($block); + return false; + } +} \ No newline at end of file diff --git a/src/material/item/generic/IronAxe.php b/src/material/item/tool/IronAxe.php similarity index 100% rename from src/material/item/generic/IronAxe.php rename to src/material/item/tool/IronAxe.php diff --git a/src/material/item/generic/IronHoe.php b/src/material/item/tool/IronHoe.php similarity index 100% rename from src/material/item/generic/IronHoe.php rename to src/material/item/tool/IronHoe.php diff --git a/src/material/item/generic/IronPickaxe.php b/src/material/item/tool/IronPickaxe.php similarity index 100% rename from src/material/item/generic/IronPickaxe.php rename to src/material/item/tool/IronPickaxe.php diff --git a/src/material/item/generic/IronShovel.php b/src/material/item/tool/IronShovel.php similarity index 100% rename from src/material/item/generic/IronShovel.php rename to src/material/item/tool/IronShovel.php diff --git a/src/material/item/generic/WoodenAxe.php b/src/material/item/tool/WoodenAxe.php similarity index 100% rename from src/material/item/generic/WoodenAxe.php rename to src/material/item/tool/WoodenAxe.php diff --git a/src/material/item/generic/WoodenPickaxe.php b/src/material/item/tool/WoodenPickaxe.php similarity index 100% rename from src/material/item/generic/WoodenPickaxe.php rename to src/material/item/tool/WoodenPickaxe.php diff --git a/src/material/item/generic/WoodenShovel.php b/src/material/item/tool/WoodenShovel.php similarity index 100% rename from src/material/item/generic/WoodenShovel.php rename to src/material/item/tool/WoodenShovel.php diff --git a/src/material/item/generic/WoodenSword.php b/src/material/item/tool/WoodenSword.php similarity index 100% rename from src/material/item/generic/WoodenSword.php rename to src/material/item/tool/WoodenSword.php