mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 20:49:05 +00:00
knockback() function for ScriptEntity now *only* knocks the entity back instead of hitting it.
Flying NPC's get knocked back properly, and their vertical speed has been increased. Flying NPC's vertical flying speed can be changed by npc.setFlySpeed(double speed) from ScriptNpc.
This commit is contained in:
1 parent
3cd1410c19
commit
12333de3a1
9 files changed
+62
-40
No files matched your search
@@ -35,6 +35,7 @@ public class DataAI {
|
||||
|
||||
// Fly Change
|
||||
public int movementType = 0;
|
||||
public double flySpeed = 1.0D;
|
||||
|
||||
public EnumAnimation animationType = EnumAnimation.NONE;
|
||||
public EnumStandingType standingType = EnumStandingType.RotateBody;
|
||||
@@ -96,8 +97,13 @@ public class DataAI {
|
||||
setMovingPath(NBTTags.getIntegerArraySet(compound.getTagList("MovingPathNew",10)));
|
||||
movingPos = compound.getInteger("MovingPos");
|
||||
movingPattern = compound.getInteger("MovingPatern");
|
||||
|
||||
movementType = compound.getInteger("MovingType");
|
||||
|
||||
if(!compound.hasKey("FlySpeed"))
|
||||
flySpeed = 1.0D;
|
||||
else
|
||||
flySpeed = compound.getDouble("FlySpeed");
|
||||
|
||||
startPos = compound.getIntArray("StartPosNew");
|
||||
if (startPos == null || startPos.length != 3){
|
||||
startPos = new int[] {
|
||||
@@ -143,8 +149,10 @@ public class DataAI {
|
||||
compound.setTag("MovingPathNew", NBTTags.nbtIntegerArraySet(movingPath));
|
||||
compound.setInteger("MovingPos", movingPos);
|
||||
compound.setInteger("MovingPatern", movingPattern);
|
||||
|
||||
compound.setInteger("MovingType", movementType);
|
||||
|
||||
compound.setDouble("FlySpeed",flySpeed);
|
||||
|
||||
npc.setAvoidWater(avoidsWater);
|
||||
|
||||
compound.setIntArray("StartPosNew", npc.getStartPos());
|
||||
|
||||
@@ -10,7 +10,7 @@ public class PathNavigateFlying extends PathNavigateSwimmer {
|
||||
super(p_i45873_1_, worldIn);
|
||||
}
|
||||
|
||||
protected PathFinder func_179679_a()
|
||||
protected PathFinder getPathFinder()
|
||||
{
|
||||
return new NPCPathFinder(new FlyNodeProcessor());
|
||||
}
|
||||
|
||||
@@ -10,12 +10,8 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
|
||||
|
||||
public EntityNPCFlying(World world) {
|
||||
super(world);
|
||||
this.getNavigator().setCanSwim(true);
|
||||
this.tasks.addTask(0, new EntityAISwimming(this));
|
||||
}
|
||||
|
||||
// FLY CHANGE [WIP]
|
||||
|
||||
@Override
|
||||
public boolean canFly(){
|
||||
return ai.movementType == 1;
|
||||
@@ -43,32 +39,36 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
|
||||
double speed = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue();
|
||||
double speedMult = 0.6000000238418579D/0.5D;
|
||||
|
||||
this.motionY *= speed*speedMult;
|
||||
|
||||
if(isEntityAlive()) {
|
||||
if (!this.worldObj.isRemote) {
|
||||
Entity entity = this.getAttackTarget();
|
||||
if (entity != null && entity.isEntityAlive()) {
|
||||
if (this.posY < entity.posY) {
|
||||
if (this.motionY < 0.0D) {
|
||||
this.motionY = 0.0D;
|
||||
}
|
||||
|
||||
this.motionY += (speed - this.motionY) * speed * speedMult;
|
||||
}
|
||||
|
||||
double d0 = entity.posX - this.posX;
|
||||
double d1 = entity.posY - this.posY;
|
||||
double d2 = entity.posZ - this.posZ;
|
||||
double d3 = d0 * d0 + d2 * d2;
|
||||
|
||||
if (d3 > 9.0D) {
|
||||
double d5 = (double) MathHelper.sqrt_double(d3);
|
||||
this.motionX += (d0 / d5 * speed - this.motionX) * speed * speedMult;
|
||||
this.motionZ += (d2 / d5 * speed - this.motionZ) * speed * speedMult;
|
||||
if(this.hurtTime == 0) {
|
||||
if (this.posY != entity.posY) {
|
||||
if (this.motionY * Math.signum(this.posY - entity.posY) > 0.0D) {
|
||||
this.motionY = 0.0D;
|
||||
}
|
||||
|
||||
this.motionY -= Math.signum(this.posY - entity.posY) * (speed * speedMult) * this.ai.flySpeed;
|
||||
}
|
||||
|
||||
if (d3 > 9.0D) {
|
||||
double d5 = MathHelper.sqrt_double(d3);
|
||||
this.motionX += (d0 / d5 * speed - this.motionX) * speed * speedMult;
|
||||
this.motionZ += (d2 / d5 * speed - this.motionZ) * speed * speedMult;
|
||||
}
|
||||
}
|
||||
|
||||
this.rotationYaw = (float) ((Math.atan2(-d0, -d2) + Math.PI) * -(180F / Math.PI));
|
||||
} else {
|
||||
if (!this.onGround && this.motionY < 0.0D)
|
||||
{
|
||||
this.motionY *= 0.6D;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBow;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.pathfinding.PathNavigate;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
@@ -59,6 +60,8 @@ import noppes.npcs.ai.EntityAIMoveIndoors;
|
||||
import noppes.npcs.ai.EntityAIPanic;
|
||||
import noppes.npcs.ai.EntityAIWander;
|
||||
import noppes.npcs.ai.EntityAIWatchClosest;
|
||||
import noppes.npcs.ai.pathfinder.PathNavigateFlying;
|
||||
import noppes.npcs.ai.pathfinder.PathNavigateGround;
|
||||
import noppes.npcs.ai.selector.NPCAttackSelector;
|
||||
import noppes.npcs.ai.target.EntityAIClearTarget;
|
||||
import noppes.npcs.ai.target.EntityAIClosestTarget;
|
||||
@@ -153,8 +156,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
public boolean updateAI = false;
|
||||
|
||||
// Fly Change
|
||||
// public EntityMoveHelper moveHelper;
|
||||
// public PathNavigate navigator;
|
||||
//public EntityMoveHelper moveHelper;
|
||||
public PathNavigate navigator;
|
||||
|
||||
public EntityNPCInterface(World world) {
|
||||
super(world);
|
||||
@@ -597,17 +600,15 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
this.targetTasks.addTask(3, new EntityAIOwnerHurtByTarget(this));
|
||||
this.targetTasks.addTask(4, new EntityAIOwnerHurtTarget(this));
|
||||
|
||||
this.tasks.addTask(0, new EntityAIWaterNav(this));
|
||||
|
||||
if(canFly()){
|
||||
//this.moveHelper = new FlyingMoveHelper(this);
|
||||
//this.navigator = new PathNavigateFlying(this, worldObj);
|
||||
this.navigator = new PathNavigateFlying(this, worldObj);
|
||||
this.getNavigator().setCanSwim(true);
|
||||
this.tasks.addTask(0, new EntityAISwimming(this));
|
||||
}
|
||||
else{
|
||||
//this.moveHelper = new EntityMoveHelper(this);
|
||||
//this.navigator = new PathNavigateGround(this, worldObj);
|
||||
this.navigator = new PathNavigateGround(this, worldObj);
|
||||
this.tasks.addTask(0, new EntityAIWaterNav(this));
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ public class ScriptEntityParticle {
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
public void setHEXcolor(int HEXcolor) {
|
||||
public void setHEXColor(int HEXcolor) {
|
||||
this.HEXcolor = HEXcolor;
|
||||
}
|
||||
|
||||
|
||||
@@ -457,20 +457,17 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
* @param power How strong the knockback is
|
||||
* @param direction The direction in which he flies back (0-360). Usually based on getRotation()
|
||||
*/
|
||||
@Override
|
||||
public void knockback(int power, float direction){
|
||||
float v = direction * (float)Math.PI / 180.0F;
|
||||
entity.velocityChanged = true;
|
||||
entity.addVelocity(-MathHelper.sin(v) * (float)power, 0.1D + power * 0.04f, MathHelper.cos(v) * (float)power);
|
||||
entity.motionX *= 0.6D;
|
||||
entity.motionZ *= 0.6D;
|
||||
entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F);
|
||||
entity.hurtResistantTime = 0;
|
||||
}
|
||||
|
||||
public void knockback(int xpower, int ypower, int zpower, float direction){
|
||||
float v = direction * (float)Math.PI / 180.0F;
|
||||
entity.velocityChanged = true;
|
||||
entity.addVelocity(-MathHelper.sin(v) * (float)xpower, 0.1D + ypower * 0.04f, MathHelper.cos(v) * (float)zpower);
|
||||
entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F);
|
||||
entity.hurtResistantTime = 0;
|
||||
}
|
||||
|
||||
public void setImmune(int ticks) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EntityDamageSource;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.scripted.ScriptItemStack;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
|
||||
@@ -923,10 +923,6 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
return ((EntityNPCInterface)this.npc).timers;
|
||||
}
|
||||
|
||||
public boolean canFly(){
|
||||
return npc.ai.movementType == 1;
|
||||
}
|
||||
|
||||
public void setFly(int fly){
|
||||
if(fly > 0)
|
||||
fly = 1;
|
||||
@@ -935,6 +931,21 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
npc.ai.movementType = fly;
|
||||
}
|
||||
|
||||
public boolean canFly(){
|
||||
return npc.ai.movementType == 1;
|
||||
}
|
||||
|
||||
public void setFlySpeed(double flySpeed){
|
||||
if(flySpeed < 0.0D)
|
||||
flySpeed = 0.0D;
|
||||
|
||||
npc.ai.flySpeed = flySpeed;
|
||||
}
|
||||
|
||||
public double getFlySpeed(double flySpeed){
|
||||
return npc.ai.flySpeed;
|
||||
}
|
||||
|
||||
public void setSkinType(byte type) {
|
||||
npc.display.skinType = type;
|
||||
npc.updateClient = true;
|
||||
|
||||
@@ -676,9 +676,13 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
|
||||
|
||||
public long getAge();
|
||||
|
||||
public void setFly(int fly);
|
||||
|
||||
public boolean canFly();
|
||||
|
||||
public void setFly(int fly);
|
||||
public void setFlySpeed(double flySpeed);
|
||||
|
||||
public double getFlySpeed(double flySpeed);
|
||||
|
||||
public void setSkinType(byte type);
|
||||
|
||||
|
||||
Reference in new issue
Block a user