Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented smithing table functionality #6202

Open
wants to merge 13 commits into
base: minor-next
Choose a base branch
from

Conversation

HimmelKreis4865
Copy link
Contributor

Introduction

This PR adds working smithing tables to pocketmine.
There are no known issues or problems

Changes

API changes

Amor->setTrim(ArmorTrim)
Armor->getTrim() : ?ArmorTrim
Armor->clearTrim()

SmithingTableInventory->getInput() : Item
SmithingTableInventory->getAddition() : Item
SmithingTableInventory->getTemplate() : Item

The new enums: ArmorTrimPattern & ArmorTrimMaterial (required to construct ArmorTrim)

Tests

Tested ingame with the smithing table several times:
image

Tested the code

$player->getInventory()->addItem(VanillaItems::LEATHER_CAP()->setTrim(new ArmorTrim(ArmorTrimMaterial::QUARTZ, ArmorTrimPattern::EYE)));

@ShockedPlot7560 ShockedPlot7560 added Category: API Related to the plugin API Category: Core Related to internal functionality Type: Enhancement Contributes features or other improvements to PocketMine-MP labels Dec 20, 2023
src/block/inventory/SmithingTableInventory.php Outdated Show resolved Hide resolved
src/block/inventory/SmithingTableInventory.php Outdated Show resolved Hide resolved
src/crafting/SmithingRecipe.php Outdated Show resolved Hide resolved
src/crafting/SmithingRecipe.php Outdated Show resolved Hide resolved
src/inventory/transaction/SmithingTransaction.php Outdated Show resolved Hide resolved
src/item/ArmorTrimPattern.php Outdated Show resolved Hide resolved
$this->session->getLogger()->debug("Sending armor trim data");
$patterns = array_map(fn(ArmorTrimPattern $pattern) => new TrimPattern($pattern->getItemId(), $pattern->value), ArmorTrimPattern::cases());
$materials = array_map(fn(ArmorTrimMaterial $material) => new TrimMaterial($material->value, $material->getColor(), $material->getItemId()), ArmorTrimMaterial::cases());
$this->session->sendDataPacket(TrimDataPacket::create($patterns, $materials));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this customizable? If so, why are we using hard enums for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HimmelKreis4865 I don't know about patterns, but colours can be definitely customized. (For example, I can change the amethyst colour from purple to white). What do you think about allowing plugins to customize this?
Screenshot_393

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I'm aware of this, and this should be customizable but I did not yet find a solution for this problem that satisfies me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a commit to make this all customizable, please tell me what you think of this

Copy link
Contributor Author

@HimmelKreis4865 HimmelKreis4865 Mar 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it looks good, but I'm not sure about passing type id and serialized item name to the constructor. Wouldn't a better to pass an Item and then serialize it when sending TrimData?
(from ipad54 on discord)

what do you guys think about this?

src/network/mcpe/cache/CraftingDataCache.php Outdated Show resolved Hide resolved
src/network/mcpe/handler/ItemStackRequestExecutor.php Outdated Show resolved Hide resolved
src/crafting/CraftingManager.php Outdated Show resolved Hide resolved
@HimmelKreis4865
Copy link
Contributor Author

There's not much more I can do at this point, everthing is fixed except for save ids.

Copy link
Contributor

@jasonw4331 jasonw4331 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good to me, one comment.

src/item/Armor.php Outdated Show resolved Hide resolved
@fractalllll

This comment was marked as off-topic.

@pandaaaBE
Copy link
Contributor

pandaaaBE commented Mar 22, 2024

image
Looks finished now :)

@HimmelKreis4865
Copy link
Contributor Author

yeah, ready to be reviewed again.

src/block/SmithingTable.php Outdated Show resolved Hide resolved
* @param Item[] $inputs
* @phpstan-param list<Item> $inputs
*/
public function getResultFor(array $inputs) : ?Item{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sceptical about the fact that it's up to the recipe to find out what the input is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh I don't see a problem here, it also has 2 usages so I don't know how I'd change it smoothly..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this relevant now? If so, please give me some more information on where to move the methods

* @param Item[] $inputs
* @phpstan-param list<Item> $inputs
*/
public function getResultFor(array $inputs) : ?Item{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

src/crafting/SmithingTransformRecipe.php Show resolved Hide resolved
src/item/ArmorTrim.php Outdated Show resolved Hide resolved
src/item/Armor.php Outdated Show resolved Hide resolved
src/item/SmithingTemplate.php Outdated Show resolved Hide resolved
src/utils/TextFormat.php Outdated Show resolved Hide resolved
@HimmelKreis4865
Copy link
Contributor Author

what is still missing?

@pandaaaBE
Copy link
Contributor

what is still missing?

nothing. just reviews 😭

Copy link
Contributor

@jasonw4331 jasonw4331 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some micro-optimizations which I believe may help the API

public function __construct(
private readonly RecipeIngredient $input,
private readonly RecipeIngredient $addition,
private readonly RecipeIngredient $template){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because these are readonly values the getter functions are redundant and these variables can be made public

public function __construct(
private string $identifier,
private string $itemName,
private int $typeId
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can also be public, making the getters redundant.

private string $identifier,
private string $color,
private string $itemName,
private int $typeId
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can also be public, making the getters redundant.

}

private function registerDefaultMaterials() : void{
$this->registerMaterial(new ArmorTrimMaterial(ArmorTrimMaterial::AMETHYST, TextFormat::MATERIAL_AMETHYST, Names::AMETHYST_SHARD, Ids::AMETHYST_SHARD));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in discord, it would be better to pass an Item and then serialise it when sending TrimData instead of passing type id and serialised item name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: API Related to the plugin API Category: Core Related to internal functionality Status: Waiting on Author Type: Enhancement Contributes features or other improvements to PocketMine-MP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants