Fix entity.l being called and use bukkit equivalent, update EntitySense, knockback enchantments get applied

This commit is contained in:
fullwall 2012-10-30 10:53:05 +08:00
parent 71d4752c58
commit a80bc89044
4 changed files with 39 additions and 20 deletions

View File

@ -7,11 +7,10 @@ import net.citizensnpcs.api.ai.TargetType;
import net.citizensnpcs.api.ai.event.CancelReason; import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.PlayerAnimation;
import net.minecraft.server.EntityLiving; import net.minecraft.server.EntityLiving;
import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPlayer;
import net.minecraft.server.Navigation; import net.minecraft.server.Navigation;
import net.minecraft.server.Packet18ArmAnimation;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.craftbukkit.entity.CraftLivingEntity; import org.bukkit.craftbukkit.entity.CraftLivingEntity;
@ -37,7 +36,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
private boolean canAttack() { private boolean canAttack() {
return attackTicks == 0 return attackTicks == 0
&& (handle.boundingBox.e > target.boundingBox.b && handle.boundingBox.b < target.boundingBox.e) && (handle.boundingBox.e > target.boundingBox.b && handle.boundingBox.b < target.boundingBox.e)
&& distanceSquared() <= ATTACK_DISTANCE && handle.l(target); && distanceSquared() <= ATTACK_DISTANCE && hasLineOfSight();
} }
@Override @Override
@ -69,6 +68,10 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
return TargetType.ENTITY; return TargetType.ENTITY;
} }
private boolean hasLineOfSight() {
return ((LivingEntity) handle.getBukkitEntity()).hasLineOfSight(target.getBukkitEntity());
}
@Override @Override
public boolean isAggressive() { public boolean isAggressive() {
return aggro; return aggro;
@ -100,8 +103,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
} else if (handle instanceof EntityPlayer) { } else if (handle instanceof EntityPlayer) {
EntityPlayer humanHandle = (EntityPlayer) handle; EntityPlayer humanHandle = (EntityPlayer) handle;
humanHandle.attack(target); humanHandle.attack(target);
Util.sendPacketNearby(handle.getBukkitEntity().getLocation(), new Packet18ArmAnimation( PlayerAnimation.HURT.play(humanHandle.getBukkitEntity());
humanHandle, 1), 64);
} else { } else {
NMS.attack(handle, target); NMS.attack(handle, target);
} }

View File

@ -116,6 +116,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
if (npc == null) if (npc == null)
return; return;
az().a();
Navigation navigation = getNavigation(); Navigation navigation = getNavigation();
if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON) if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON)
motX = motY = motZ = 0; motX = motY = motZ = 0;

View File

@ -9,10 +9,12 @@ import java.util.WeakHashMap;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.minecraft.server.ControllerLook; import net.minecraft.server.ControllerLook;
import net.minecraft.server.DamageSource; import net.minecraft.server.DamageSource;
import net.minecraft.server.EnchantmentManager;
import net.minecraft.server.Entity; import net.minecraft.server.Entity;
import net.minecraft.server.EntityLiving; import net.minecraft.server.EntityLiving;
import net.minecraft.server.EntityMonster; import net.minecraft.server.EntityMonster;
import net.minecraft.server.EntityTypes; import net.minecraft.server.EntityTypes;
import net.minecraft.server.MathHelper;
import net.minecraft.server.MobEffectList; import net.minecraft.server.MobEffectList;
import net.minecraft.server.Navigation; import net.minecraft.server.Navigation;
import net.minecraft.server.NetworkManager; import net.minecraft.server.NetworkManager;
@ -70,7 +72,29 @@ public class NMS {
damage -= 2 << handle.getEffect(MobEffectList.WEAKNESS).getAmplifier(); 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) { public static void clearGoals(PathfinderGoalSelector... goalSelectors) {

View File

@ -6,9 +6,6 @@ import net.minecraft.server.Packet17EntityLocationAction;
import net.minecraft.server.Packet18ArmAnimation; import net.minecraft.server.Packet18ArmAnimation;
import net.minecraft.server.Packet40EntityMetadata; 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.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -60,7 +57,11 @@ public enum PlayerAnimation {
}; };
public void play(Player player) { 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) { protected void playAnimation(EntityPlayer player, int radius) {
@ -68,15 +69,6 @@ public enum PlayerAnimation {
} }
protected void sendPacketNearby(Packet packet, EntityPlayer player, int radius) { protected void sendPacketNearby(Packet packet, EntityPlayer player, int radius) {
radius *= radius; Util.sendPacketNearby(player.getBukkitEntity().getLocation(), packet, 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);
}
} }
} }