Sync ender dragon parts

This commit is contained in:
fullwall 2023-03-29 00:30:56 +08:00
parent a1281c391f
commit c171e3f29b
12 changed files with 467 additions and 12 deletions

View File

@ -77,6 +77,31 @@ public class NMS {
BRIDGE.attack(attacker, bukkitTarget);
}
public static float[][] calculateDragonPositions(float yrot, double[][] latency) {
float[][] positions = new float[8][];
float f7 = (float) (latency[1][1] - latency[2][1]) * 10.0F * 0.017453292F;
float f8 = (float) Math.cos(f7);
float f9 = (float) Math.sin(f7);
float f6 = yrot * 0.017453292F;
float f11 = (float) Math.sin(f6);
float f12 = (float) Math.cos(f6);
positions[2] = new float[] { f11 * 0.5F, 0.0F, -f12 * 0.5F };
positions[6] = new float[] { f12 * 4.5F, 2F, f11 * 4.5F };
positions[7] = new float[] { f12 * -4.5F, 2f, f11 * -4.5F };
float f15 = (float) (latency[1][1] - latency[0][1]);
positions[0] = new float[] { f11 * 6.5F * f8, f15 + f9 * 6.5F, -f12 * 6.5F * f8 };
positions[1] = new float[] { f11 * 5.5F * f8, f15 + f9 * 5.5F, -f12 * 5.5F * f8 };
for (int k = 3; k < 6; ++k) {
float f16 = f6 + Util.clamp((float) (latency[k][0] - latency[1][0])) * 0.017453292F;
float f3 = (float) Math.sin(f16);
float f4 = (float) Math.cos(f16);
float f17 = (k - 2) * 2.0F;
positions[k] = new float[] { -(f11 * 1.5F + f3 * f17) * f8,
(float) (latency[k][1] - latency[1][1] - (f17 + 1.5F) * f9 + 1.5), (f12 * 1.5F + f4 * f17) * f8 };
}
return positions;
}
public static void callKnockbackEvent(NPC npc, float strength, double dx, double dz,
Consumer<NPCKnockbackEvent> cb) {
NPCKnockbackEvent event = new NPCKnockbackEvent(npc, strength, dx, dz);

View File

@ -15,10 +15,13 @@ import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_10_R1.AxisAlignedBB;
import net.minecraft.server.v1_10_R1.DamageSource;
import net.minecraft.server.v1_10_R1.DragonControllerPhase;
import net.minecraft.server.v1_10_R1.Entity;
import net.minecraft.server.v1_10_R1.EntityEnderDragon;
import net.minecraft.server.v1_10_R1.NBTTagCompound;
import net.minecraft.server.v1_10_R1.SoundEffect;
import net.minecraft.server.v1_10_R1.Vec3D;
import net.minecraft.server.v1_10_R1.World;
public class EnderDragonController extends MobEntityController {
@ -97,7 +100,20 @@ public class EnderDragonController extends MobEntityController {
return npc == null ? super.d(save) : false;
}
@Override
protected boolean dealDamage(DamageSource source, float f) {
if (npc == null)
return super.dealDamage(source, f);
Vec3D old = new Vec3D(motX, motY, motZ);
boolean res = super.dealDamage(source, f);
if (getDragonControllerManager().a() == DragonControllerPhase.k) {
motX = old.x;
motY = old.y;
motZ = old.z;
}
return res;
}
@Override
public void g(double x, double y, double z) {
@ -140,6 +156,31 @@ public class EnderDragonController extends MobEntityController {
public void n() {
if (npc != null) {
npc.update();
if (this.c < 0) {
for (int i = 0; i < this.b.length; ++i) {
this.b[i][0] = this.yaw;
this.b[i][1] = this.locY;
}
}
if (++this.c == this.b.length) {
this.c = 0;
}
this.b[this.c][0] = this.yaw;
this.b[this.c][1] = this.locY;
float[][] pos = NMS.calculateDragonPositions(yaw,
new double[][] { a(0, 1F), a(5, 1F), a(10, 1F), a(12, 1F), a(14, 1F), a(16, 1F) });
for (int j = 0; j < children.length; ++j) {
Vec3D vec3 = new Vec3D(this.children[j].locX, this.children[j].locY, this.children[j].locZ);
children[j].setPosition(this.locX + pos[j][0], this.locY + pos[j][1], this.locZ + pos[j][2]);
children[j].lastX = vec3.x;
children[j].lastY = vec3.y;
children[j].lastZ = vec3.z;
}
if (getBukkitEntity().getPassenger() != null) {
yaw = getBukkitEntity().getPassenger().getLocation().getYaw() - 180;
}

View File

@ -15,10 +15,13 @@ import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
import net.minecraft.server.v1_11_R1.DamageSource;
import net.minecraft.server.v1_11_R1.DragonControllerPhase;
import net.minecraft.server.v1_11_R1.Entity;
import net.minecraft.server.v1_11_R1.EntityEnderDragon;
import net.minecraft.server.v1_11_R1.NBTTagCompound;
import net.minecraft.server.v1_11_R1.SoundEffect;
import net.minecraft.server.v1_11_R1.Vec3D;
import net.minecraft.server.v1_11_R1.World;
public class EnderDragonController extends MobEntityController {
@ -97,7 +100,20 @@ public class EnderDragonController extends MobEntityController {
return npc == null ? super.d(save) : false;
}
@Override
protected boolean dealDamage(DamageSource source, float f) {
if (npc == null)
return super.dealDamage(source, f);
Vec3D old = new Vec3D(motX, motY, motZ);
boolean res = super.dealDamage(source, f);
if (getDragonControllerManager().a() == DragonControllerPhase.k) {
motX = old.x;
motY = old.y;
motZ = old.z;
}
return res;
}
@Override
public void f(double x, double y, double z) {
@ -141,6 +157,31 @@ public class EnderDragonController extends MobEntityController {
public void n() {
if (npc != null) {
npc.update();
if (this.c < 0) {
for (int i = 0; i < this.b.length; ++i) {
this.b[i][0] = this.yaw;
this.b[i][1] = this.locY;
}
}
if (++this.c == this.b.length) {
this.c = 0;
}
this.b[this.c][0] = this.yaw;
this.b[this.c][1] = this.locY;
float[][] pos = NMS.calculateDragonPositions(yaw,
new double[][] { a(0, 1F), a(5, 1F), a(10, 1F), a(12, 1F), a(14, 1F), a(16, 1F) });
for (int j = 0; j < children.length; ++j) {
Vec3D vec3 = new Vec3D(this.children[j].locX, this.children[j].locY, this.children[j].locZ);
children[j].setPosition(this.locX + pos[j][0], this.locY + pos[j][1], this.locZ + pos[j][2]);
children[j].lastX = vec3.x;
children[j].lastY = vec3.y;
children[j].lastZ = vec3.z;
}
if (getBukkitEntity().getPassenger() != null) {
yaw = getBukkitEntity().getPassenger().getLocation().getYaw() - 180;
}

View File

@ -16,10 +16,12 @@ import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_12_R1.AxisAlignedBB;
import net.minecraft.server.v1_12_R1.DamageSource;
import net.minecraft.server.v1_12_R1.DragonControllerPhase;
import net.minecraft.server.v1_12_R1.Entity;
import net.minecraft.server.v1_12_R1.EntityEnderDragon;
import net.minecraft.server.v1_12_R1.NBTTagCompound;
import net.minecraft.server.v1_12_R1.SoundEffect;
import net.minecraft.server.v1_12_R1.Vec3D;
import net.minecraft.server.v1_12_R1.World;
public class EnderDragonController extends MobEntityController {
@ -98,7 +100,20 @@ public class EnderDragonController extends MobEntityController {
return npc == null ? super.d(save) : false;
}
@Override
protected boolean dealDamage(DamageSource source, float f) {
if (npc == null)
return super.dealDamage(source, f);
Vec3D old = new Vec3D(motX, motY, motZ);
boolean res = super.dealDamage(source, f);
if (getDragonControllerManager().a() == DragonControllerPhase.k) {
motX = old.x;
motY = old.y;
motZ = old.z;
}
return res;
}
@Override
public void f(double x, double y, double z) {
@ -142,6 +157,31 @@ public class EnderDragonController extends MobEntityController {
public void n() {
if (npc != null) {
npc.update();
if (this.c < 0) {
for (int i = 0; i < this.b.length; ++i) {
this.b[i][0] = this.yaw;
this.b[i][1] = this.locY;
}
}
if (++this.c == this.b.length) {
this.c = 0;
}
this.b[this.c][0] = this.yaw;
this.b[this.c][1] = this.locY;
float[][] pos = NMS.calculateDragonPositions(yaw,
new double[][] { a(0, 1F), a(5, 1F), a(10, 1F), a(12, 1F), a(14, 1F), a(16, 1F) });
for (int j = 0; j < children.length; ++j) {
Vec3D vec3 = new Vec3D(this.children[j].locX, this.children[j].locY, this.children[j].locZ);
children[j].setPosition(this.locX + pos[j][0], this.locY + pos[j][1], this.locZ + pos[j][2]);
children[j].lastX = vec3.x;
children[j].lastY = vec3.y;
children[j].lastZ = vec3.z;
}
if (getBukkitEntity().getPassenger() != null) {
yaw = getBukkitEntity().getPassenger().getLocation().getYaw() - 180;
}

View File

@ -18,6 +18,7 @@ import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_13_R2.AxisAlignedBB;
import net.minecraft.server.v1_13_R2.DamageSource;
import net.minecraft.server.v1_13_R2.DragonControllerPhase;
import net.minecraft.server.v1_13_R2.Entity;
import net.minecraft.server.v1_13_R2.EntityBoat;
import net.minecraft.server.v1_13_R2.EntityEnderDragon;
@ -26,6 +27,7 @@ import net.minecraft.server.v1_13_R2.FluidType;
import net.minecraft.server.v1_13_R2.NBTTagCompound;
import net.minecraft.server.v1_13_R2.SoundEffect;
import net.minecraft.server.v1_13_R2.Tag;
import net.minecraft.server.v1_13_R2.Vec3D;
import net.minecraft.server.v1_13_R2.World;
public class EnderDragonController extends MobEntityController {
@ -114,7 +116,20 @@ public class EnderDragonController extends MobEntityController {
return NMSImpl.getSoundEffect(npc, super.D(), NPC.Metadata.AMBIENT_SOUND);
}
@Override
protected boolean dealDamage(DamageSource source, float f) {
if (npc == null)
return super.dealDamage(source, f);
Vec3D old = new Vec3D(motX, motY, motZ);
boolean res = super.dealDamage(source, f);
if (getDragonControllerManager().a() == DragonControllerPhase.HOVER) {
motX = old.x;
motY = old.y;
motZ = old.z;
}
return res;
}
@Override
public void f(double x, double y, double z) {
@ -153,6 +168,31 @@ public class EnderDragonController extends MobEntityController {
public void movementTick() {
if (npc != null) {
npc.update();
if (this.c < 0) {
for (int i = 0; i < this.b.length; ++i) {
this.b[i][0] = this.yaw;
this.b[i][1] = this.locY;
}
}
if (++this.c == this.b.length) {
this.c = 0;
}
this.b[this.c][0] = this.yaw;
this.b[this.c][1] = this.locY;
float[][] pos = NMS.calculateDragonPositions(yaw,
new double[][] { a(0, 1F), a(5, 1F), a(10, 1F), a(12, 1F), a(14, 1F), a(16, 1F) });
for (int j = 0; j < children.length; ++j) {
Vec3D vec3 = new Vec3D(this.children[j].locX, this.children[j].locY, this.children[j].locZ);
children[j].setPosition(this.locX + pos[j][0], this.locY + pos[j][1], this.locZ + pos[j][2]);
children[j].lastX = vec3.x;
children[j].lastY = vec3.y;
children[j].lastZ = vec3.z;
}
if (getBukkitEntity().getPassenger() != null) {
yaw = getBukkitEntity().getPassenger().getLocation().getYaw() - 180;
}

View File

@ -16,6 +16,7 @@ import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_14_R1.AxisAlignedBB;
import net.minecraft.server.v1_14_R1.DamageSource;
import net.minecraft.server.v1_14_R1.DragonControllerPhase;
import net.minecraft.server.v1_14_R1.Entity;
import net.minecraft.server.v1_14_R1.EntityBoat;
import net.minecraft.server.v1_14_R1.EntityEnderDragon;
@ -106,7 +107,18 @@ public class EnderDragonController extends MobEntityController {
return npc == null ? super.d(save) : false;
}
@Override
protected boolean dealDamage(DamageSource source, float f) {
if (npc == null)
return super.dealDamage(source, f);
Vec3D old = getMot();
boolean res = super.dealDamage(source, f);
if (getDragonControllerManager().a() == DragonControllerPhase.HOVER) {
setMot(old);
}
return res;
}
@Override
public void f(double x, double y, double z) {
@ -153,6 +165,31 @@ public class EnderDragonController extends MobEntityController {
public void movementTick() {
if (npc != null) {
npc.update();
if (this.d < 0) {
for (int i = 0; i < this.c.length; ++i) {
this.c[i][0] = this.yaw;
this.c[i][1] = this.locY;
}
}
if (++this.d == this.c.length) {
this.d = 0;
}
this.c[this.d][0] = this.yaw;
this.c[this.d][1] = this.locY;
float[][] pos = NMS.calculateDragonPositions(yaw,
new double[][] { a(0, 1F), a(5, 1F), a(10, 1F), a(12, 1F), a(14, 1F), a(16, 1F) });
for (int j = 0; j < children.length; ++j) {
Vec3D vec3 = new Vec3D(this.children[j].locX, this.children[j].locY, this.children[j].locZ);
children[j].setPosition(this.locX + pos[j][0], this.locY + pos[j][1], this.locZ + pos[j][2]);
children[j].lastX = vec3.x;
children[j].lastY = vec3.y;
children[j].lastZ = vec3.z;
}
if (getRidingPassenger() != null) {
yaw = getRidingPassenger().getBukkitYaw() - 180;
}

View File

@ -17,6 +17,7 @@ import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_15_R1.AxisAlignedBB;
import net.minecraft.server.v1_15_R1.DamageSource;
import net.minecraft.server.v1_15_R1.DragonControllerPhase;
import net.minecraft.server.v1_15_R1.Entity;
import net.minecraft.server.v1_15_R1.EntityBoat;
import net.minecraft.server.v1_15_R1.EntityEnderDragon;
@ -99,7 +100,18 @@ public class EnderDragonController extends MobEntityController {
return npc == null ? super.d(save) : false;
}
@Override
protected boolean dealDamage(DamageSource source, float f) {
if (npc == null)
return super.dealDamage(source, f);
Vec3D old = getMot();
boolean res = super.dealDamage(source, f);
if (getDragonControllerManager().a() == DragonControllerPhase.HOVER) {
setMot(old);
}
return res;
}
@Override
public CraftEntity getBukkitEntity() {
@ -149,6 +161,30 @@ public class EnderDragonController extends MobEntityController {
NMSImpl.updateMinecraftAIState(npc, this);
}
if (npc != null && !npc.useMinecraftAI()) {
if (this.d < 0) {
for (int i = 0; i < this.c.length; ++i) {
this.c[i][0] = this.yaw;
this.c[i][1] = this.locY();
}
}
if (++this.d == this.c.length) {
this.d = 0;
}
this.c[this.d][0] = this.yaw;
this.c[this.d][1] = this.locY();
float[][] pos = NMS.calculateDragonPositions(yaw,
new double[][] { a(0, 1F), a(5, 1F), a(10, 1F), a(12, 1F), a(14, 1F), a(16, 1F) });
for (int j = 0; j < children.length; ++j) {
Vec3D vec3 = new Vec3D(this.children[j].locX(), this.children[j].locY(), this.children[j].locZ());
children[j].setPosition(this.locX() + pos[j][0], this.locY() + pos[j][1], this.locZ() + pos[j][2]);
children[j].lastX = children[j].E = vec3.x;
children[j].lastY = children[j].F = vec3.y;
children[j].lastZ = children[j].G = vec3.z;
}
if (getRidingPassenger() != null) {
yaw = getRidingPassenger().getBukkitYaw() - 180;
}

View File

@ -17,6 +17,7 @@ import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_16_R3.AxisAlignedBB;
import net.minecraft.server.v1_16_R3.DamageSource;
import net.minecraft.server.v1_16_R3.DragonControllerPhase;
import net.minecraft.server.v1_16_R3.Entity;
import net.minecraft.server.v1_16_R3.EntityBoat;
import net.minecraft.server.v1_16_R3.EntityEnderDragon;
@ -99,7 +100,18 @@ public class EnderDragonController extends MobEntityController {
return npc == null ? super.d(save) : false;
}
@Override
protected boolean dealDamage(DamageSource source, float f) {
if (npc == null)
return super.dealDamage(source, f);
Vec3D old = getMot();
boolean res = super.dealDamage(source, f);
if (getDragonControllerManager().a() == DragonControllerPhase.HOVER) {
setMot(old);
}
return res;
}
@Override
public CraftEntity getBukkitEntity() {
@ -149,6 +161,30 @@ public class EnderDragonController extends MobEntityController {
NMSImpl.updateMinecraftAIState(npc, this);
}
if (npc != null && !npc.useMinecraftAI()) {
if (this.d < 0) {
for (int i = 0; i < this.c.length; ++i) {
this.c[i][0] = this.yaw;
this.c[i][1] = this.locY();
}
}
if (++this.d == this.c.length) {
this.d = 0;
}
this.c[this.d][0] = this.yaw;
this.c[this.d][1] = this.locY();
float[][] pos = NMS.calculateDragonPositions(yaw,
new double[][] { a(0, 1F), a(5, 1F), a(10, 1F), a(12, 1F), a(14, 1F), a(16, 1F) });
for (int j = 0; j < children.length; ++j) {
Vec3D vec3 = new Vec3D(this.children[j].locX(), this.children[j].locY(), this.children[j].locZ());
children[j].setPosition(this.locX() + pos[j][0], this.locY() + pos[j][1], this.locZ() + pos[j][2]);
children[j].lastX = children[j].D = vec3.x;
children[j].lastY = children[j].E = vec3.y;
children[j].lastZ = children[j].F = vec3.z;
}
if (getRidingPassenger() != null) {
yaw = getRidingPassenger().getBukkitYaw() - 180;
}

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.boss.enderdragon.EnderDragon;
import net.minecraft.world.entity.boss.enderdragon.phases.EnderDragonPhase;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.level.Level;
@ -63,6 +64,32 @@ public class EnderDragonController extends MobEntityController {
NMSImpl.updateMinecraftAIState(npc, this);
}
if (npc != null && !npc.useMinecraftAI()) {
if (this.posPointer < 0) {
for (int i = 0; i < this.positions.length; ++i) {
this.positions[i][0] = this.getYRot();
this.positions[i][1] = this.getY();
}
}
if (++this.posPointer == this.positions.length) {
this.posPointer = 0;
}
this.positions[this.posPointer][0] = this.getYRot();
this.positions[this.posPointer][1] = this.getY();
float[][] pos = NMS.calculateDragonPositions(getYRot(),
new double[][] { getLatencyPos(0, 1F), getLatencyPos(5, 1F), getLatencyPos(10, 1F),
getLatencyPos(12, 1F), getLatencyPos(14, 1F), getLatencyPos(16, 1F) });
for (int j = 0; j < subEntities.length; ++j) {
Vec3 vec3 = new Vec3(this.subEntities[j].getX(), this.subEntities[j].getY(),
this.subEntities[j].getZ());
subEntities[j].setPos(this.getX() + pos[j][0], this.getY() + pos[j][1], this.getZ() + pos[j][2]);
subEntities[j].xo = subEntities[j].xOld = vec3.x;
subEntities[j].yo = subEntities[j].yOld = vec3.y;
subEntities[j].zo = subEntities[j].zOld = vec3.z;
}
if (getFirstPassenger() != null) {
setYRot(getFirstPassenger().getBukkitYaw() - 180);
}
@ -95,8 +122,6 @@ public class EnderDragonController extends MobEntityController {
}
}
@Override
protected SoundEvent getAmbientSound() {
return NMSImpl.getSoundEffect(npc, super.getAmbientSound(), NPC.Metadata.AMBIENT_SOUND);
@ -169,6 +194,19 @@ public class EnderDragonController extends MobEntityController {
Util.callCollisionEvent(npc, entity.getBukkitEntity());
}
@Override
protected boolean reallyHurt(DamageSource source, float f) {
if (npc == null)
return super.reallyHurt(source, f);
Vec3 old = getDeltaMovement();
boolean res = super.reallyHurt(source, f);
if (getPhaseManager().getCurrentPhase() == EnderDragonPhase.HOVERING) {
setDeltaMovement(old);
}
return res;
}
@Override
public boolean save(CompoundTag save) {
return npc == null ? super.save(save) : false;

View File

@ -23,6 +23,7 @@ import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraft.world.entity.boss.enderdragon.phases.EnderDragonPhase;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.level.Level;
@ -65,6 +66,32 @@ public class EnderDragonController extends MobEntityController {
NMSImpl.updateMinecraftAIState(npc, this);
}
if (npc != null && !npc.useMinecraftAI()) {
if (this.posPointer < 0) {
for (int i = 0; i < this.positions.length; ++i) {
this.positions[i][0] = this.getYRot();
this.positions[i][1] = this.getY();
}
}
if (++this.posPointer == this.positions.length) {
this.posPointer = 0;
}
this.positions[this.posPointer][0] = this.getYRot();
this.positions[this.posPointer][1] = this.getY();
float[][] pos = NMS.calculateDragonPositions(getYRot(),
new double[][] { getLatencyPos(0, 1F), getLatencyPos(5, 1F), getLatencyPos(10, 1F),
getLatencyPos(12, 1F), getLatencyPos(14, 1F), getLatencyPos(16, 1F) });
for (int j = 0; j < subEntities.length; ++j) {
Vec3 vec3 = new Vec3(this.subEntities[j].getX(), this.subEntities[j].getY(),
this.subEntities[j].getZ());
subEntities[j].setPos(this.getX() + pos[j][0], this.getY() + pos[j][1], this.getZ() + pos[j][2]);
subEntities[j].xo = subEntities[j].xOld = vec3.x;
subEntities[j].yo = subEntities[j].yOld = vec3.y;
subEntities[j].zo = subEntities[j].zOld = vec3.z;
}
if (getFirstPassenger() != null) {
setYRot(getFirstPassenger().getBukkitYaw() - 180);
}
@ -97,8 +124,6 @@ public class EnderDragonController extends MobEntityController {
}
}
@Override
protected SoundEvent getAmbientSound() {
return NMSImpl.getSoundEffect(npc, super.getAmbientSound(), NPC.Metadata.AMBIENT_SOUND);
@ -171,6 +196,19 @@ public class EnderDragonController extends MobEntityController {
Util.callCollisionEvent(npc, entity.getBukkitEntity());
}
@Override
protected boolean reallyHurt(DamageSource source, float f) {
if (npc == null)
return super.reallyHurt(source, f);
Vec3 old = getDeltaMovement();
boolean res = super.reallyHurt(source, f);
if (getPhaseManager().getCurrentPhase() == EnderDragonPhase.HOVERING) {
setDeltaMovement(old);
}
return res;
}
@Override
public boolean save(CompoundTag save) {
return npc == null ? super.save(save) : false;

View File

@ -23,6 +23,7 @@ import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraft.world.entity.boss.enderdragon.phases.EnderDragonPhase;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.level.Level;
@ -63,20 +64,48 @@ public class EnderDragonController extends MobEntityController {
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
}
if (npc != null && !npc.useMinecraftAI()) {
if (this.posPointer < 0) {
for (int i = 0; i < this.positions.length; ++i) {
this.positions[i][0] = this.getYRot();
this.positions[i][1] = this.getY();
}
}
if (++this.posPointer == this.positions.length) {
this.posPointer = 0;
}
this.positions[this.posPointer][0] = this.getYRot();
this.positions[this.posPointer][1] = this.getY();
float[][] pos = NMS.calculateDragonPositions(getYRot(),
new double[][] { getLatencyPos(0, 1F), getLatencyPos(5, 1F), getLatencyPos(10, 1F),
getLatencyPos(12, 1F), getLatencyPos(14, 1F), getLatencyPos(16, 1F) });
for (int j = 0; j < subEntities.length; ++j) {
Vec3 vec3 = new Vec3(this.subEntities[j].getX(), this.subEntities[j].getY(),
this.subEntities[j].getZ());
subEntities[j].setPos(this.getX() + pos[j][0], this.getY() + pos[j][1], this.getZ() + pos[j][2]);
subEntities[j].xo = subEntities[j].xOld = vec3.x;
subEntities[j].yo = subEntities[j].yOld = vec3.y;
subEntities[j].zo = subEntities[j].zOld = vec3.z;
}
if (getFirstPassenger() != null) {
setYRot(getFirstPassenger().getBukkitYaw() - 180);
}
Vec3 mot = getDeltaMovement();
if (mot.x != 0 || mot.y != 0 || mot.z != 0) {
mot = mot.multiply(0.98, 0.98, 0.98);
mot = mot.multiply(0.98, 0.91, 0.98);
if (getFirstPassenger() == null) {
setYRot(Util.getDragonYaw(getBukkitEntity(), mot.x, mot.z));
}
setPos(getX() + mot.x, getY() + mot.y, getZ() + mot.z);
setDeltaMovement(mot);
}
} else {
super.aiStep();
}
@ -169,6 +198,19 @@ public class EnderDragonController extends MobEntityController {
Util.callCollisionEvent(npc, entity.getBukkitEntity());
}
@Override
protected boolean reallyHurt(DamageSource source, float f) {
if (npc == null)
return super.reallyHurt(source, f);
Vec3 old = getDeltaMovement();
boolean res = super.reallyHurt(source, f);
if (getPhaseManager().getCurrentPhase() == EnderDragonPhase.HOVERING) {
setDeltaMovement(old);
}
return res;
}
@Override
public boolean save(CompoundTag save) {
return npc == null ? super.save(save) : false;

View File

@ -15,9 +15,11 @@ import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_8_R3.AxisAlignedBB;
import net.minecraft.server.v1_8_R3.DamageSource;
import net.minecraft.server.v1_8_R3.Entity;
import net.minecraft.server.v1_8_R3.EntityEnderDragon;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.Vec3D;
import net.minecraft.server.v1_8_R3.World;
public class EnderDragonController extends MobEntityController {
@ -108,6 +110,20 @@ public class EnderDragonController extends MobEntityController {
}
}
@Override
protected boolean dealDamage(DamageSource source, float f) {
if (npc == null)
return super.dealDamage(source, f);
Vec3D old = new Vec3D(motX, motY, motZ);
boolean res = super.dealDamage(source, f);
motX = old.a;
motY = old.b;
motZ = old.c;
return res;
}
@Override
public void g(double x, double y, double z) {
Vector vector = Util.callPushEvent(npc, x, y, z);
@ -132,6 +148,31 @@ public class EnderDragonController extends MobEntityController {
public void m() {
if (npc != null) {
npc.update();
if (this.bl < 0) {
for (int i = 0; i < this.bk.length; ++i) {
this.bk[i][0] = this.yaw;
this.bk[i][1] = this.locY;
}
}
if (++this.bl == this.bk.length) {
this.bl = 0;
}
this.bk[this.bl][0] = this.yaw;
this.bk[this.bl][1] = this.locY;
float[][] pos = NMS.calculateDragonPositions(yaw,
new double[][] { b(0, 1F), b(5, 1F), b(10, 1F), b(12, 1F), b(14, 1F), b(16, 1F) });
for (int j = 0; j < children.length; ++j) {
Vec3D vec3 = new Vec3D(this.children[j].locX, this.children[j].locY, this.children[j].locZ);
children[j].setPosition(this.locX + pos[j][0], this.locY + pos[j][1], this.locZ + pos[j][2]);
children[j].lastX = vec3.a;
children[j].lastY = vec3.b;
children[j].lastZ = vec3.c;
}
if (getBukkitEntity().getPassenger() != null) {
yaw = getBukkitEntity().getPassenger().getLocation().getYaw() - 180;
}