Added Morgul Blast Projectile
parent
c90bf6cf46
commit
9d6799bc4f
@ -0,0 +1,100 @@
|
|||||||
|
package com.zivilon.cinder_loe.projectiles;
|
||||||
|
|
||||||
|
import lotr.common.LOTRMod;
|
||||||
|
import lotr.common.entity.npc.LOTREntityNPC;
|
||||||
|
import lotr.common.entity.projectile.LOTREntityMallornLeafBomb;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.entity.projectile.EntityThrowable;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.util.DamageSource;
|
||||||
|
import net.minecraft.util.MathHelper;
|
||||||
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
|
import net.minecraft.util.Vec3;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class MorgulBlast extends LOTREntityMallornLeafBomb {
|
||||||
|
private UUID throwerUUID;
|
||||||
|
private int leavesAge;
|
||||||
|
private static int MAX_LEAVES_AGE = 200;
|
||||||
|
public float leavesDamage = 10;
|
||||||
|
|
||||||
|
|
||||||
|
public MorgulBlast(World world) {
|
||||||
|
super(world);
|
||||||
|
this.setSize(2.0f, 2.0f);
|
||||||
|
this.setPosition(this.posX, this.posY, this.posZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void explode(Entity target) {
|
||||||
|
if (!this.worldObj.isRemote) {
|
||||||
|
double range = 2.0;
|
||||||
|
List entities = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, this.boundingBox.expand(range, range, range));
|
||||||
|
if (!entities.isEmpty()) {
|
||||||
|
for (int i = 0; i < entities.size(); ++i) {
|
||||||
|
float damage;
|
||||||
|
EntityLivingBase entity = (EntityLivingBase)entities.get(i);
|
||||||
|
if (!this.isEntityVulnerable((Entity)entity) || !((damage = this.leavesDamage / Math.max(1.0f, this.getDistanceToEntity((Entity)entity))) > 0.0f)) continue;
|
||||||
|
entity.attackEntityFrom(DamageSource.causeMobDamage((EntityLivingBase)this.getThrower()), damage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setDead();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private boolean isEntityVulnerable(Entity target) {
|
||||||
|
if (target == this.getThrower()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (target instanceof EntityLivingBase) {
|
||||||
|
EntityLivingBase livingTarget = (EntityLivingBase)target;
|
||||||
|
EntityLivingBase thrower = this.getThrower();
|
||||||
|
if (thrower instanceof LOTREntityNPC) {
|
||||||
|
((LOTREntityNPC)thrower).getJumpHelper().doJump();
|
||||||
|
return LOTRMod.canNPCAttackEntity((LOTREntityNPC)thrower, livingTarget, false);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpdate() {
|
||||||
|
super.onUpdate();
|
||||||
|
if (!this.worldObj.isRemote) {
|
||||||
|
++this.leavesAge;
|
||||||
|
if (this.leavesAge >= MAX_LEAVES_AGE) {
|
||||||
|
this.explode(null);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Vec3 axis = Vec3.createVectorHelper((double)(-this.motionX), (double)(-this.motionY), (double)(-this.motionZ));
|
||||||
|
int leaves = 20;
|
||||||
|
for (int l = 0; l < leaves; ++l) {
|
||||||
|
float angle = (float)l / (float)leaves * 2.0f * (float)Math.PI;
|
||||||
|
Vec3 rotate = Vec3.createVectorHelper((double)1.0, (double)1.0, (double)1.0);
|
||||||
|
rotate.rotateAroundX((float)Math.toRadians(40.0));
|
||||||
|
rotate.rotateAroundY(angle);
|
||||||
|
float dot = (float)rotate.dotProduct(axis);
|
||||||
|
Vec3 parallel = Vec3.createVectorHelper((double)(axis.xCoord * (double)dot), (double)(axis.yCoord * (double)dot), (double)(axis.zCoord * (double)dot));
|
||||||
|
Vec3 perp = parallel.subtract(rotate);
|
||||||
|
Vec3 cross = rotate.crossProduct(axis);
|
||||||
|
float sin = MathHelper.sin((float)(-angle));
|
||||||
|
float cos = MathHelper.cos((float)(-angle));
|
||||||
|
Vec3 crossSin = Vec3.createVectorHelper((double)(cross.xCoord * (double)sin), (double)(cross.yCoord * (double)sin), (double)(cross.zCoord * (double)sin));
|
||||||
|
Vec3 perpCos = Vec3.createVectorHelper((double)(perp.xCoord * (double)cos), (double)(perp.yCoord * (double)cos), (double)(perp.zCoord * (double)cos));
|
||||||
|
Vec3 result = parallel.addVector(crossSin.xCoord + perpCos.xCoord, crossSin.yCoord + perpCos.yCoord, crossSin.zCoord + perpCos.zCoord);
|
||||||
|
double d = this.posX;
|
||||||
|
double d1 = this.posY;
|
||||||
|
double d2 = this.posZ;
|
||||||
|
double d3 = result.xCoord / 10.0;
|
||||||
|
double d4 = result.yCoord / 10.0;
|
||||||
|
double d5 = result.zCoord / 10.0;
|
||||||
|
LOTRMod.proxy.spawnParticle("morgulPortal", d, d1, d2, d3, d4, d5);
|
||||||
|
LOTRMod.proxy.spawnParticle("smoke", d, d1, d2, d3 * 0.5, d4 * 0.5, d5 * 0.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue