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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
}

View File

@ -37,8 +37,11 @@ class CraftingManager{
/** @var ShapelessRecipe[][] */
protected $shapelessRecipes = [];
/** @var FurnaceRecipeManager */
protected $furnaceRecipeManager;
/**
* @var FurnaceRecipeManager[]
* @phpstan-var array<int, FurnaceRecipeManager>
*/
protected $furnaceRecipeManagers;
/**
* @var ObjectSet
@ -48,14 +51,18 @@ class CraftingManager{
public function __construct(){
$this->recipeRegisteredCallbacks = new ObjectSet();
$this->furnaceRecipeManager = new FurnaceRecipeManager();
foreach(FurnaceType::getAll() as $furnaceType){
$this->furnaceRecipeManagers[$furnaceType->id()] = new FurnaceRecipeManager();
}
$recipeRegisteredCallbacks = $this->recipeRegisteredCallbacks;
$this->furnaceRecipeManager->getRecipeRegisteredCallbacks()->add(static function(FurnaceRecipe $recipe) use ($recipeRegisteredCallbacks) : void{
foreach($recipeRegisteredCallbacks as $callback){
$callback();
}
});
foreach($this->furnaceRecipeManagers as $furnaceRecipeManager){
$furnaceRecipeManager->getRecipeRegisteredCallbacks()->add(static function(FurnaceRecipe $recipe) use ($recipeRegisteredCallbacks) : void{
foreach($recipeRegisteredCallbacks as $callback){
$callback();
}
});
}
}
/** @phpstan-return ObjectSet<\Closure() : void> */
@ -123,8 +130,8 @@ class CraftingManager{
return $this->shapedRecipes;
}
public function getFurnaceRecipeManager() : FurnaceRecipeManager{
return $this->furnaceRecipeManager;
public function getFurnaceRecipeManager(FurnaceType $furnaceType) : FurnaceRecipeManager{
return $this->furnaceRecipeManagers[$furnaceType->id()];
}
public function registerShapedRecipe(ShapedRecipe $recipe) : void{

View File

@ -61,10 +61,17 @@ final class CraftingManagerFromDataHelper{
));
}
foreach($recipes["smelting"] as $recipe){
if($recipe["block"] !== "furnace"){ //TODO: filter others out for now to avoid breaking economics
$furnaceType = match ($recipe["block"]){
"furnace" => FurnaceType::FURNACE(),
"blast_furnace" => FurnaceType::BLAST_FURNACE(),
"smoker" => FurnaceType::SMOKER(),
//TODO: campfire
default => null
};
if($furnaceType === null){
continue;
}
$result->getFurnaceRecipeManager()->register(new FurnaceRecipe(
$result->getFurnaceRecipeManager($furnaceType)->register(new FurnaceRecipe(
Item::jsonDeserialize($recipe["output"]),
Item::jsonDeserialize($recipe["input"]))
);

View File

@ -0,0 +1,55 @@
<?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\crafting;
use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever registry members are added, removed or changed.
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static FurnaceType BLAST_FURNACE()
* @method static FurnaceType FURNACE()
* @method static FurnaceType SMOKER()
*/
final class FurnaceType{
use EnumTrait {
__construct as Enum___construct;
}
protected static function setup() : void{
self::registerAll(
new self("furnace", 200),
new self("blast_furnace", 100),
new self("smoker", 100),
);
}
private function __construct(string $enumName, private int $cookDurationTicks){
$this->Enum___construct($enumName);
}
public function getCookDurationTicks() : int{ return $this->cookDurationTicks; }
}

View File

@ -30,6 +30,7 @@ use pocketmine\block\inventory\EnchantInventory;
use pocketmine\block\inventory\FurnaceInventory;
use pocketmine\block\inventory\HopperInventory;
use pocketmine\block\inventory\LoomInventory;
use pocketmine\crafting\FurnaceType;
use pocketmine\inventory\CreativeInventory;
use pocketmine\inventory\Inventory;
use pocketmine\inventory\transaction\action\SlotChangeAction;
@ -49,6 +50,7 @@ use pocketmine\network\mcpe\protocol\types\inventory\CreativeContentEntry;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use pocketmine\network\mcpe\protocol\types\inventory\WindowTypes;
use pocketmine\player\Player;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\ObjectSet;
use function array_map;
use function array_search;
@ -166,8 +168,12 @@ class InventoryManager{
case $inv instanceof LoomInventory:
return [ContainerOpenPacket::blockInvVec3($id, WindowTypes::LOOM, $inv->getHolder())];
case $inv instanceof FurnaceInventory:
//TODO: specialized furnace types
return [ContainerOpenPacket::blockInvVec3($id, WindowTypes::FURNACE, $inv->getHolder())];
return match($inv->getFurnaceType()->id()){
FurnaceType::FURNACE()->id() => [ContainerOpenPacket::blockInvVec3($id, WindowTypes::FURNACE, $inv->getHolder())],
FurnaceType::BLAST_FURNACE()->id() => [ContainerOpenPacket::blockInvVec3($id, WindowTypes::BLAST_FURNACE, $inv->getHolder())],
FurnaceType::SMOKER()->id() => [ContainerOpenPacket::blockInvVec3($id, WindowTypes::SMOKER, $inv->getHolder())],
default => throw new AssumptionFailedError("Unreachable")
};
case $inv instanceof EnchantInventory:
return [ContainerOpenPacket::blockInvVec3($id, WindowTypes::ENCHANTMENT, $inv->getHolder())];
case $inv instanceof BrewingStandInventory:

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe\cache;
use pocketmine\crafting\CraftingManager;
use pocketmine\crafting\FurnaceType;
use pocketmine\item\Item;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\CraftingDataPacket;
@ -33,6 +34,7 @@ use pocketmine\network\mcpe\protocol\types\recipe\RecipeIngredient;
use pocketmine\network\mcpe\protocol\types\recipe\ShapedRecipe as ProtocolShapedRecipe;
use pocketmine\network\mcpe\protocol\types\recipe\ShapelessRecipe as ProtocolShapelessRecipe;
use pocketmine\timings\Timings;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Binary;
use pocketmine\utils\SingletonTrait;
use Ramsey\Uuid\Uuid;
@ -115,15 +117,23 @@ final class CraftingDataCache{
}
}
foreach($manager->getFurnaceRecipeManager()->getAll() as $recipe){
$input = $converter->coreItemStackToNet($recipe->getInput());
$pk->entries[] = new ProtocolFurnaceRecipe(
CraftingDataPacket::ENTRY_FURNACE_DATA,
$input->getId(),
$input->getMeta(),
$converter->coreItemStackToNet($recipe->getResult()),
"furnace"
);
foreach(FurnaceType::getAll() as $furnaceType){
$typeTag = match($furnaceType->id()){
FurnaceType::FURNACE()->id() => "furnace",
FurnaceType::BLAST_FURNACE()->id() => "blast_furnace",
FurnaceType::SMOKER()->id() => "smoker",
default => throw new AssumptionFailedError("Unreachable"),
};
foreach($manager->getFurnaceRecipeManager($furnaceType)->getAll() as $recipe){
$input = $converter->coreItemStackToNet($recipe->getInput());
$pk->entries[] = new ProtocolFurnaceRecipe(
CraftingDataPacket::ENTRY_FURNACE_DATA,
$input->getId(),
$input->getMeta(),
$converter->coreItemStackToNet($recipe->getResult()),
$typeTag
);
}
}
Timings::$craftingDataCacheRebuild->stopTiming();

File diff suppressed because one or more lines are too long