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:
luisc committed 2021-12-06 00:10:10 -06:00
1 parent 3cd1410c19
commit 12333de3a1
9 files changed
+62 -40

No files matched your search

@@ -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);