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

Added Villager Trades and basic movement #1263

Merged
merged 11 commits into from
Jul 13, 2023
Merged

Added Villager Trades and basic movement #1263

merged 11 commits into from
Jul 13, 2023

Conversation

Buddelbubi
Copy link
Member

No description provided.

@smartcmd
Copy link
Member

Cool ❤️

@smartcmd smartcmd requested review from CoolLoong and SuperIceCN and removed request for CoolLoong June 26, 2023 12:17
@SuperIceCN SuperIceCN requested a review from smartcmd June 27, 2023 02:28
Copy link
Member

@SuperIceCN SuperIceCN left a comment

Choose a reason for hiding this comment

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

A Problem is that Profession.class does not exist.

Also, please format your code:

  1. Remove the unused imports
  2. There should be space between expression tokens, e.g. tick % (10 * 10) == 0
  3. There should be space between if/for/while, conditions and code blocks
  4. No empty lines at the start and the end of methods.

Anyway, thank you very much for your contribution to PNX!

pom.xml Outdated
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to roll back the version from 1.18.24 to 1.18.22?

Copy link
Member Author

Choose a reason for hiding this comment

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

IntelliJ did that

Copy link
Member Author

Choose a reason for hiding this comment

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

You dont

),
Set.of(
new Behavior(new FlatRandomRoamExecutor(0.4f, 12, 40, true, 100, true, 10), new PassByTimeEvaluator(CoreMemoryTypes.LAST_BE_ATTACKED_TIME, 0, 100), 4, 1),
new Behavior(new EntityBreedingExecutor<>(EntityPig.class, 16, 100, 0.5f), entity -> entity.getMemoryStorage().get(CoreMemoryTypes.IS_IN_LOVE), 3, 1),
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need EntityBreedingExecutor with EntityPig.class? Can we feed the villagers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Uh. I focused on the functionality. I probably missed that

new Behavior(new LookAtTargetExecutor(CoreMemoryTypes.NEAREST_PLAYER, 100), new ProbabilityEvaluator(4, 10), 1, 1, 100),
new Behavior(new FlatRandomRoamExecutor(0.2f, 12, 100, false, -1, true, 10), (entity -> true), 1, 1)
),
Set.of(new NearestFeedingPlayerSensor(8, 0), new NearestPlayerSensor(8, 0, 20)),
Copy link
Member

Choose a reason for hiding this comment

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

If we use NearestFeedingPlayerSensor, the Entity must extends EntityAnimal. However it's not the case for villager now.

this.setTradeSeed(new Random().nextInt(Integer.MAX_VALUE));
this.setProfession(profession.getIndex());
this.applyProfession(profession);
BlockVector3 blockVector = block.getLocation().asBlockVector3();
Copy link
Member

Choose a reason for hiding this comment

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

Using block.getFloorX/Y/Z instead.

if (id == profession.getBlockid()) {
professionFound = true;
if (this.profession != profession.getIndex()) {
this.setTradeSeed(new Random().nextInt(Integer.MAX_VALUE));
Copy link
Member

Choose a reason for hiding this comment

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

Using ThreadLocalRandom or NukkitRandom from the level of this villager instead, Random is globally synchronized and may block PNX, thereby affecting performance.

pom.xml Show resolved Hide resolved
src/main/java/cn/nukkit/Server.java Show resolved Hide resolved

public static final int NETWORK_ID = 115;
/**
* 代表交易配方
*/
public final ListTag<Tag> recipes = new ListTag<>("Recipes");
@Getter
public ListTag<Tag> recipes = new ListTag<>("Recipes");
Copy link
Member

Choose a reason for hiding this comment

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

change to protected

return new BehaviorGroup(
this.tickSpread,
Set.of(
//用于刷新InLove状态的核心行为
Copy link
Member

Choose a reason for hiding this comment

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

These behaviors do not match the villagers, please remove them

//todo:Growth rate
all(
new PassByTimeEvaluator(CoreMemoryTypes.ENTITY_SPAWN_TIME, 20 * 60 * 20, Integer.MAX_VALUE),
entity -> entity instanceof EntityAnimal animal && animal.isBaby()
Copy link
Member

Choose a reason for hiding this comment

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

please remove this

),
Set.of(
new Behavior(new FlatRandomRoamExecutor(0.4f, 12, 40, true, 100, true, 10), new PassByTimeEvaluator(CoreMemoryTypes.LAST_BE_ATTACKED_TIME, 0, 100), 4, 1),
new Behavior(new EntityBreedingExecutor<>(EntityPig.class, 16, 100, 0.5f), entity -> entity.getMemoryStorage().get(CoreMemoryTypes.IS_IN_LOVE), 3, 1),
Copy link
Member

Choose a reason for hiding this comment

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

please remove this

@@ -300,6 +306,24 @@ public void handle(@NotNull PlayerHandle playerHandle, @NotNull InventoryTransac
}
if (playerHandle.getTradingTransaction().canExecute()) {
playerHandle.getTradingTransaction().execute();

for(Inventory inventory : playerHandle.getTradingTransaction().getInventories()) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggest moving to TradeTransaction#execute

@CoolLoong
Copy link
Member

@Buddelbubi You did not commit cn.nukkit.entity.data.profession.Profession

@SuperIceCN
Copy link
Member

May I ask if you have time to resolve the problems in this PR recently?

@Buddelbubi
Copy link
Member Author

I already did. Did I miss some?

@Mcayear Mcayear requested review from CoolLoong and SuperIceCN July 12, 2023 02:39
@CoolLoong
Copy link
Member

thank you for your PR

@@ -18,7 +18,7 @@ public interface ProtocolInfo {
/**
* Actual Minecraft: PE protocol version
*/
int CURRENT_PROTOCOL = dynamic(589);
int CURRENT_PROTOCOL = dynamic(594);
Copy link
Member

Choose a reason for hiding this comment

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

please wait #1312

@CoolLoong
Copy link
Member

Other than that, there are no issue

@Buddelbubi
Copy link
Member Author

Done

@CoolLoong
Copy link
Member

@SuperIceCN

@SuperIceCN SuperIceCN merged commit 1432647 into PowerNukkitX:master Jul 13, 2023
@SuperIceCN SuperIceCN mentioned this pull request Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants