mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-24 03:25:13 +01:00
Fix entity.l being called and use bukkit equivalent, update EntitySense, knockback enchantments get applied
This commit is contained in:
parent
71d4752c58
commit
a80bc89044
@ -7,11 +7,10 @@ import net.citizensnpcs.api.ai.TargetType;
|
||||
import net.citizensnpcs.api.ai.event.CancelReason;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
import net.minecraft.server.EntityLiving;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.Navigation;
|
||||
import net.minecraft.server.Packet18ArmAnimation;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
||||
@ -37,7 +36,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
|
||||
private boolean canAttack() {
|
||||
return attackTicks == 0
|
||||
&& (handle.boundingBox.e > target.boundingBox.b && handle.boundingBox.b < target.boundingBox.e)
|
||||
&& distanceSquared() <= ATTACK_DISTANCE && handle.l(target);
|
||||
&& distanceSquared() <= ATTACK_DISTANCE && hasLineOfSight();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,6 +68,10 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
|
||||
return TargetType.ENTITY;
|
||||
}
|
||||
|
||||
private boolean hasLineOfSight() {
|
||||
return ((LivingEntity) handle.getBukkitEntity()).hasLineOfSight(target.getBukkitEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAggressive() {
|
||||
return aggro;
|
||||
@ -100,8 +103,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
|
||||
} else if (handle instanceof EntityPlayer) {
|
||||
EntityPlayer humanHandle = (EntityPlayer) handle;
|
||||
humanHandle.attack(target);
|
||||
Util.sendPacketNearby(handle.getBukkitEntity().getLocation(), new Packet18ArmAnimation(
|
||||
humanHandle, 1), 64);
|
||||
PlayerAnimation.HURT.play(humanHandle.getBukkitEntity());
|
||||
} else {
|
||||
NMS.attack(handle, target);
|
||||
}
|
||||
|
@ -116,6 +116,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
||||
if (npc == null)
|
||||
return;
|
||||
|
||||
az().a();
|
||||
Navigation navigation = getNavigation();
|
||||
if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON)
|
||||
motX = motY = motZ = 0;
|
||||
|
@ -9,10 +9,12 @@ import java.util.WeakHashMap;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.minecraft.server.ControllerLook;
|
||||
import net.minecraft.server.DamageSource;
|
||||
import net.minecraft.server.EnchantmentManager;
|
||||
import net.minecraft.server.Entity;
|
||||
import net.minecraft.server.EntityLiving;
|
||||
import net.minecraft.server.EntityMonster;
|
||||
import net.minecraft.server.EntityTypes;
|
||||
import net.minecraft.server.MathHelper;
|
||||
import net.minecraft.server.MobEffectList;
|
||||
import net.minecraft.server.Navigation;
|
||||
import net.minecraft.server.NetworkManager;
|
||||
@ -70,7 +72,29 @@ public class NMS {
|
||||
damage -= 2 << handle.getEffect(MobEffectList.WEAKNESS).getAmplifier();
|
||||
}
|
||||
|
||||
target.damageEntity(DamageSource.mobAttack(handle), damage);
|
||||
int knockbackLevel = 0;
|
||||
|
||||
if (target instanceof EntityLiving) {
|
||||
damage += EnchantmentManager.a(handle, target);
|
||||
knockbackLevel += EnchantmentManager.getKnockbackEnchantmentLevel(handle, target);
|
||||
}
|
||||
|
||||
boolean success = target.damageEntity(DamageSource.mobAttack(handle), damage);
|
||||
|
||||
if (!success)
|
||||
return;
|
||||
if (knockbackLevel > 0) {
|
||||
target.g(-MathHelper.sin((float) (handle.yaw * Math.PI / 180.0F)) * knockbackLevel * 0.5F, 0.1D,
|
||||
|
||||
MathHelper.cos((float) (handle.yaw * Math.PI / 180.0F)) * knockbackLevel * 0.5F);
|
||||
handle.motX *= 0.6D;
|
||||
handle.motZ *= 0.6D;
|
||||
}
|
||||
|
||||
int fireAspectLevel = EnchantmentManager.getFireAspectEnchantmentLevel(handle, target);
|
||||
|
||||
if (fireAspectLevel > 0)
|
||||
target.setOnFire(fireAspectLevel * 4);
|
||||
}
|
||||
|
||||
public static void clearGoals(PathfinderGoalSelector... goalSelectors) {
|
||||
|
@ -6,9 +6,6 @@ import net.minecraft.server.Packet17EntityLocationAction;
|
||||
import net.minecraft.server.Packet18ArmAnimation;
|
||||
import net.minecraft.server.Packet40EntityMetadata;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -60,7 +57,11 @@ public enum PlayerAnimation {
|
||||
};
|
||||
|
||||
public void play(Player player) {
|
||||
playAnimation(((CraftPlayer) player).getHandle(), 64);
|
||||
play(player, 64);
|
||||
}
|
||||
|
||||
public void play(Player player, int radius) {
|
||||
playAnimation(((CraftPlayer) player).getHandle(), radius);
|
||||
}
|
||||
|
||||
protected void playAnimation(EntityPlayer player, int radius) {
|
||||
@ -68,15 +69,6 @@ public enum PlayerAnimation {
|
||||
}
|
||||
|
||||
protected void sendPacketNearby(Packet packet, EntityPlayer player, int radius) {
|
||||
radius *= radius;
|
||||
World world = player.world.getWorld();
|
||||
Location location = player.getBukkitEntity().getLocation();
|
||||
for (Player dest : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (dest == null || world != dest.getWorld())
|
||||
continue;
|
||||
if (location.distanceSquared(dest.getLocation()) > radius)
|
||||
continue;
|
||||
((CraftPlayer) dest).getHandle().netServerHandler.sendPacket(packet);
|
||||
}
|
||||
Util.sendPacketNearby(player.getBukkitEntity().getLocation(), packet, radius);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user