tanyaofei / minecraft-fakeplayer

A plugin for minecraft server to spawn fake players, inspired by Carpet Mod
Apache License 2.0
94 stars 12 forks source link

FakePlayer does not receive knockback when hit by players #94

Open BoomPixel opened 4 days ago

BoomPixel commented 4 days ago

Describe the bug / 描述你的 bug 情况 When a FakePlayer is hit by another player, the FakePlayer does not receive knockback.

To Reproduce / 如何触发 Steps to reproduce the behavior: / 触发的步骤

  1. Create a FakePlayer using the plugin.
  2. Hit the FakePlayer with any weapon or by hand.
  3. Observe that the FakePlayer does not receive any knockback.

Server information / 服务器信息

Additional context / 更多信息 Only the plugin and the required dependencies are installed, with no other plugins present. No errors appear in the server logs.

PPGC777 commented 3 days ago

I guess you have OP privilege. So, when you spawn the fakeplayer, this fakeplayer maybe is godmode or other gamemode.

BoomPixel commented 3 days ago

The issue doesn't seem to be related to OP privileges or a specific gamemode like godmode. After reviewing the Citizens plugin code, I found a solution to the knockback issue for FakePlayers. The problem occurs because knockback is usually handled by the client for player entities, but since FakePlayers don’t have a client, this logic needs to be manually handled on the server.

In Citizens, they resolved this by manually handling the knockback server-side. Here’s how they implemented it:

  @Override
  public boolean hurt(DamageSource damagesource, float f) {
      // knock back velocity is cancelled and sent to client for handling when
      // the entity is a player. there is no client so make this happen
      // manually.
      boolean damaged = super.hurt(damagesource, f);
      if (damaged && hurtMarked) {
          hurtMarked = false;
          Bukkit.getScheduler().runTask(CitizensAPI.getPlugin(), () -> EntityHumanNPC.this.hurtMarked = true);
      }
      return damaged;
  }

Source: https://github.com/CitizensDev/Citizens2/blob/0f701a3c4078ab8adac30365180fae34babab411/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/entity/EntityHumanNPC.java#L248-L259

Ziyang-Bai commented 2 days ago

参阅README 默认情况下,假玩家处于无敌模式。玩家需要手动关闭无敌模式 /fp config set invulnerable false 才能吸引侵略性。关闭后,他们会收到饥饿和健康效果。您可能需要使用 res 或 信标 来确保假玩家的饥饿和健康。 所以假人处于无敌模式,你应当使用 指令将玩家修改为允许被攻击的模式 See README By default, fake players are in invincible mode. Players need to manually turn off invincible mode with /fp config set invulnerable false to attract aggression. After turning it off, they will receive hunger and health effects. You may need to use res or beacon to ensure the fake player's hunger 和 health。 So the fakeplayer is in invincible mode, you should use the command to modify the fakeplayer to a mode that allows being attacked or knockback. @ @BoomPixel

u12e1juioj commented 2 days ago

参阅README 默认情况下,假玩家处于无敌模式。玩家需要手动关闭无敌模式 /fp config set invulnerable false 才能吸引侵略性。关闭后,他们会收到饥饿和健康效果。您可能需要使用 res 或 信标 来确保假玩家的饥饿和健康。 所以假人处于无敌模式,你应当使用 指令将玩家修改为允许被攻击的模式 See README By default, fake players are in invincible mode. Players need to manually turn off invincible mode with /fp config set invulnerable false to attract aggression. After turning it off, they will receive hunger and health effects. You may need to use res or beacon to ensure the fake player's hunger 和 health。 So the fakeplayer is in invincible mode, you should use the command to modify the fakeplayer to a mode that allows being attacked or knockback. @ @BoomPixel

已经关闭了无敌模式,可正常受到爆炸造成的击退,但不能受到玩家攻击所造成的击退,可造成正常伤害

Ziyang-Bai commented 1 day ago

That's weird, But why are you giving FakePlayer knockback (to play as badminton? LOL)? I use this plugin mainly to give redstone machines random ticks.

tanyaofei commented 1 day ago

knockback is a clientside behavior, so they are not knocked back when attacked by other players. i am looking for a way to simulate knockback to maintain the same behavior

u12e1juioj commented 1 day ago

That's weird, But why are you giving FakePlayer knockback (to play as badminton? LOL)? I use this plugin mainly to give redstone machines random ticks.

所以能否添加一个开关来使FakePlayer受到玩家击退,我正在研究一些有趣的装置

Ziyang-Bai commented 1 day ago

也许我会研究出来解决方法,过段时间也许我会提交贡献。 Maybe I'll work out a solution, I'll submit a contribution later.