Implemented Blast Furnace and Smoker (#4362)

This commit is contained in:
Dylan T
2021-08-12 23:27:05 +01:00
committed by GitHub
parent 483c16cc41
commit 27e0ecf7ee
14 changed files with 235 additions and 39 deletions

View File

@ -32,6 +32,7 @@ use pocketmine\block\tile\Barrel as TileBarrel;
use pocketmine\block\tile\Beacon as TileBeacon;
use pocketmine\block\tile\Bed as TileBed;
use pocketmine\block\tile\Bell as TileBell;
use pocketmine\block\tile\BlastFurnace as TileBlastFurnace;
use pocketmine\block\tile\BrewingStand as TileBrewingStand;
use pocketmine\block\tile\Chest as TileChest;
use pocketmine\block\tile\Comparator as TileComparator;
@ -39,14 +40,15 @@ use pocketmine\block\tile\DaylightSensor as TileDaylightSensor;
use pocketmine\block\tile\EnchantTable as TileEnchantingTable;
use pocketmine\block\tile\EnderChest as TileEnderChest;
use pocketmine\block\tile\FlowerPot as TileFlowerPot;
use pocketmine\block\tile\Furnace as TileFurnace;
use pocketmine\block\tile\Hopper as TileHopper;
use pocketmine\block\tile\ItemFrame as TileItemFrame;
use pocketmine\block\tile\Jukebox as TileJukebox;
use pocketmine\block\tile\MonsterSpawner as TileMonsterSpawner;
use pocketmine\block\tile\NormalFurnace as TileNormalFurnace;
use pocketmine\block\tile\Note as TileNote;
use pocketmine\block\tile\ShulkerBox as TileShulkerBox;
use pocketmine\block\tile\Skull as TileSkull;
use pocketmine\block\tile\Smoker as TileSmoker;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\utils\InvalidBlockStateException;
use pocketmine\block\utils\SlabType;
@ -200,7 +202,9 @@ class BlockFactory{
$this->remap(Ids::FLOWER_POT_BLOCK, $meta, $flowerPot);
}
$this->register(new FrostedIce(new BID(Ids::FROSTED_ICE, 0), "Frosted Ice", new BlockBreakInfo(2.5, BlockToolType::PICKAXE)));
$this->register(new Furnace(new BIDFlattened(Ids::FURNACE, [Ids::LIT_FURNACE], 0, null, TileFurnace::class), "Furnace", new BlockBreakInfo(3.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel())));
$this->register(new Furnace(new BIDFlattened(Ids::FURNACE, [Ids::LIT_FURNACE], 0, null, TileNormalFurnace::class), "Furnace", new BlockBreakInfo(3.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel())));
$this->register(new Furnace(new BIDFlattened(Ids::BLAST_FURNACE, [Ids::LIT_BLAST_FURNACE], 0, null, TileBlastFurnace::class), "Blast Furnace", new BlockBreakInfo(3.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel())));
$this->register(new Furnace(new BIDFlattened(Ids::SMOKER, [Ids::LIT_SMOKER], 0, null, TileSmoker::class), "Smoker", new BlockBreakInfo(3.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel())));
$glassBreakInfo = new BlockBreakInfo(0.3);
$this->register(new Glass(new BID(Ids::GLASS, 0), "Glass", $glassBreakInfo));
@ -549,7 +553,6 @@ class BlockFactory{
));
//region --- auto-generated TODOs for bedrock-1.11.0 ---
//TODO: minecraft:blast_furnace
//TODO: minecraft:bubble_column
//TODO: minecraft:campfire
//TODO: minecraft:cartography_table
@ -570,8 +573,6 @@ class BlockFactory{
//TODO: minecraft:kelp
//TODO: minecraft:lava_cauldron
//TODO: minecraft:lectern
//TODO: minecraft:lit_blast_furnace
//TODO: minecraft:lit_smoker
//TODO: minecraft:movingBlock
//TODO: minecraft:observer
//TODO: minecraft:piston
@ -581,7 +582,6 @@ class BlockFactory{
//TODO: minecraft:seagrass
//TODO: minecraft:slime
//TODO: minecraft:smithing_table
//TODO: minecraft:smoker
//TODO: minecraft:sticky_piston
//TODO: minecraft:stonecutter_block
//TODO: minecraft:structure_block

View File

@ -82,6 +82,7 @@ use function assert;
* @method static WallSign BIRCH_WALL_SIGN()
* @method static Wood BIRCH_WOOD()
* @method static GlazedTerracotta BLACK_GLAZED_TERRACOTTA()
* @method static Furnace BLAST_FURNACE()
* @method static GlazedTerracotta BLUE_GLAZED_TERRACOTTA()
* @method static BlueIce BLUE_ICE()
* @method static Flower BLUE_ORCHID()
@ -487,6 +488,7 @@ use function assert;
* @method static SeaLantern SEA_LANTERN()
* @method static SeaPickle SEA_PICKLE()
* @method static ShulkerBox SHULKER_BOX()
* @method static Furnace SMOKER()
* @method static Opaque SMOOTH_QUARTZ()
* @method static Slab SMOOTH_QUARTZ_SLAB()
* @method static Stair SMOOTH_QUARTZ_STAIRS()
@ -645,6 +647,7 @@ final class VanillaBlocks{
self::register("birch_wall_sign", $factory->get(442, 2));
self::register("birch_wood", $factory->get(467, 2));
self::register("black_glazed_terracotta", $factory->get(235, 2));
self::register("blast_furnace", $factory->get(451, 2));
self::register("blue_glazed_terracotta", $factory->get(231, 2));
self::register("blue_ice", $factory->get(266, 0));
self::register("blue_orchid", $factory->get(38, 1));
@ -1050,6 +1053,7 @@ final class VanillaBlocks{
self::register("sea_lantern", $factory->get(169, 0));
self::register("sea_pickle", $factory->get(411, 0));
self::register("shulker_box", $factory->get(205, 0));
self::register("smoker", $factory->get(453, 2));
self::register("smooth_quartz", $factory->get(155, 3));
self::register("smooth_quartz_slab", $factory->get(421, 1));
self::register("smooth_quartz_stairs", $factory->get(440, 0));

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block\inventory;
use pocketmine\crafting\FurnaceType;
use pocketmine\inventory\SimpleInventory;
use pocketmine\item\Item;
use pocketmine\world\Position;
@ -30,11 +31,16 @@ use pocketmine\world\Position;
class FurnaceInventory extends SimpleInventory implements BlockInventory{
use BlockInventoryTrait;
public function __construct(Position $holder){
private FurnaceType $furnaceType;
public function __construct(Position $holder, FurnaceType $furnaceType){
$this->holder = $holder;
$this->furnaceType = $furnaceType;
parent::__construct(3);
}
public function getFurnaceType() : FurnaceType{ return $this->furnaceType; }
public function getResult() : Item{
return $this->getItem(2);
}

View File

@ -0,0 +1,32 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block\tile;
use pocketmine\crafting\FurnaceType;
class BlastFurnace extends Furnace{
public function getFurnaceType() : FurnaceType{
return FurnaceType::BLAST_FURNACE();
}
}

View File

@ -26,6 +26,7 @@ namespace pocketmine\block\tile;
use pocketmine\block\Furnace as BlockFurnace;
use pocketmine\block\inventory\FurnaceInventory;
use pocketmine\crafting\FurnaceRecipe;
use pocketmine\crafting\FurnaceType;
use pocketmine\event\inventory\FurnaceBurnEvent;
use pocketmine\event\inventory\FurnaceSmeltEvent;
use pocketmine\inventory\CallbackInventoryListener;
@ -39,7 +40,7 @@ use pocketmine\world\World;
use function array_map;
use function max;
class Furnace extends Spawnable implements Container, Nameable{
abstract class Furnace extends Spawnable implements Container, Nameable{
use NameableTrait;
use ContainerTrait;
@ -58,7 +59,7 @@ class Furnace extends Spawnable implements Container, Nameable{
public function __construct(World $world, Vector3 $pos){
parent::__construct($world, $pos);
$this->inventory = new FurnaceInventory($this->pos);
$this->inventory = new FurnaceInventory($this->pos, $this->getFurnaceType());
$this->inventory->getListeners()->add(CallbackInventoryListener::onAnyChange(
static function(Inventory $unused) use ($world, $pos) : void{
$world->scheduleDelayedBlockUpdate($pos, 1);
@ -148,6 +149,8 @@ class Furnace extends Spawnable implements Container, Nameable{
}
}
abstract public function getFurnaceType() : FurnaceType;
public function onUpdate() : bool{
//TODO: move this to Block
if($this->closed){
@ -165,7 +168,9 @@ class Furnace extends Spawnable implements Container, Nameable{
$fuel = $this->inventory->getFuel();
$raw = $this->inventory->getSmelting();
$product = $this->inventory->getResult();
$smelt = $this->pos->getWorld()->getServer()->getCraftingManager()->getFurnaceRecipeManager()->match($raw);
$furnaceType = $this->getFurnaceType();
$smelt = $this->pos->getWorld()->getServer()->getCraftingManager()->getFurnaceRecipeManager($furnaceType)->match($raw);
$canSmelt = ($smelt instanceof FurnaceRecipe and $raw->getCount() > 0 and (($smelt->getResult()->equals($product) and $product->getCount() < $product->getMaxStackSize()) or $product->isNull()));
if($this->remainingFuelTime <= 0 and $canSmelt and $fuel->getFuelTime() > 0 and $fuel->getCount() > 0){
@ -178,7 +183,7 @@ class Furnace extends Spawnable implements Container, Nameable{
if($smelt instanceof FurnaceRecipe and $canSmelt){
++$this->cookTime;
if($this->cookTime >= 200){ //10 seconds
if($this->cookTime >= $furnaceType->getCookDurationTicks()){
$product = $smelt->getResult()->setCount($product->getCount() + 1);
$ev = new FurnaceSmeltEvent($this, $raw, $product);
@ -190,7 +195,7 @@ class Furnace extends Spawnable implements Container, Nameable{
$this->inventory->setSmelting($raw);
}
$this->cookTime -= 200;
$this->cookTime -= $furnaceType->getCookDurationTicks();
}
}elseif($this->remainingFuelTime <= 0){
$this->remainingFuelTime = $this->cookTime = $this->maxFuelTime = 0;

View File

@ -0,0 +1,32 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block\tile;
use pocketmine\crafting\FurnaceType;
class NormalFurnace extends Furnace{
public function getFurnaceType() : FurnaceType{
return FurnaceType::FURNACE();
}
}

32
src/block/tile/Smoker.php Normal file
View File

@ -0,0 +1,32 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block\tile;
use pocketmine\crafting\FurnaceType;
class Smoker extends Furnace{
public function getFurnaceType() : FurnaceType{
return FurnaceType::SMOKER();
}
}

View File

@ -54,6 +54,7 @@ final class TileFactory{
$this->register(Beacon::class, ["Beacon", "minecraft:beacon"]);
$this->register(Bed::class, ["Bed", "minecraft:bed"]);
$this->register(Bell::class, ["Bell", "minecraft:bell"]);
$this->register(BlastFurnace::class, ["BlastFurnace", "minecraft:blast_furnace"]);
$this->register(BrewingStand::class, ["BrewingStand", "minecraft:brewing_stand"]);
$this->register(Chest::class, ["Chest", "minecraft:chest"]);
$this->register(Comparator::class, ["Comparator", "minecraft:comparator"]);
@ -61,7 +62,7 @@ final class TileFactory{
$this->register(EnchantTable::class, ["EnchantTable", "minecraft:enchanting_table"]);
$this->register(EnderChest::class, ["EnderChest", "minecraft:ender_chest"]);
$this->register(FlowerPot::class, ["FlowerPot", "minecraft:flower_pot"]);
$this->register(Furnace::class, ["Furnace", "minecraft:furnace"]);
$this->register(NormalFurnace::class, ["Furnace", "minecraft:furnace"]);
$this->register(Hopper::class, ["Hopper", "minecraft:hopper"]);
$this->register(ItemFrame::class, ["ItemFrame"]); //this is an entity in PC
$this->register(Jukebox::class, ["Jukebox", "RecordPlayer", "minecraft:jukebox"]);
@ -69,9 +70,9 @@ final class TileFactory{
$this->register(Note::class, ["Music", "minecraft:noteblock"]);
$this->register(ShulkerBox::class, ["ShulkerBox", "minecraft:shulker_box"]);
$this->register(Sign::class, ["Sign", "minecraft:sign"]);
$this->register(Smoker::class, ["Smoker", "minecraft:smoker"]);
$this->register(Skull::class, ["Skull", "minecraft:skull"]);
//TODO: BlastFurnace
//TODO: Campfire
//TODO: Cauldron
//TODO: ChalkboardBlock
@ -87,7 +88,6 @@ final class TileFactory{
//TODO: MovingBlock
//TODO: NetherReactor
//TODO: PistonArm
//TODO: Smoker
//TODO: StructureBlock
}