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
Implement Villager v2 and trade functionality #6310
base: minor-next
Are you sure you want to change the base?
Conversation
Do we really want to force an API to everyone ? I can only think about the Form API. Wouldn't it be the function of a virion to do so? |
On the other hand people will know as long as pocketmine gets updated this feature will be supported |
I don't think it is possible to implement this with virion so. |
Now ready to be reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick review, I still have to validate with BDS behavior
final class ArmorerProfession extends VillagerProfession{ | ||
|
||
public function __construct(){ | ||
parent::__construct(VillagerProfessionTypeIds::ARMORER, "entity.villager.armor", VanillaBlocks::BLAST_FURNACE()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a translation key, make a PR in https://github.com/pmmp/Language to later use a constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a client-side translation key, so I don't think PM-side translations are needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid hardcode translations, this is not the only place where translation is only used client-side, e.g. names of enchantments.
} | ||
|
||
/** @phpstan-return list<TradeRecipe> */ | ||
public function getRecipes(int $biomeId) : array{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In vanilla only a few recipes are selected per group, see https://github.com/Mojang/bedrock-samples/blob/main/behavior_pack/trading/armorer_trades.json, for more details. Probably with a function that generates recipes is not enough and will have to be extended to a dedicated class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So as far as I understand, (also according to bedrock.dev wiki), recipes are separated something called "groups" and they are randomly selected whenever trade recipes are generated, right? Perhaps we could make a script that generates recipe class from behaviour pack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would be best if this is self-generated. I think that for now we only need to make an api to implement trade tables with their groups and leave the generation of recipes for another PR.
|
||
namespace pocketmine\entity\trade; | ||
|
||
final class TradeRecipeData{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the name of the class, it gives me to understand that it contains the data of a single recipe, or that it's for data processing, maybe something like TradeRecipeManager, TradeRecipeGroup, or TradeRecipesHolder would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not sure about this class name. TradeRecipeManager feels like it's too generic (which people might understand it manages all trade recipes), TradeRecipeGroup doesn't seem valid since it doesn't only contain trade recipes. TradeRecipesHolder might be good but I think we still need better name than these. (or separate other values like tier, exp to other class?)
use pocketmine\entity\Living; | ||
use pocketmine\network\mcpe\protocol\ClientboundPacket; | ||
|
||
abstract class EntityInventory extends SimpleInventory{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What other uses would this class have?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if there are any other use cases (including future), as far as I know trade is the only one which doesn't use ContainerOpen for opening inventory.
The pull request is very bloated by the recipes generation, so perhaps it would be nice to leave them for a separate PR |
At the moment I'm still dubious about the fact that the API has been implemented right down to the NPC itself. Is this a mission of pocketmine itself, or in the same way as the forms, we should let the community create libraries instead of imposing one. |
It isn't same with forms. Trade needs a lot of reflection hacks and closure hacks to work on plugins. |
by the way, villager trading is not only an api but also implements the normal trades now, unlike before. i find it nice that the pr also offer an api to be able to make trades, if there were several different plugins the support on the discord server would be annoying just like with scoreboard, bossbar and forms apis - it's annoying if someone uses jojo's api but you don't know the api yourself it would be better if there was one in the core that everyone uses |
Introduction
This PR implements Villager V2 and trade functionality.
Relevant issues
Changes
API changes
VillagerV2::setProfession(VillagerProfession)
: Sets a profession of this villager, also updates recipes.VillagerV2::getProfession() : VillagerProfession
: Returns the current profession of the villager.VillagerV2::getRecipeData() : RecipeData
: Returns the recipe data of this villager.Behavioural changes
Villager Spawn Egg will now spawn Villager V2 instead of legacy Villager.
Backwards compatibility
There is no known BC breaking change.
Follow-up
N/A
Tests
I tested this PR by doing the following (tick all that apply):
tests/phpunit
folder)Minecraft.2024-03-26.14-47-44.mp4
Plugin used for this test: