Improve underwater mobs staying in place

This commit is contained in:
fullwall 2022-02-16 17:36:03 +08:00
parent bf56a6dcb2
commit 984ce6d9e7
27 changed files with 245 additions and 49 deletions

View File

@ -11,6 +11,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.WaterMob;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.metadata.FixedMetadataValue;
@ -151,6 +152,11 @@ public class CitizensNPC extends AbstractNPC {
return getEntity() != null && NMS.isValid(getEntity());
}
private boolean isWaterMob(Entity entity) {
return entity instanceof WaterMob || entity.getType().name().equals("TURTLE")
|| entity.getType().name().equals("AXOLOTL");
}
@Override
public void load(final DataKey root) {
super.load(root);
@ -362,7 +368,8 @@ public class CitizensNPC extends AbstractNPC {
resetCachedCoord();
return;
}
if (data().get(NPC.Metadata.SWIMMING, true)) {
if (data().has(NPC.Metadata.SWIMMING) ? data().<Boolean> get(NPC.Metadata.SWIMMING)
: !isWaterMob(getEntity())) {
NMS.trySwim(getEntity());
}
navigator.run();
@ -397,6 +404,7 @@ public class CitizensNPC extends AbstractNPC {
if (isLiving) {
NMS.setKnockbackResistance((LivingEntity) getEntity(), isProtected() ? 1D : 0D);
}
if (isLiving && getEntity() instanceof Player) {
updateUsingItemState((Player) getEntity());
}

View File

@ -22,6 +22,7 @@ import net.minecraft.server.v1_13_R2.EntityCod;
import net.minecraft.server.v1_13_R2.EntityHuman;
import net.minecraft.server.v1_13_R2.EntityMinecartAbstract;
import net.minecraft.server.v1_13_R2.EnumHand;
import net.minecraft.server.v1_13_R2.EnumMoveType;
import net.minecraft.server.v1_13_R2.IBlockData;
import net.minecraft.server.v1_13_R2.ItemStack;
import net.minecraft.server.v1_13_R2.Items;
@ -90,7 +91,16 @@ public class CodController extends MobEntityController {
@Override
public void a(float f, float f1, float f2) {
if (npc == null || !npc.isFlyable()) {
super.a(f, f1, f2);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(f, f1, f2, 0.01F);
this.move(EnumMoveType.SELF, this.motX, this.motY, this.motZ);
this.motX *= 0.9D;
this.motY *= 0.9D;
this.motZ *= 0.9D;
} else {
super.a(f, f1, f2);
}
} else {
NMSImpl.flyingMoveLogic(this, f, f1, f2);
}

View File

@ -22,6 +22,7 @@ import net.minecraft.server.v1_13_R2.EntityHuman;
import net.minecraft.server.v1_13_R2.EntityMinecartAbstract;
import net.minecraft.server.v1_13_R2.EntitySalmon;
import net.minecraft.server.v1_13_R2.EnumHand;
import net.minecraft.server.v1_13_R2.EnumMoveType;
import net.minecraft.server.v1_13_R2.IBlockData;
import net.minecraft.server.v1_13_R2.ItemStack;
import net.minecraft.server.v1_13_R2.Items;
@ -76,7 +77,16 @@ public class SalmonController extends MobEntityController {
@Override
public void a(float f, float f1, float f2) {
if (npc == null || !npc.isFlyable()) {
super.a(f, f1, f2);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(f, f1, f2, 0.01F);
this.move(EnumMoveType.SELF, this.motX, this.motY, this.motZ);
this.motX *= 0.9D;
this.motY *= 0.9D;
this.motZ *= 0.9D;
} else {
super.a(f, f1, f2);
}
} else {
NMSImpl.flyingMoveLogic(this, f, f1, f2);
}

View File

@ -22,6 +22,7 @@ import net.minecraft.server.v1_13_R2.EntityHuman;
import net.minecraft.server.v1_13_R2.EntityMinecartAbstract;
import net.minecraft.server.v1_13_R2.EntityTropicalFish;
import net.minecraft.server.v1_13_R2.EnumHand;
import net.minecraft.server.v1_13_R2.EnumMoveType;
import net.minecraft.server.v1_13_R2.IBlockData;
import net.minecraft.server.v1_13_R2.ItemStack;
import net.minecraft.server.v1_13_R2.Items;
@ -76,7 +77,16 @@ public class TropicalFishController extends MobEntityController {
@Override
public void a(float f, float f1, float f2) {
if (npc == null || !npc.isFlyable()) {
super.a(f, f1, f2);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(f, f1, f2, 0.01F);
this.move(EnumMoveType.SELF, this.motX, this.motY, this.motZ);
this.motX *= 0.9D;
this.motY *= 0.9D;
this.motZ *= 0.9D;
} else {
super.a(f, f1, f2);
}
} else {
NMSImpl.flyingMoveLogic(this, f, f1, f2);
}

View File

@ -22,6 +22,7 @@ import net.minecraft.server.v1_13_R2.EntityBoat;
import net.minecraft.server.v1_13_R2.EntityInsentient;
import net.minecraft.server.v1_13_R2.EntityMinecartAbstract;
import net.minecraft.server.v1_13_R2.EntityTurtle;
import net.minecraft.server.v1_13_R2.EnumMoveType;
import net.minecraft.server.v1_13_R2.IBlockData;
import net.minecraft.server.v1_13_R2.NBTTagCompound;
import net.minecraft.server.v1_13_R2.Navigation;
@ -66,7 +67,16 @@ public class TurtleController extends MobEntityController {
@Override
public void a(float f, float f1, float f2) {
if (npc == null || !npc.isFlyable()) {
super.a(f, f1, f2);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(f, f1, f2, 0.01F);
this.move(EnumMoveType.SELF, this.motX, this.motY, this.motZ);
this.motX *= 0.9D;
this.motY *= 0.9D;
this.motZ *= 0.9D;
} else {
super.a(f, f1, f2);
}
} else {
NMSImpl.flyingMoveLogic(this, f, f1, f2);
}

View File

@ -23,6 +23,7 @@ import net.minecraft.server.v1_14_R1.EntityHuman;
import net.minecraft.server.v1_14_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_14_R1.EntityTypes;
import net.minecraft.server.v1_14_R1.EnumHand;
import net.minecraft.server.v1_14_R1.EnumMoveType;
import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.ItemStack;
import net.minecraft.server.v1_14_R1.Items;
@ -120,7 +121,13 @@ public class CodController extends MobEntityController {
@Override
public void e(Vec3D vec3d) {
if (npc == null || !npc.isFlyable()) {
super.e(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(0.01F, vec3d);
this.move(EnumMoveType.SELF, this.getMot());
this.setMot(this.getMot().a(0.9D));
} else {
super.e(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -23,6 +23,7 @@ import net.minecraft.server.v1_14_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_14_R1.EntitySalmon;
import net.minecraft.server.v1_14_R1.EntityTypes;
import net.minecraft.server.v1_14_R1.EnumHand;
import net.minecraft.server.v1_14_R1.EnumMoveType;
import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.ItemStack;
import net.minecraft.server.v1_14_R1.Items;
@ -106,7 +107,13 @@ public class SalmonController extends MobEntityController {
@Override
public void e(Vec3D vec3d) {
if (npc == null || !npc.isFlyable()) {
super.e(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(0.01F, vec3d);
this.move(EnumMoveType.SELF, this.getMot());
this.setMot(this.getMot().a(0.9D));
} else {
super.e(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -23,6 +23,7 @@ import net.minecraft.server.v1_14_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_14_R1.EntityTropicalFish;
import net.minecraft.server.v1_14_R1.EntityTypes;
import net.minecraft.server.v1_14_R1.EnumHand;
import net.minecraft.server.v1_14_R1.EnumMoveType;
import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.ItemStack;
import net.minecraft.server.v1_14_R1.Items;
@ -106,7 +107,13 @@ public class TropicalFishController extends MobEntityController {
@Override
public void e(Vec3D vec3d) {
if (npc == null || !npc.isFlyable()) {
super.e(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(0.01F, vec3d);
this.move(EnumMoveType.SELF, this.getMot());
this.setMot(this.getMot().a(0.9D));
} else {
super.e(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -23,6 +23,7 @@ import net.minecraft.server.v1_14_R1.EntityInsentient;
import net.minecraft.server.v1_14_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_14_R1.EntityTurtle;
import net.minecraft.server.v1_14_R1.EntityTypes;
import net.minecraft.server.v1_14_R1.EnumMoveType;
import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_14_R1.Navigation;
@ -104,7 +105,13 @@ public class TurtleController extends MobEntityController {
@Override
public void e(Vec3D vec3d) {
if (npc == null || !npc.isFlyable()) {
super.e(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(0.01F, vec3d);
this.move(EnumMoveType.SELF, this.getMot());
this.setMot(this.getMot().a(0.9D));
} else {
super.e(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -24,6 +24,7 @@ import net.minecraft.server.v1_15_R1.EntityHuman;
import net.minecraft.server.v1_15_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_15_R1.EntityTypes;
import net.minecraft.server.v1_15_R1.EnumHand;
import net.minecraft.server.v1_15_R1.EnumMoveType;
import net.minecraft.server.v1_15_R1.IBlockData;
import net.minecraft.server.v1_15_R1.ItemStack;
import net.minecraft.server.v1_15_R1.Items;
@ -124,7 +125,13 @@ public class CodController extends MobEntityController {
@Override
public void e(Vec3D vec3d) {
if (npc == null || !npc.isFlyable()) {
super.e(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(0.01F, vec3d);
this.move(EnumMoveType.SELF, this.getMot());
this.setMot(this.getMot().a(0.9D));
} else {
super.e(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -24,6 +24,7 @@ import net.minecraft.server.v1_15_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_15_R1.EntitySalmon;
import net.minecraft.server.v1_15_R1.EntityTypes;
import net.minecraft.server.v1_15_R1.EnumHand;
import net.minecraft.server.v1_15_R1.EnumMoveType;
import net.minecraft.server.v1_15_R1.IBlockData;
import net.minecraft.server.v1_15_R1.ItemStack;
import net.minecraft.server.v1_15_R1.Items;
@ -110,7 +111,13 @@ public class SalmonController extends MobEntityController {
@Override
public void e(Vec3D vec3d) {
if (npc == null || !npc.isFlyable()) {
super.e(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(0.01F, vec3d);
this.move(EnumMoveType.SELF, this.getMot());
this.setMot(this.getMot().a(0.9D));
} else {
super.e(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -24,6 +24,7 @@ import net.minecraft.server.v1_15_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_15_R1.EntityTropicalFish;
import net.minecraft.server.v1_15_R1.EntityTypes;
import net.minecraft.server.v1_15_R1.EnumHand;
import net.minecraft.server.v1_15_R1.EnumMoveType;
import net.minecraft.server.v1_15_R1.IBlockData;
import net.minecraft.server.v1_15_R1.ItemStack;
import net.minecraft.server.v1_15_R1.Items;
@ -110,7 +111,13 @@ public class TropicalFishController extends MobEntityController {
@Override
public void e(Vec3D vec3d) {
if (npc == null || !npc.isFlyable()) {
super.e(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(0.01F, vec3d);
this.move(EnumMoveType.SELF, this.getMot());
this.setMot(this.getMot().a(0.9D));
} else {
super.e(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -24,6 +24,7 @@ import net.minecraft.server.v1_15_R1.EntityInsentient;
import net.minecraft.server.v1_15_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_15_R1.EntityTurtle;
import net.minecraft.server.v1_15_R1.EntityTypes;
import net.minecraft.server.v1_15_R1.EnumMoveType;
import net.minecraft.server.v1_15_R1.IBlockData;
import net.minecraft.server.v1_15_R1.NBTTagCompound;
import net.minecraft.server.v1_15_R1.Navigation;
@ -110,7 +111,13 @@ public class TurtleController extends MobEntityController {
@Override
public void e(Vec3D vec3d) {
if (npc == null || !npc.isFlyable()) {
super.e(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(0.01F, vec3d);
this.move(EnumMoveType.SELF, this.getMot());
this.setMot(this.getMot().a(0.9D));
} else {
super.e(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -26,6 +26,7 @@ import net.minecraft.server.v1_16_R3.EntityMinecartAbstract;
import net.minecraft.server.v1_16_R3.EntityTypes;
import net.minecraft.server.v1_16_R3.EnumHand;
import net.minecraft.server.v1_16_R3.EnumInteractionResult;
import net.minecraft.server.v1_16_R3.EnumMoveType;
import net.minecraft.server.v1_16_R3.IBlockData;
import net.minecraft.server.v1_16_R3.ItemStack;
import net.minecraft.server.v1_16_R3.Items;
@ -131,7 +132,13 @@ public class CodController extends MobEntityController {
@Override
public void g(Vec3D vec3d) {
if (npc == null || !npc.isFlyable()) {
super.g(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(0.01F, vec3d);
this.move(EnumMoveType.SELF, this.getMot());
this.setMot(this.getMot().a(0.9D));
} else {
super.g(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -26,6 +26,7 @@ import net.minecraft.server.v1_16_R3.EntitySalmon;
import net.minecraft.server.v1_16_R3.EntityTypes;
import net.minecraft.server.v1_16_R3.EnumHand;
import net.minecraft.server.v1_16_R3.EnumInteractionResult;
import net.minecraft.server.v1_16_R3.EnumMoveType;
import net.minecraft.server.v1_16_R3.IBlockData;
import net.minecraft.server.v1_16_R3.ItemStack;
import net.minecraft.server.v1_16_R3.Items;
@ -125,7 +126,13 @@ public class SalmonController extends MobEntityController {
@Override
public void g(Vec3D vec3d) {
if (npc == null || !npc.isFlyable()) {
super.g(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(0.01F, vec3d);
this.move(EnumMoveType.SELF, this.getMot());
this.setMot(this.getMot().a(0.9D));
} else {
super.g(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -26,6 +26,7 @@ import net.minecraft.server.v1_16_R3.EntityTropicalFish;
import net.minecraft.server.v1_16_R3.EntityTypes;
import net.minecraft.server.v1_16_R3.EnumHand;
import net.minecraft.server.v1_16_R3.EnumInteractionResult;
import net.minecraft.server.v1_16_R3.EnumMoveType;
import net.minecraft.server.v1_16_R3.IBlockData;
import net.minecraft.server.v1_16_R3.ItemStack;
import net.minecraft.server.v1_16_R3.Items;
@ -125,7 +126,13 @@ public class TropicalFishController extends MobEntityController {
@Override
public void g(Vec3D vec3d) {
if (npc == null || !npc.isFlyable()) {
super.g(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(0.01F, vec3d);
this.move(EnumMoveType.SELF, this.getMot());
this.setMot(this.getMot().a(0.9D));
} else {
super.g(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -25,6 +25,7 @@ import net.minecraft.server.v1_16_R3.EntityInsentient;
import net.minecraft.server.v1_16_R3.EntityMinecartAbstract;
import net.minecraft.server.v1_16_R3.EntityTurtle;
import net.minecraft.server.v1_16_R3.EntityTypes;
import net.minecraft.server.v1_16_R3.EnumMoveType;
import net.minecraft.server.v1_16_R3.IBlockData;
import net.minecraft.server.v1_16_R3.NBTTagCompound;
import net.minecraft.server.v1_16_R3.Navigation;
@ -124,7 +125,13 @@ public class TurtleController extends MobEntityController {
@Override
public void g(Vec3D vec3d) {
if (npc == null || !npc.isFlyable()) {
super.g(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.a(0.01F, vec3d);
this.move(EnumMoveType.SELF, this.getMot());
this.setMot(this.getMot().a(0.9D));
} else {
super.g(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -22,6 +22,7 @@ import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.entity.ai.navigation.GroundPathNavigation;
import net.minecraft.world.entity.ai.navigation.PathNavigation;
@ -228,7 +229,13 @@ public class AxolotlController extends MobEntityController {
@Override
public void travel(Vec3 vec3d) {
if (npc == null || !npc.isFlyable()) {
super.travel(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.moveRelative(this.getSpeed(), vec3d);
this.move(MoverType.SELF, this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().scale(0.9D));
} else {
super.travel(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -22,6 +22,7 @@ import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.entity.animal.Cod;
import net.minecraft.world.entity.player.Player;
@ -228,7 +229,13 @@ public class CodController extends MobEntityController {
@Override
public void travel(Vec3 vec3d) {
if (npc == null || !npc.isFlyable()) {
super.travel(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.moveRelative(0.01F, vec3d);
this.move(MoverType.SELF, this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().scale(0.9D));
} else {
super.travel(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -22,6 +22,7 @@ import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.entity.animal.Salmon;
import net.minecraft.world.entity.player.Player;
@ -220,7 +221,13 @@ public class SalmonController extends MobEntityController {
@Override
public void travel(Vec3 vec3d) {
if (npc == null || !npc.isFlyable()) {
super.travel(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.moveRelative(0.01F, vec3d);
this.move(MoverType.SELF, this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().scale(0.9D));
} else {
super.travel(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -22,6 +22,7 @@ import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.entity.animal.TropicalFish;
import net.minecraft.world.entity.player.Player;
@ -222,7 +223,13 @@ public class TropicalFishController extends MobEntityController {
@Override
public void travel(Vec3 vec3d) {
if (npc == null || !npc.isFlyable()) {
super.travel(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.moveRelative(0.01F, vec3d);
this.move(MoverType.SELF, this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().scale(0.9D));
} else {
super.travel(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -21,6 +21,7 @@ import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.ai.control.JumpControl;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.entity.ai.navigation.GroundPathNavigation;
@ -207,7 +208,13 @@ public class TurtleController extends MobEntityController {
@Override
public void travel(Vec3 vec3d) {
if (npc == null || !npc.isFlyable()) {
super.travel(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.moveRelative(0.1F, vec3d);
this.move(MoverType.SELF, this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().scale(0.9D));
} else {
super.travel(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -23,6 +23,7 @@ import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.entity.ai.navigation.GroundPathNavigation;
import net.minecraft.world.entity.ai.navigation.PathNavigation;
@ -236,7 +237,13 @@ public class AxolotlController extends MobEntityController {
@Override
public void travel(Vec3 vec3d) {
if (npc == null || !npc.isFlyable()) {
super.travel(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.moveRelative(this.getSpeed(), vec3d);
this.move(MoverType.SELF, this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().scale(0.9D));
} else {
super.travel(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -23,6 +23,7 @@ import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.entity.animal.Cod;
import net.minecraft.world.entity.player.Player;
@ -217,8 +218,9 @@ public class CodController extends MobEntityController {
// this method is called by both the entities involved - cancelling
// it will not stop the NPC from moving.
super.push(entity);
if (npc != null)
if (npc != null) {
Util.callCollisionEvent(npc, entity.getBukkitEntity());
}
}
@Override
@ -236,7 +238,13 @@ public class CodController extends MobEntityController {
@Override
public void travel(Vec3 vec3d) {
if (npc == null || !npc.isFlyable()) {
super.travel(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.moveRelative(0.01F, vec3d);
this.move(MoverType.SELF, this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().scale(0.9D));
} else {
super.travel(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -23,6 +23,7 @@ import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.entity.animal.Salmon;
import net.minecraft.world.entity.player.Player;
@ -228,7 +229,13 @@ public class SalmonController extends MobEntityController {
@Override
public void travel(Vec3 vec3d) {
if (npc == null || !npc.isFlyable()) {
super.travel(vec3d);
if (!npc.useMinecraftAI() && isInWater() ) {
this.moveRelative(0.01F, vec3d);
this.move(MoverType.SELF, this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().scale(0.9D));
} else {
super.travel(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -22,6 +22,7 @@ import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.ai.control.JumpControl;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.entity.ai.navigation.GroundPathNavigation;
@ -215,7 +216,13 @@ public class TurtleController extends MobEntityController {
@Override
public void travel(Vec3 vec3d) {
if (npc == null || !npc.isFlyable()) {
super.travel(vec3d);
if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) {
this.moveRelative(0.1F, vec3d);
this.move(MoverType.SELF, this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().scale(0.9D));
} else {
super.travel(vec3d);
}
} else {
NMSImpl.flyingMoveLogic(this, vec3d);
}

View File

@ -336,56 +336,56 @@ public class NMSImpl implements NMSBridge {
@Override
public void attack(org.bukkit.entity.LivingEntity attacker, org.bukkit.entity.LivingEntity btarget) {
LivingEntity handle = getHandle(attacker);
LivingEntity source = getHandle(attacker);
LivingEntity target = getHandle(btarget);
if (handle instanceof ServerPlayer) {
((ServerPlayer) handle).attack(target);
PlayerAnimation.ARM_SWING.play((Player) handle.getBukkitEntity());
if (source instanceof ServerPlayer) {
((ServerPlayer) source).attack(target);
PlayerAnimation.ARM_SWING.play((Player) source.getBukkitEntity());
return;
}
if (handle instanceof Mob) {
((Mob) handle).doHurtTarget(target);
if (source instanceof Mob) {
((Mob) source).doHurtTarget(target);
return;
}
AttributeInstance attackDamage = handle.getAttribute(Attributes.ATTACK_DAMAGE);
AttributeInstance attackDamage = source.getAttribute(Attributes.ATTACK_DAMAGE);
float f = (float) (attackDamage == null ? 1 : attackDamage.getValue());
int i = 0;
f += EnchantmentHelper.getDamageBonus(handle.getMainHandItem(), target.getMobType());
i += EnchantmentHelper.getKnockbackBonus(handle);
f += EnchantmentHelper.getDamageBonus(source.getMainHandItem(), target.getMobType());
i += EnchantmentHelper.getKnockbackBonus(source);
boolean flag = target.hurt(DamageSource.mobAttack(handle), f);
boolean flag = target.hurt(DamageSource.mobAttack(source), f);
if (!flag)
return;
if (i > 0) {
target.knockback(-Math.sin(handle.getYRot() * Math.PI / 180.0F) * i * 0.5F, 0.1D,
Math.cos(handle.getYRot() * Math.PI / 180.0F) * i * 0.5F);
handle.setDeltaMovement(handle.getDeltaMovement().multiply(0.6, 1, 0.6));
target.knockback(-Math.sin(source.getYRot() * Math.PI / 180.0F) * i * 0.5F, 0.1D,
Math.cos(source.getYRot() * Math.PI / 180.0F) * i * 0.5F);
source.setDeltaMovement(source.getDeltaMovement().multiply(0.6, 1, 0.6));
}
int fireAspectLevel = EnchantmentHelper.getFireAspect(handle);
int fireAspectLevel = EnchantmentHelper.getFireAspect(source);
if (fireAspectLevel > 0) {
target.setSecondsOnFire(fireAspectLevel * 4, false);
}
if (target instanceof ServerPlayer) {
ServerPlayer entityhuman = (ServerPlayer) target;
ItemStack itemstack = handle.getMainHandItem();
ItemStack itemstack = source.getMainHandItem();
ItemStack itemstack1 = entityhuman.isUsingItem() ? entityhuman.getUseItem() : ItemStack.EMPTY;
if (!itemstack.isEmpty() && !itemstack1.isEmpty()
&& itemstack.getItem() instanceof net.minecraft.world.item.AxeItem && itemstack1.is(Items.SHIELD)) {
float f2 = 0.25F + EnchantmentHelper.getBlockEfficiency(handle) * 0.05F;
float f2 = 0.25F + EnchantmentHelper.getBlockEfficiency(source) * 0.05F;
if (new Random().nextFloat() < f2) {
entityhuman.getCooldowns().addCooldown(Items.SHIELD, 100);
handle.level.broadcastEntityEvent(entityhuman, (byte) 30);
source.level.broadcastEntityEvent(entityhuman, (byte) 30);
}
}
}
EnchantmentHelper.doPostHurtEffects(handle, target);
EnchantmentHelper.doPostDamageEffects(target, handle);
EnchantmentHelper.doPostHurtEffects(source, target);
EnchantmentHelper.doPostDamageEffects(target, source);
}
@Override
@ -704,7 +704,7 @@ public class NMSImpl implements NMSBridge {
public TargetNavigator getTargetNavigator(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity target,
NavigatorParameters parameters) {
PathNavigation navigation = getNavigation(entity);
return navigation == null ? null : new NavigationFieldWrapper(navigation, target, parameters);
return navigation == null ? null : new MCTargetNavigator(navigation, target, parameters);
}
@Override
@ -1393,12 +1393,12 @@ public class NMSImpl implements NMSBridge {
}
}
private static class NavigationFieldWrapper implements TargetNavigator {
private static class MCTargetNavigator implements TargetNavigator {
private final PathNavigation navigation;
private final NavigatorParameters parameters;
private final org.bukkit.entity.Entity target;
private NavigationFieldWrapper(PathNavigation navigation, org.bukkit.entity.Entity target,
private MCTargetNavigator(PathNavigation navigation, org.bukkit.entity.Entity target,
NavigatorParameters parameters) {
this.navigation = navigation;
this.target = target;