From 94f8cfb59bc8b5cd567449816fa70e3233b73277 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 6 Sep 2013 13:46:52 +0200 Subject: [PATCH] Added Single Explosions [ignite TNT using fling & steel] --- src/API/PlayerAPI.php | 3 + src/material/Block.php | 6 ++ src/material/block/StairBlock.php | 1 + src/material/block/attachable/Ladder.php | 1 + src/material/block/attachable/SignPost.php | 1 + src/material/block/attachable/Torch.php | 1 + src/material/block/attachable/Trapdoor.php | 1 + src/material/block/liquid/Lava.php | 1 + src/material/block/liquid/StillLava.php | 1 + src/material/block/liquid/StillWater.php | 1 + src/material/block/liquid/Water.php | 1 + src/material/block/misc/Air.php | 1 + src/material/block/misc/Bed.php | 1 + src/material/block/misc/Fire.php | 1 + src/material/block/misc/TNT.php | 14 +++++ src/material/block/nonfull/Cake.php | 1 + src/material/block/nonfull/Cobweb.php | 1 + src/material/block/nonfull/Fence.php | 1 + src/material/block/nonfull/FenceGate.php | 1 + src/material/block/nonfull/IronDoor.php | 1 + src/material/block/nonfull/Slab.php | 4 +- src/material/block/nonfull/SnowLayer.php | 1 + src/material/block/nonfull/WoodDoor.php | 1 + src/material/block/ore/CoalOre.php | 1 + src/material/block/ore/DiamondOre.php | 1 + src/material/block/ore/GlowingRedstoneOre.php | 1 + src/material/block/ore/GoldOre.php | 1 + src/material/block/ore/IronOre.php | 1 + src/material/block/ore/LapisOre.php | 1 + src/material/block/ore/RedstoneOre.php | 1 + src/material/block/plant/BrownMushroom.php | 1 + src/material/block/plant/Cactus.php | 1 + src/material/block/plant/CyanFlower.php | 1 + src/material/block/plant/Dandelion.php | 1 + src/material/block/plant/DeadBush.php | 1 + src/material/block/plant/MelonStem.php | 1 + src/material/block/plant/RedMushroom.php | 1 + src/material/block/plant/Sapling.php | 1 + src/material/block/plant/Sugarcane.php | 1 + src/material/block/plant/TallGrass.php | 1 + src/material/block/plant/Wheat.php | 1 + src/material/block/solid/Bedrock.php | 1 + src/material/block/solid/Bookshelf.php | 1 + src/material/block/solid/Bricks.php | 1 + src/material/block/solid/BurningFurnace.php | 1 + src/material/block/solid/Chest.php | 1 + src/material/block/solid/Clay.php | 1 + src/material/block/solid/Cobblestone.php | 1 + src/material/block/solid/Diamond.php | 1 + src/material/block/solid/Dirt.php | 1 + src/material/block/solid/DoubleSlab.php | 4 +- src/material/block/solid/Farmland.php | 1 + src/material/block/solid/Glass.php | 1 + src/material/block/solid/Glowstone.php | 1 + src/material/block/solid/Gold.php | 1 + src/material/block/solid/Grass.php | 1 + src/material/block/solid/Gravel.php | 1 + src/material/block/solid/Ice.php | 1 + src/material/block/solid/Iron.php | 1 + src/material/block/solid/Lapis.php | 1 + src/material/block/solid/Leaves.php | 1 + src/material/block/solid/Melon.php | 1 + src/material/block/solid/MossStone.php | 1 + src/material/block/solid/NetherBrick.php | 1 + src/material/block/solid/Netherrack.php | 1 + src/material/block/solid/Obsidian.php | 2 +- src/material/block/solid/Planks.php | 1 + src/material/block/solid/Sand.php | 1 + src/material/block/solid/Sandstone.php | 3 +- src/material/block/solid/Snow.php | 1 + src/material/block/solid/SoulSand.php | 1 + src/material/block/solid/Stone.php | 1 + src/material/block/solid/StoneBricks.php | 1 + src/material/block/solid/Wood.php | 1 + src/material/block/solid/Wool.php | 1 + src/material/block/solid/Workbench.php | 1 + src/world/Explosion.php | 61 +++++++++++-------- 77 files changed, 134 insertions(+), 32 deletions(-) diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 5e9d56355..e3d80dacd 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -101,6 +101,9 @@ class PlayerAPI{ case "fall": $message = " hit the ground too hard"; break; + case "explosion": + $message = " blew up"; + break; default: $message = " died"; break; diff --git a/src/material/Block.php b/src/material/Block.php index 5915d7f8e..7bff673a1 100644 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -131,6 +131,7 @@ abstract class Block extends Position{ protected $meta; protected $name; protected $breakTime; + protected $hardness; public $isActivable = false; public $breakable = true; public $isFlowable = false; @@ -151,6 +152,11 @@ abstract class Block extends Position{ $this->meta = (int) $meta; $this->name = $name; $this->breakTime = 0.20; + $this->hardness = 10; + } + + final public function getHardness(){ + return ($this->hardness); } final public function getName(){ diff --git a/src/material/block/StairBlock.php b/src/material/block/StairBlock.php index a72324225..87897e53a 100644 --- a/src/material/block/StairBlock.php +++ b/src/material/block/StairBlock.php @@ -27,6 +27,7 @@ class StairBlock extends TransparentBlock{ }else{ $this->isFullBlock = false; } + $this->hardness = 30; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/attachable/Ladder.php b/src/material/block/attachable/Ladder.php index c730737a1..3ccc0eedf 100644 --- a/src/material/block/attachable/Ladder.php +++ b/src/material/block/attachable/Ladder.php @@ -24,6 +24,7 @@ class LadderBlock extends TransparentBlock{ parent::__construct(LADDER, $meta, "Ladder"); $this->isSolid = false; $this->isFullBlock = false; + $this->hardness = 2; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($target->isTransparent === false){ diff --git a/src/material/block/attachable/SignPost.php b/src/material/block/attachable/SignPost.php index 06be976b9..743d35adc 100644 --- a/src/material/block/attachable/SignPost.php +++ b/src/material/block/attachable/SignPost.php @@ -24,6 +24,7 @@ class SignPostBlock extends TransparentBlock{ parent::__construct(SIGN_POST, $meta, "Sign Post"); $this->isSolid = false; $this->isFullBlock = false; + $this->hardness = 5; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/attachable/Torch.php b/src/material/block/attachable/Torch.php index c1696dd74..25c51e39b 100644 --- a/src/material/block/attachable/Torch.php +++ b/src/material/block/attachable/Torch.php @@ -22,6 +22,7 @@ class TorchBlock extends FlowableBlock{ public function __construct($meta = 0){ parent::__construct(TORCH, $meta, "Torch"); + $this->hardness = 0; } public function onUpdate($type){ diff --git a/src/material/block/attachable/Trapdoor.php b/src/material/block/attachable/Trapdoor.php index 906875d4c..53b666118 100644 --- a/src/material/block/attachable/Trapdoor.php +++ b/src/material/block/attachable/Trapdoor.php @@ -28,6 +28,7 @@ class TrapdoorBlock extends TransparentBlock{ }else{ $this->isFullBlock = true; } + $this->hardness = 15; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if(($target->isTransparent === false or $target->getID() === SLAB) and $face !== 0 and $face !== 1){ diff --git a/src/material/block/liquid/Lava.php b/src/material/block/liquid/Lava.php index fa5feb0dd..eb0b8758c 100644 --- a/src/material/block/liquid/Lava.php +++ b/src/material/block/liquid/Lava.php @@ -22,6 +22,7 @@ class LavaBlock extends LiquidBlock{ public function __construct($meta = 0){ parent::__construct(LAVA, $meta, "Lava"); + $this->hardness = 0; } } \ No newline at end of file diff --git a/src/material/block/liquid/StillLava.php b/src/material/block/liquid/StillLava.php index 1c7c5a6ba..e8c374285 100644 --- a/src/material/block/liquid/StillLava.php +++ b/src/material/block/liquid/StillLava.php @@ -22,6 +22,7 @@ class StillLavaBlock extends LiquidBlock{ public function __construct($meta = 0){ parent::__construct(STILL_LAVA, $meta, "Still Lava"); + $this->hardness = 500; } } \ No newline at end of file diff --git a/src/material/block/liquid/StillWater.php b/src/material/block/liquid/StillWater.php index 3ff43ac1c..b36cb3401 100644 --- a/src/material/block/liquid/StillWater.php +++ b/src/material/block/liquid/StillWater.php @@ -27,6 +27,7 @@ require_once("Water.php"); class StillWaterBlock extends WaterBlock{ public function __construct($meta = 0){ LiquidBlock::__construct(STILL_WATER, $meta, "Still Water"); + $this->hardness = 500; } } \ No newline at end of file diff --git a/src/material/block/liquid/Water.php b/src/material/block/liquid/Water.php index e46542805..2faacf2bb 100644 --- a/src/material/block/liquid/Water.php +++ b/src/material/block/liquid/Water.php @@ -22,6 +22,7 @@ class WaterBlock extends LiquidBlock{ public function __construct($meta = 0){ parent::__construct(WATER, $meta, "Water"); + $this->hardness = 500; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/misc/Air.php b/src/material/block/misc/Air.php index 274e76a9e..1a966ce8b 100644 --- a/src/material/block/misc/Air.php +++ b/src/material/block/misc/Air.php @@ -31,6 +31,7 @@ class AirBlock extends TransparentBlock{ $this->hasPhysics = false; $this->isSolid = false; $this->isFullBlock = true; + $this->hardness = 0; } diff --git a/src/material/block/misc/Bed.php b/src/material/block/misc/Bed.php index 25fcb82a9..e664cae84 100644 --- a/src/material/block/misc/Bed.php +++ b/src/material/block/misc/Bed.php @@ -24,6 +24,7 @@ class BedBlock extends TransparentBlock{ parent::__construct(BED_BLOCK, $type, "Bed Block"); $this->isActivable = true; $this->isFullBlock = false; + $this->hardness = 1; } public function onActivate(Item $item, Player $player){ diff --git a/src/material/block/misc/Fire.php b/src/material/block/misc/Fire.php index fb0969cbf..6706476c8 100644 --- a/src/material/block/misc/Fire.php +++ b/src/material/block/misc/Fire.php @@ -25,6 +25,7 @@ class FireBlock extends FlowableBlock{ $this->isReplaceable = true; $this->breakable = false; $this->isFullBlock = true; + $this->hardness = 0; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/misc/TNT.php b/src/material/block/misc/TNT.php index 1cd7c8d1c..a5d8982d8 100644 --- a/src/material/block/misc/TNT.php +++ b/src/material/block/misc/TNT.php @@ -22,5 +22,19 @@ class TNTBlock extends SolidBlock{ public function __construct(){ parent::__construct(TNT, 0, "TNT"); + $this->hardness = 0; + $this->isActivable = true; + } + + public function onActivate(Item $item, Player $player){ + if($item->getID() === FLINT_STEEL){ + if(($player->gamemode & 0x01) === 0){ + $item->useOn($this); + } + $explosion = new Explosion($this->level, $this, 4); + $explosion->explode(); + return true; + } + return false; } } \ No newline at end of file diff --git a/src/material/block/nonfull/Cake.php b/src/material/block/nonfull/Cake.php index 87d8cf40d..b13d48486 100644 --- a/src/material/block/nonfull/Cake.php +++ b/src/material/block/nonfull/Cake.php @@ -25,6 +25,7 @@ class CakeBlock extends TransparentBlock{ $this->isFullBlock = false; $this->isActivable = true; $this->meta = $meta & 0x07; + $this->hardness = 2.5; } public function onUpdate($type){ diff --git a/src/material/block/nonfull/Cobweb.php b/src/material/block/nonfull/Cobweb.php index 2ddaf850c..4b82d9f61 100644 --- a/src/material/block/nonfull/Cobweb.php +++ b/src/material/block/nonfull/Cobweb.php @@ -24,6 +24,7 @@ class CobwebBlock extends FlowableBlock{ parent::__construct(COBWEB, 0, "Cobweb"); $this->isSolid = true; $this->isFullBlock = false; + $this->hardness = 25; } public function getDrops(Item $item, Player $player){ return array(); diff --git a/src/material/block/nonfull/Fence.php b/src/material/block/nonfull/Fence.php index 73515d28c..f3e48e8a9 100644 --- a/src/material/block/nonfull/Fence.php +++ b/src/material/block/nonfull/Fence.php @@ -23,6 +23,7 @@ class FenceBlock extends TransparentBlock{ public function __construct(){ parent::__construct(FENCE, 0, "Fence"); $this->isFullBlock = false; + $this->hardness = 15; } } \ No newline at end of file diff --git a/src/material/block/nonfull/FenceGate.php b/src/material/block/nonfull/FenceGate.php index fefc59e32..6f54ee571 100644 --- a/src/material/block/nonfull/FenceGate.php +++ b/src/material/block/nonfull/FenceGate.php @@ -28,6 +28,7 @@ class FenceGateBlock extends TransparentBlock{ }else{ $this->isFullBlock = false; } + $this->hardness = 15; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $faces = array( diff --git a/src/material/block/nonfull/IronDoor.php b/src/material/block/nonfull/IronDoor.php index af8368457..d8d41ec82 100644 --- a/src/material/block/nonfull/IronDoor.php +++ b/src/material/block/nonfull/IronDoor.php @@ -23,6 +23,7 @@ class IronDoorBlock extends DoorBlock{ public function __construct($meta = 0){ parent::__construct(IRON_DOOR_BLOCK, $meta, "Iron Door Block"); //$this->isActivable = true; + $this->hardness = 25; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/nonfull/Slab.php b/src/material/block/nonfull/Slab.php index 80f27bd2d..feeeacca8 100644 --- a/src/material/block/nonfull/Slab.php +++ b/src/material/block/nonfull/Slab.php @@ -29,7 +29,6 @@ class SlabBlock extends TransparentBlock{ 3 => "Cobblestone", 4 => "Brick", 5 => "Stone Brick", - //6 => "Nether Brick", 6 => "Quartz", ); $this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Slab"; @@ -37,7 +36,8 @@ class SlabBlock extends TransparentBlock{ $this->isFullBlock = true; }else{ $this->isFullBlock = false; - } + } + $this->hardness = 30; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/nonfull/SnowLayer.php b/src/material/block/nonfull/SnowLayer.php index 7eccab533..b5c90d9d5 100644 --- a/src/material/block/nonfull/SnowLayer.php +++ b/src/material/block/nonfull/SnowLayer.php @@ -25,6 +25,7 @@ class SnowLayerBlock extends FlowableBlock{ $this->isReplaceable = true; $this->isSolid = false; $this->isFullBlock = false; + $this->hardness = 0.5; } public function onUpdate($type){ diff --git a/src/material/block/nonfull/WoodDoor.php b/src/material/block/nonfull/WoodDoor.php index b418f09ea..ee310b751 100644 --- a/src/material/block/nonfull/WoodDoor.php +++ b/src/material/block/nonfull/WoodDoor.php @@ -23,6 +23,7 @@ class WoodDoorBlock extends DoorBlock{ public function __construct($meta = 0){ parent::__construct(WOOD_DOOR_BLOCK, $meta, "Wood Door Block"); $this->isActivable = true; + $this->hardness = 15; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/ore/CoalOre.php b/src/material/block/ore/CoalOre.php index 34c1dde6d..cf66c5fe1 100644 --- a/src/material/block/ore/CoalOre.php +++ b/src/material/block/ore/CoalOre.php @@ -22,6 +22,7 @@ class CoalOreBlock extends SolidBlock{ public function __construct(){ parent::__construct(COAL_ORE, 0, "Coal Ore"); + $this->hardness = 15; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/ore/DiamondOre.php b/src/material/block/ore/DiamondOre.php index df9b79dbe..76e55db4c 100644 --- a/src/material/block/ore/DiamondOre.php +++ b/src/material/block/ore/DiamondOre.php @@ -22,6 +22,7 @@ class DiamondOreBlock extends SolidBlock{ public function __construct(){ parent::__construct(DIAMOND_ORE, 0, "Diamond Ore"); + $this->hardness = 15; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/ore/GlowingRedstoneOre.php b/src/material/block/ore/GlowingRedstoneOre.php index eced08216..5089e3f6f 100644 --- a/src/material/block/ore/GlowingRedstoneOre.php +++ b/src/material/block/ore/GlowingRedstoneOre.php @@ -22,6 +22,7 @@ class GlowingRedstoneOreBlock extends SolidBlock{ public function __construct(){ parent::__construct(GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore"); + $this->hardness = 15; } public function onUpdate($type){ diff --git a/src/material/block/ore/GoldOre.php b/src/material/block/ore/GoldOre.php index 72f8e10b6..7ca0e3a3f 100644 --- a/src/material/block/ore/GoldOre.php +++ b/src/material/block/ore/GoldOre.php @@ -22,6 +22,7 @@ class GoldOreBlock extends SolidBlock{ public function __construct(){ parent::__construct(GOLD_ORE, 0, "Gold Ore"); + $this->hardness = 15; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/ore/IronOre.php b/src/material/block/ore/IronOre.php index c5da77a60..c4200bc6b 100644 --- a/src/material/block/ore/IronOre.php +++ b/src/material/block/ore/IronOre.php @@ -22,6 +22,7 @@ class IronOreBlock extends SolidBlock{ public function __construct(){ parent::__construct(IRON_ORE, 0, "Iron Ore"); + $this->hardness = 15; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/ore/LapisOre.php b/src/material/block/ore/LapisOre.php index 6a985a5eb..e18247f2b 100644 --- a/src/material/block/ore/LapisOre.php +++ b/src/material/block/ore/LapisOre.php @@ -22,6 +22,7 @@ class LapisOreBlock extends SolidBlock{ public function __construct(){ parent::__construct(LAPIS_ORE, 0, "Lapis Ore"); + $this->hardness = 15; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/ore/RedstoneOre.php b/src/material/block/ore/RedstoneOre.php index 573972ecc..ddcf135d6 100644 --- a/src/material/block/ore/RedstoneOre.php +++ b/src/material/block/ore/RedstoneOre.php @@ -22,6 +22,7 @@ class RedstoneOreBlock extends SolidBlock{ public function __construct(){ parent::__construct(REDSTONE_ORE, 0, "Redstone Ore"); + $this->hardness = 15; } public function onUpdate($type){ diff --git a/src/material/block/plant/BrownMushroom.php b/src/material/block/plant/BrownMushroom.php index c8a627244..a4796966d 100644 --- a/src/material/block/plant/BrownMushroom.php +++ b/src/material/block/plant/BrownMushroom.php @@ -22,6 +22,7 @@ class BrownMushroomBlock extends FlowableBlock{ public function __construct(){ parent::__construct(BROWN_MUSHROOM, 0, "Brown Mushroom"); + $this->hardness = 0; } public function onUpdate($type){ diff --git a/src/material/block/plant/Cactus.php b/src/material/block/plant/Cactus.php index bb3128164..ad2202eed 100644 --- a/src/material/block/plant/Cactus.php +++ b/src/material/block/plant/Cactus.php @@ -23,6 +23,7 @@ class CactusBlock extends TransparentBlock{ public function __construct($meta = 0){ parent::__construct(CACTUS, $meta, "Cactus"); $this->isFullBlock = false; + $this->hardness = 2; } public function onUpdate($type){ diff --git a/src/material/block/plant/CyanFlower.php b/src/material/block/plant/CyanFlower.php index 4ddb08aed..0d35ebe83 100644 --- a/src/material/block/plant/CyanFlower.php +++ b/src/material/block/plant/CyanFlower.php @@ -22,6 +22,7 @@ class CyanFlowerBlock extends FlowableBlock{ public function __construct(){ parent::__construct(CYAN_FLOWER, 0, "Cyan Flower"); + $this->hardness = 0; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/plant/Dandelion.php b/src/material/block/plant/Dandelion.php index 7c9e5aa85..75761b870 100644 --- a/src/material/block/plant/Dandelion.php +++ b/src/material/block/plant/Dandelion.php @@ -22,6 +22,7 @@ class DandelionBlock extends FlowableBlock{ public function __construct(){ parent::__construct(DANDELION, 0, "Dandelion"); + $this->hardness = 0; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/plant/DeadBush.php b/src/material/block/plant/DeadBush.php index 2537ab720..643ad211a 100644 --- a/src/material/block/plant/DeadBush.php +++ b/src/material/block/plant/DeadBush.php @@ -23,6 +23,7 @@ class DeadBushBlock extends FlowableBlock{ public function __construct(){ parent::__construct(DEAD_BUSH, 0, "Dead Bush"); $this->isReplaceable = true; + $this->hardness = 0; } public function onUpdate($type){ diff --git a/src/material/block/plant/MelonStem.php b/src/material/block/plant/MelonStem.php index c240889aa..38bba91f2 100644 --- a/src/material/block/plant/MelonStem.php +++ b/src/material/block/plant/MelonStem.php @@ -23,6 +23,7 @@ class MelonStemBlock extends FlowableBlock{ public function __construct($meta = 0){ parent::__construct(MELON_STEM, $meta, "Melon Stem"); $this->isActivable = true; + $this->hardness = 0; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); diff --git a/src/material/block/plant/RedMushroom.php b/src/material/block/plant/RedMushroom.php index e96123228..288c4f935 100644 --- a/src/material/block/plant/RedMushroom.php +++ b/src/material/block/plant/RedMushroom.php @@ -22,6 +22,7 @@ class RedMushroomBlock extends FlowableBlock{ public function __construct(){ parent::__construct(RED_MUSHROOM, 0, "Red Mushroom"); + $this->hardness = 0; } public function onUpdate($type){ diff --git a/src/material/block/plant/Sapling.php b/src/material/block/plant/Sapling.php index 0b5674f8a..61a96c061 100644 --- a/src/material/block/plant/Sapling.php +++ b/src/material/block/plant/Sapling.php @@ -34,6 +34,7 @@ class SaplingBlock extends FlowableBlock{ 2 => "Birch Sapling", ); $this->name = $names[$this->meta & 0x03]; + $this->hardness = 0; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/plant/Sugarcane.php b/src/material/block/plant/Sugarcane.php index 233370413..3a8a1f126 100644 --- a/src/material/block/plant/Sugarcane.php +++ b/src/material/block/plant/Sugarcane.php @@ -22,6 +22,7 @@ class SugarcaneBlock extends FlowableBlock{ public function __construct($meta = 0){ parent::__construct(SUGARCANE_BLOCK, $meta, "Sugarcane"); + $this->hardness = 0; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/plant/TallGrass.php b/src/material/block/plant/TallGrass.php index bd7c1ae91..d79a45985 100644 --- a/src/material/block/plant/TallGrass.php +++ b/src/material/block/plant/TallGrass.php @@ -29,6 +29,7 @@ class TallGrassBlock extends FlowableBlock{ 2 => "Fern", ); $this->name = $names[$this->meta & 0x03]; + $this->hardness = 0; } public function onUpdate($type){ diff --git a/src/material/block/plant/Wheat.php b/src/material/block/plant/Wheat.php index 70a704642..1b28ebc23 100644 --- a/src/material/block/plant/Wheat.php +++ b/src/material/block/plant/Wheat.php @@ -23,6 +23,7 @@ class WheatBlock extends FlowableBlock{ public function __construct($meta = 0){ parent::__construct(WHEAT_BLOCK, $meta, "Wheat Block"); $this->isActivable = true; + $this->hardness = 0; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/solid/Bedrock.php b/src/material/block/solid/Bedrock.php index 4adbd20e5..399f85605 100644 --- a/src/material/block/solid/Bedrock.php +++ b/src/material/block/solid/Bedrock.php @@ -23,6 +23,7 @@ class BedrockBlock extends SolidBlock{ public function __construct(){ parent::__construct(BEDROCK, 0, "Bedrock"); $this->breakable = false; + $this->hardness = 18000000; } public function isBreakable(Item $item, Player $player){ diff --git a/src/material/block/solid/Bookshelf.php b/src/material/block/solid/Bookshelf.php index 907dee7be..27c19411d 100644 --- a/src/material/block/solid/Bookshelf.php +++ b/src/material/block/solid/Bookshelf.php @@ -22,6 +22,7 @@ class BookshelfBlock extends SolidBlock{ public function __construct(){ parent::__construct(BOOKSHELF, 0, "Bookshelf"); + $this->hardness = 7.5; } } \ No newline at end of file diff --git a/src/material/block/solid/Bricks.php b/src/material/block/solid/Bricks.php index 800526db8..808d7c6b3 100644 --- a/src/material/block/solid/Bricks.php +++ b/src/material/block/solid/Bricks.php @@ -22,6 +22,7 @@ class BricksBlock extends SolidBlock{ public function __construct(){ parent::__construct(BRICKS_BLOCK, 0, "Bricks"); + $this->hardness = 30; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/BurningFurnace.php b/src/material/block/solid/BurningFurnace.php index 50a40c480..d47fca178 100644 --- a/src/material/block/solid/BurningFurnace.php +++ b/src/material/block/solid/BurningFurnace.php @@ -23,6 +23,7 @@ class BurningFurnaceBlock extends SolidBlock{ public function __construct($meta = 0){ parent::__construct(BURNING_FURNACE, $meta, "Burning Furnace"); $this->isActivable = true; + $this->hardness = 17.5; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/solid/Chest.php b/src/material/block/solid/Chest.php index 32f015ba2..419ec08ac 100644 --- a/src/material/block/solid/Chest.php +++ b/src/material/block/solid/Chest.php @@ -23,6 +23,7 @@ class ChestBlock extends TransparentBlock{ public function __construct($meta = 0){ parent::__construct(CHEST, $meta, "Chest"); $this->isActivable = true; + $this->hardness = 15; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $server = ServerAPI::request(); diff --git a/src/material/block/solid/Clay.php b/src/material/block/solid/Clay.php index 425f649fd..2cb77dee0 100644 --- a/src/material/block/solid/Clay.php +++ b/src/material/block/solid/Clay.php @@ -22,6 +22,7 @@ class ClayBlock extends SolidBlock{ public function __construct(){ parent::__construct(CLAY_BLOCK, 0, "Clay Block"); + $this->hardness = 3; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/Cobblestone.php b/src/material/block/solid/Cobblestone.php index 33d3dfd44..961d1c5f7 100644 --- a/src/material/block/solid/Cobblestone.php +++ b/src/material/block/solid/Cobblestone.php @@ -22,6 +22,7 @@ class CobblestoneBlock extends SolidBlock{ public function __construct(){ parent::__construct(COBBLESTONE, 0, "Cobblestone"); + $this->hardness = 30; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/Diamond.php b/src/material/block/solid/Diamond.php index f103daa56..0d7cd40c9 100644 --- a/src/material/block/solid/Diamond.php +++ b/src/material/block/solid/Diamond.php @@ -22,6 +22,7 @@ class DiamondBlock extends SolidBlock{ public function __construct(){ parent::__construct(DIAMOND_BLOCK, 0, "Diamond Block"); + $this->hardness = 30; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/Dirt.php b/src/material/block/solid/Dirt.php index 22f54df56..ca41c9f10 100644 --- a/src/material/block/solid/Dirt.php +++ b/src/material/block/solid/Dirt.php @@ -23,6 +23,7 @@ class DirtBlock extends SolidBlock{ public function __construct(){ parent::__construct(DIRT, 0, "Dirt"); $this->isActivable = true; + $this->hardness = 2.5; } public function onActivate(Item $item, Player $player){ diff --git a/src/material/block/solid/DoubleSlab.php b/src/material/block/solid/DoubleSlab.php index baa177333..6e1fd7caf 100644 --- a/src/material/block/solid/DoubleSlab.php +++ b/src/material/block/solid/DoubleSlab.php @@ -29,10 +29,10 @@ class DoubleSlabBlock extends SolidBlock{ 3 => "Cobblestone", 4 => "Brick", 5 => "Stone Brick", - 6 => "Nether Brick", - 7 => "Quartz", + 6 => "Quartz", ); $this->name = "Double " . $names[$this->meta & 0x07] . " Slab"; + $this->hardness = 30; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/Farmland.php b/src/material/block/solid/Farmland.php index 4a1898747..8a01dd188 100644 --- a/src/material/block/solid/Farmland.php +++ b/src/material/block/solid/Farmland.php @@ -22,6 +22,7 @@ class FarmlandBlock extends SolidBlock{ public function __construct($meta = 0){ parent::__construct(FARMLAND, $meta, "Farmland"); + $this->hardness = 3; } public function getDrops(Item $item, Player $player){ return array( diff --git a/src/material/block/solid/Glass.php b/src/material/block/solid/Glass.php index 0b87e8b48..b95d2c00b 100644 --- a/src/material/block/solid/Glass.php +++ b/src/material/block/solid/Glass.php @@ -22,6 +22,7 @@ class GlassBlock extends TransparentBlock{ public function __construct(){ parent::__construct(GLASS, 0, "Glass"); + $this->hardness = 1.5; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/Glowstone.php b/src/material/block/solid/Glowstone.php index 483c03ced..3f1cd1218 100644 --- a/src/material/block/solid/Glowstone.php +++ b/src/material/block/solid/Glowstone.php @@ -22,6 +22,7 @@ class GlowstoneBlock extends TransparentBlock{ public function __construct(){ parent::__construct(GLOWSTONE_BLOCK, 0, "Glowstone"); + $this->hardness = 1.5; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/Gold.php b/src/material/block/solid/Gold.php index a41817526..7e20e403b 100644 --- a/src/material/block/solid/Gold.php +++ b/src/material/block/solid/Gold.php @@ -22,6 +22,7 @@ class GoldBlock extends SolidBlock{ public function __construct(){ parent::__construct(GOLD_BLOCK, 0, "Gold Block"); + $this->hardness = 30; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/Grass.php b/src/material/block/solid/Grass.php index d6e11ad1c..c8e17993a 100644 --- a/src/material/block/solid/Grass.php +++ b/src/material/block/solid/Grass.php @@ -23,6 +23,7 @@ class GrassBlock extends SolidBlock{ public function __construct(){ parent::__construct(GRASS, 0, "Grass"); $this->isActivable = true; + $this->hardness = 3; } public function getDrops(Item $item, Player $player){ return array( diff --git a/src/material/block/solid/Gravel.php b/src/material/block/solid/Gravel.php index b272b73b0..72032c44d 100644 --- a/src/material/block/solid/Gravel.php +++ b/src/material/block/solid/Gravel.php @@ -22,6 +22,7 @@ class GravelBlock extends FallableBlock{ public function __construct(){ parent::__construct(GRAVEL, 0, "Gravel"); + $this->hardness = 3; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/Ice.php b/src/material/block/solid/Ice.php index b7dd654e7..a86d9ffbb 100644 --- a/src/material/block/solid/Ice.php +++ b/src/material/block/solid/Ice.php @@ -22,6 +22,7 @@ class IceBlock extends TransparentBlock{ public function __construct(){ parent::__construct(ICE, 0, "Ice"); + $this->hardness = 2.5; } public function onBreak(Item $item, Player $player){ diff --git a/src/material/block/solid/Iron.php b/src/material/block/solid/Iron.php index cdbb70f87..83fc7ca89 100644 --- a/src/material/block/solid/Iron.php +++ b/src/material/block/solid/Iron.php @@ -22,6 +22,7 @@ class IronBlock extends SolidBlock{ public function __construct(){ parent::__construct(IRON_BLOCK, 0, "Iron Block"); + $this->hardness = 30; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/Lapis.php b/src/material/block/solid/Lapis.php index 3214de335..fe971337c 100644 --- a/src/material/block/solid/Lapis.php +++ b/src/material/block/solid/Lapis.php @@ -22,6 +22,7 @@ class LapisBlock extends SolidBlock{ public function __construct(){ parent::__construct(LAPIS_BLOCK, 0, "Lapis Block"); + $this->hardness = 15; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/Leaves.php b/src/material/block/solid/Leaves.php index 9fd470ba4..c0cc6fbd1 100644 --- a/src/material/block/solid/Leaves.php +++ b/src/material/block/solid/Leaves.php @@ -32,6 +32,7 @@ class LeavesBlock extends TransparentBlock{ 3 => "", ); $this->name = $names[$this->meta & 0x03]; + $this->hardness = 1; } private function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null){ diff --git a/src/material/block/solid/Melon.php b/src/material/block/solid/Melon.php index 484982808..4cd938581 100644 --- a/src/material/block/solid/Melon.php +++ b/src/material/block/solid/Melon.php @@ -22,6 +22,7 @@ class MelonBlock extends TransparentBlock{ public function __construct(){ parent::__construct(MELON_BLOCK, 0, "Melon Block"); + $this->hardness = 5; } public function getDrops(Item $item, Player $player){ return array( diff --git a/src/material/block/solid/MossStone.php b/src/material/block/solid/MossStone.php index 90d55c3d8..1c65d9309 100644 --- a/src/material/block/solid/MossStone.php +++ b/src/material/block/solid/MossStone.php @@ -22,6 +22,7 @@ class MossStoneBlock extends SolidBlock{ public function __construct(){ parent::__construct(MOSS_STONE, 0, "Moss Stone"); + $this->hardness = 30; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/NetherBrick.php b/src/material/block/solid/NetherBrick.php index 2d80ee0b4..720194330 100644 --- a/src/material/block/solid/NetherBrick.php +++ b/src/material/block/solid/NetherBrick.php @@ -22,6 +22,7 @@ class NetherBricksBlock extends SolidBlock{ public function __construct(){ parent::__construct(NETHER_BRICKS, 0, "Nether Bricks"); + $this->hardness = 30; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/Netherrack.php b/src/material/block/solid/Netherrack.php index 9b4d636ca..f6af2ab8b 100644 --- a/src/material/block/solid/Netherrack.php +++ b/src/material/block/solid/Netherrack.php @@ -22,6 +22,7 @@ class NetherrackBlock extends SolidBlock{ public function __construct(){ parent::__construct(NETHERRACK, 0, "Netherrack"); + $this->hardness = 2; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/Obsidian.php b/src/material/block/solid/Obsidian.php index a8243f785..04b05c197 100644 --- a/src/material/block/solid/Obsidian.php +++ b/src/material/block/solid/Obsidian.php @@ -22,7 +22,7 @@ class ObsidianBlock extends SolidBlock{ public function __construct(){ parent::__construct(OBSIDIAN, 0, "Obsidian"); - + $this->hardness = 6000; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/Planks.php b/src/material/block/solid/Planks.php index 138c2c351..4d00e8324 100644 --- a/src/material/block/solid/Planks.php +++ b/src/material/block/solid/Planks.php @@ -22,6 +22,7 @@ class PlanksBlock extends SolidBlock{ public function __construct($meta = 0){ parent::__construct(PLANKS, $meta, "Wooden Planks"); + $this->hardness = 15; } } \ No newline at end of file diff --git a/src/material/block/solid/Sand.php b/src/material/block/solid/Sand.php index 089c6bf27..0b6c0d7fe 100644 --- a/src/material/block/solid/Sand.php +++ b/src/material/block/solid/Sand.php @@ -22,6 +22,7 @@ class SandBlock extends FallableBlock{ public function __construct(){ parent::__construct(SAND, 0, "Sand"); + $this->hardness = 2.5; } } \ No newline at end of file diff --git a/src/material/block/solid/Sandstone.php b/src/material/block/solid/Sandstone.php index d91150fd5..30e19e804 100644 --- a/src/material/block/solid/Sandstone.php +++ b/src/material/block/solid/Sandstone.php @@ -27,7 +27,8 @@ class SandstoneBlock extends SolidBlock{ 1 => "Chiseled Sandstone", 2 => "Smooth Sandstone", ); - $this->name = $names[$this->meta & 0x03]; + $this->name = $names[$this->meta & 0x03]; + $this->hardness = 4; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/Snow.php b/src/material/block/solid/Snow.php index bc805683b..d5fbf6dd1 100644 --- a/src/material/block/solid/Snow.php +++ b/src/material/block/solid/Snow.php @@ -22,6 +22,7 @@ class SnowBlock extends SolidBlock{ public function __construct(){ parent::__construct(SNOW_BLOCK, 0, "Snow Block"); + $this->hardness = 1; } } \ No newline at end of file diff --git a/src/material/block/solid/SoulSand.php b/src/material/block/solid/SoulSand.php index c593b6e43..01d7cc659 100644 --- a/src/material/block/solid/SoulSand.php +++ b/src/material/block/solid/SoulSand.php @@ -22,6 +22,7 @@ class SoulSandBlock extends SolidBlock{ public function __construct(){ parent::__construct(SOUL_SAND, 0, "Soul Sand"); + $this->hardness = 2.5; } } \ No newline at end of file diff --git a/src/material/block/solid/Stone.php b/src/material/block/solid/Stone.php index e53208c16..836c9c616 100644 --- a/src/material/block/solid/Stone.php +++ b/src/material/block/solid/Stone.php @@ -22,6 +22,7 @@ class StoneBlock extends SolidBlock{ public function __construct(){ parent::__construct(STONE, 0, "Stone"); + $this->hardness = 30; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/StoneBricks.php b/src/material/block/solid/StoneBricks.php index 238a6b6cc..b169161fd 100644 --- a/src/material/block/solid/StoneBricks.php +++ b/src/material/block/solid/StoneBricks.php @@ -29,6 +29,7 @@ class StoneBricksBlock extends SolidBlock{ 3 => "Chiseled Stone Bricks", ); $this->name = $names[$this->meta & 0x03]; + $this->hardness = 30; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/Wood.php b/src/material/block/solid/Wood.php index ffa6651e6..1edd77254 100644 --- a/src/material/block/solid/Wood.php +++ b/src/material/block/solid/Wood.php @@ -33,6 +33,7 @@ class WoodBlock extends SolidBlock{ ); $this->meta &= 0x03; $this->name = $names[$this->meta]; + $this->hardness = 10; } } \ No newline at end of file diff --git a/src/material/block/solid/Wool.php b/src/material/block/solid/Wool.php index 5f4edfde7..e5c4f0586 100644 --- a/src/material/block/solid/Wool.php +++ b/src/material/block/solid/Wool.php @@ -41,6 +41,7 @@ class WoolBlock extends SolidBlock{ 15 => "Black Wool", ); $this->name = $names[$this->meta]; + $this->hardness = 4; } } \ No newline at end of file diff --git a/src/material/block/solid/Workbench.php b/src/material/block/solid/Workbench.php index 6d82a97de..30c3944e9 100644 --- a/src/material/block/solid/Workbench.php +++ b/src/material/block/solid/Workbench.php @@ -23,6 +23,7 @@ class WorkbenchBlock extends SolidBlock{ public function __construct($meta = 0){ parent::__construct(WORKBENCH, $meta, "Crafting Table"); $this->isActivable = true; + $this->hardness = 15; } public function onActivate(Item $item, Player $player){ diff --git a/src/world/Explosion.php b/src/world/Explosion.php index 6bcb406c0..14929b3ec 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -20,27 +20,29 @@ */ class Explosion{ - private $i = 16; //Rays + private $i = 8; //Rays public $level; public $source; public $size; public $affectedBlocks = array(); - public function __construct($level, Vector3 $center, $size){ + public function __construct(Level $level, Vector3 $center, $size){ $this->level = $level; $this->source = $center; $this->size = max($size, 0); } public function explode(){ - if($this->size < 0.1 or ServerAPI::request()->api->dhandle("entity.explosion", array( - "level" => $level, + $server = ServerAPI::request(); + if($this->size < 0.1 or $server->api->dhandle("entity.explosion", array( + "level" => $this->level, "source" => $this->source, "size" => $this->size ))){ return false; } - + $airblock = new AirBlock(); + $drops = array(); for($i = 0; $i < $this->i; ++$i){ for($j = 0; $j < $this->i; ++$j){ for($k = 0; $k < $this->i; ++$k){ @@ -53,24 +55,25 @@ class Explosion{ $d4 /= $d6; $d5 /= $d6; - $f1 = $this->size * (0.7 + lcg_value() * 0.6); + $f1 = $this->size * (0.7 + (mt_rand(0, 1000000) / 1000000) * 0.6); $d0 = $this->source->x; $d1 = $this->source->y; $d2 = $this->source->z; for($f2 = 0.3; $f1 > 0; $f1 -= $f2 * 0.75){ - $l = floor($d0); - $i1 = floor($d1); - $j1 = floor($d2); - $k1 = $this->level->getBlock(new Vector3($l, $i1, $j1))->getID(); - if($k1 > AIR){ - $f3 = 0.5; //Placeholder - $f1 -= ($f3 + 0.4) * $f2; - } + $l = (int) $d0; + $i1 = (int) $d1; + $j1 = (int) $d2; + $k1 = $this->level->getBlock(new Vector3($l, $i1, $j1)); - if($f1 > 0 and $i1 < 128 and $i1 >= 0){ - $this->level->setBlock(new Vector3($l, $i1, $j1), AIR, 0, false); - $this->affectedBlocks[$l.$i1.$j1] = new Vector3($l, $i1, $j1); + $f1 -= ($k1->getHardness() / 5 + 0.3) * $f2; + + if(!($k1 instanceof AirBlock) and $f1 > 0 and $i1 < 128 and $i1 >= 0){ + $this->level->setBlockRaw(new Vector3($l, $i1, $j1), $airblock, false, false); //Do not send record + $this->affectedBlocks[$l.$i1.$j1] = new Vector3($l - $this->source->x, $i1 - $this->source->y, $j1 - $this->source->z); + if(mt_rand(0, 100) < 30){ + $drops[] = array(new Position($l, $i1, $j1, $this->level), BlockAPI::getItem($k1->getID(), $k1->getMetadata())); + } } $d0 += $d3 * $f2; @@ -81,15 +84,21 @@ class Explosion{ } } } - - foreach(ServerAPI::request()->api->player->getAll() as $player){ - $player->dataPacket(MC_EXPLOSION, array( - "x" => $this->source->x, - "y" => $this->source->y, - "z" => $this->source->z, - "radius" => $this->size, - "records" => array(), //Blocks are already sent - )); + + $server->api->player->broadcastPacket($server->api->player->getAll($this->level), MC_EXPLOSION, array( + "x" => $this->source->x, + "y" => $this->source->y, + "z" => $this->source->z, + "radius" => $this->size, + "records" => $this->affectedBlocks, + )); + foreach($server->api->entity->getRadius($this->source, 10) as $entity){ + $impact = (1 - $this->source->distance($entity) / 10); + $damage = (int) (($impact * $impact + $impact) * 4 * $this->size + 1); + $entity->harm($damage, "explosion"); + } + foreach($drops as $drop){ + $server->api->entity->drop($drop[0], $drop[1]); } } } \ No newline at end of file