use of net.minecraft.util.MovingObjectPosition in project ArsMagica2 by Mithion.
the class Telekinesis method doTK_Extrapolated.
private boolean doTK_Extrapolated(ItemStack stack, World world, double impactX, double impactY, double impactZ, EntityLivingBase caster) {
if (caster instanceof EntityPlayer) {
double range = ExtendedProperties.For(caster).TK_Distance;
MovingObjectPosition mop = ItemsCommonProxy.spell.getMovingObjectPosition(caster, world, range, false, false);
if (mop == null) {
impactX = caster.posX + (Math.cos(Math.toRadians(caster.rotationYaw + 90)) * range);
impactZ = caster.posZ + (Math.sin(Math.toRadians(caster.rotationYaw + 90)) * range);
impactY = caster.posY + caster.getEyeHeight() + (-Math.sin(Math.toRadians(caster.rotationPitch)) * range);
}
}
double distance = 16;
int hDist = 3;
List<Entity> entities = world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(impactX - distance, impactY - hDist, impactZ - distance, impactX + distance, impactY + hDist, impactZ + distance));
entities.addAll(world.getEntitiesWithinAABB(EntityXPOrb.class, AxisAlignedBB.getBoundingBox(impactX - distance, impactY - hDist, impactZ - distance, impactX + distance, impactY + hDist, impactZ + distance)));
for (Entity e : entities) {
if (e.ticksExisted < 20) {
continue;
}
AMVector3 movement = MathUtilities.GetMovementVectorBetweenPoints(new AMVector3(e), new AMVector3(impactX, impactY, impactZ));
if (!world.isRemote) {
float factor = 0.15f;
if (movement.y > 0)
movement.y = 0;
double x = -(movement.x * factor);
double y = -(movement.y * factor);
double z = -(movement.z * factor);
e.addVelocity(x, y, z);
if (Math.abs(e.motionX) > Math.abs(x * 2)) {
e.motionX = x * (e.motionX / e.motionX);
}
if (Math.abs(e.motionY) > Math.abs(y * 2)) {
e.motionY = y * (e.motionY / e.motionY);
}
if (Math.abs(e.motionZ) > Math.abs(z * 2)) {
e.motionZ = z * (e.motionZ / e.motionZ);
}
}
}
return true;
}
use of net.minecraft.util.MovingObjectPosition in project ArsMagica2 by Mithion.
the class Telekinesis method spawnParticles.
@Override
public void spawnParticles(World world, double x, double y, double z, EntityLivingBase caster, Entity target, Random rand, int colorModifier) {
if (caster instanceof EntityPlayer) {
double range = ExtendedProperties.For(caster).TK_Distance;
MovingObjectPosition mop = ItemsCommonProxy.spell.getMovingObjectPosition(caster, world, range, false, false);
if (mop == null) {
x = caster.posX + (Math.cos(Math.toRadians(caster.rotationYaw + 90)) * range);
z = caster.posZ + (Math.sin(Math.toRadians(caster.rotationYaw + 90)) * range);
y = caster.posY + (-Math.sin(Math.toRadians(caster.rotationPitch)) * range);
}
}
AMParticle effect = (AMParticle) AMCore.instance.proxy.particleManager.spawn(world, "arcane", x - 0.5 + rand.nextDouble(), y - 0.5 + rand.nextDouble(), z - 0.5 + rand.nextDouble());
if (effect != null) {
effect.AddParticleController(new ParticleApproachPoint(effect, x, y, z, 0.025f, 0.025f, 1, false));
effect.setRGBColorF(0.8f, 0.3f, 0.7f);
if (colorModifier > -1) {
effect.setRGBColorF(((colorModifier >> 16) & 0xFF) / 255.0f, ((colorModifier >> 8) & 0xFF) / 255.0f, (colorModifier & 0xFF) / 255.0f);
}
}
}
use of net.minecraft.util.MovingObjectPosition in project ArsMagica2 by Mithion.
the class Touch method beginStackStage.
@Override
public SpellCastResult beginStackStage(ItemSpellBase item, ItemStack stack, EntityLivingBase caster, EntityLivingBase target, World world, double x, double y, double z, int side, boolean giveXP, int useCount) {
if (target != null) {
Entity e = target;
if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
SpellCastResult result = SpellHelper.instance.applyStageToEntity(stack, caster, world, e, 0, giveXP);
return result;
}
boolean targetWater = SpellUtils.instance.modifierIsPresent(SpellModifiers.TARGET_NONSOLID_BLOCKS, stack, 0);
MovingObjectPosition mop = item.getMovingObjectPosition(caster, world, 2.5f, true, targetWater);
if (mop == null) {
return SpellCastResult.EFFECT_FAILED;
} else {
if (mop.typeOfHit == MovingObjectType.ENTITY) {
Entity e = mop.entityHit;
if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
SpellCastResult result = SpellHelper.instance.applyStageToEntity(stack, caster, world, (target == null) ? e : target, 0, giveXP);
if (result != SpellCastResult.SUCCESS) {
return result;
}
ItemStack newItemStack = SpellUtils.instance.popStackStage(stack);
return SpellHelper.instance.applyStackStage(newItemStack, caster, target, mop.hitVec.xCoord, mop.hitVec.yCoord, mop.hitVec.zCoord, 0, world, true, giveXP, 0);
} else {
SpellCastResult result = SpellHelper.instance.applyStageToGround(stack, caster, world, mop.blockX, mop.blockY, mop.blockZ, mop.sideHit, mop.hitVec.xCoord, mop.hitVec.yCoord, mop.hitVec.zCoord, 0, giveXP);
if (result != SpellCastResult.SUCCESS) {
return result;
}
ItemStack newItemStack = SpellUtils.instance.popStackStage(stack);
return SpellHelper.instance.applyStackStage(newItemStack, caster, target, mop.blockX, mop.blockY, mop.blockZ, mop.sideHit, world, true, giveXP, 0);
}
}
}
use of net.minecraft.util.MovingObjectPosition in project ArsMagica2 by Mithion.
the class EntityManaVortex method onUpdate.
@Override
public void onUpdate() {
this.ticksExisted++;
this.rotation += 5;
if (!this.worldObj.isRemote && (this.isDead || this.ticksExisted >= getTicksToExist())) {
this.setDead();
return;
}
if (this.getTicksToExist() - this.ticksExisted <= 20) {
this.scale -= 1f / 20f;
} else if (this.scale < 0.99f) {
this.scale = (float) (Math.sin((float) this.ticksExisted / 50));
}
if (getTicksToExist() - this.ticksExisted <= 5 && !hasGoneBoom) {
hasGoneBoom = true;
if (!worldObj.isRemote) {
List players = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, this.boundingBox.expand(3 + Math.floor(this.ticksExisted / 50), 2, 3 + Math.floor(this.ticksExisted / 50)));
float damage = this.dataWatcher.getWatchableObjectFloat(DW_MANA_STOLEN) * 0.005f;
if (damage > 100)
damage = 100;
Object[] playerArray = players.toArray();
for (Object o : playerArray) {
EntityLivingBase e = (EntityLivingBase) o;
MovingObjectPosition mop = this.worldObj.rayTraceBlocks(Vec3.createVectorHelper(this.posX, this.posY, this.posZ), Vec3.createVectorHelper(e.posX, e.posY + e.getEyeHeight(), e.posZ), false);
if (mop == null)
e.attackEntityFrom(DamageSources.causeEntityPhysicalDamage(this), damage);
}
} else {
for (int i = 0; i < 360; i += AMCore.config.FullGFX() ? 5 : AMCore.config.LowGFX() ? 10 : 20) {
AMParticle effect = (AMParticle) AMCore.instance.proxy.particleManager.spawn(worldObj, "ember", this.posX, this.posY, this.posZ);
if (effect != null) {
effect.setIgnoreMaxAge(true);
effect.AddParticleController(new ParticleMoveOnHeading(effect, i, 0, 0.7f, 1, false));
effect.setRGBColorF(0.24f, 0.24f, 0.8f);
effect.noClip = false;
effect.AddParticleController(new ParticleFadeOut(effect, 1, false).setFadeSpeed(0.05f).setKillParticleOnFinish(true));
effect.AddParticleController(new ParticleLeaveParticleTrail(effect, "ember", false, 5, 1, false).addControllerToParticleList(new ParticleMoveOnHeading(effect, i, 0, 0.1f, 1, false)).addControllerToParticleList(new ParticleFadeOut(effect, 1, false).setFadeSpeed(0.1f).setKillParticleOnFinish(true)).setParticleRGB_F(0.24f, 0.24f, 0.8f).addRandomOffset(0.2f, 0.2f, 0.2f));
}
}
}
}
if (getTicksToExist() - this.ticksExisted > 30) {
//get all players within 5 blocks
List<EntityLivingBase> players = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, this.boundingBox.expand(3 + Math.floor(this.ticksExisted / 50), 2, 3 + Math.floor(this.ticksExisted / 50)));
Object[] playerArray = players.toArray();
Vec3 thisPos = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
for (Object o : playerArray) {
EntityLivingBase e = (EntityLivingBase) o;
MovingObjectPosition mop = this.worldObj.rayTraceBlocks(Vec3.createVectorHelper(this.posX, this.posY, this.posZ), Vec3.createVectorHelper(e.posX, e.posY + e.getEyeHeight(), e.posZ), false);
if (mop != null)
continue;
Vec3 playerPos = Vec3.createVectorHelper(e.posX, e.posY + e.getEyeHeight(), e.posZ);
if (worldObj.isRemote) {
if (AMCore.config.NoGFX()) {
break;
}
if (AMCore.config.LowGFX() && (this.ticksExisted % 4) != 0) {
break;
}
AMParticle effect = (AMParticle) AMCore.instance.proxy.particleManager.spawn(worldObj, "ember", e.posX, e.posY + (e.getEyeHeight() / 2), e.posZ);
if (effect != null) {
effect.AddParticleController(new ParticleArcToEntity(effect, 1, this, false).generateControlPoints().setKillParticleOnFinish(true));
effect.setRGBColorF(0.24f, 0.24f, 0.8f);
effect.setIgnoreMaxAge(true);
}
}
float manaStolen = ExtendedProperties.For(e).getMaxMana() * 0.01f;
float curMana = ExtendedProperties.For(e).getCurrentMana();
if (manaStolen > curMana)
manaStolen = curMana;
this.dataWatcher.updateObject(DW_MANA_STOLEN, this.dataWatcher.getWatchableObjectFloat(DW_MANA_STOLEN) + manaStolen);
ExtendedProperties.For(e).setCurrentMana(ExtendedProperties.For(e).getCurrentMana() - manaStolen);
AMVector3 movement = MathUtilities.GetMovementVectorBetweenEntities(e, this);
float speed = -0.075f;
e.addVelocity(movement.x * speed, movement.y * speed, movement.z * speed);
}
}
}
use of net.minecraft.util.MovingObjectPosition in project ArsMagica2 by Mithion.
the class MathUtilities method getPointedEntity.
public static Entity getPointedEntity(World world, EntityLivingBase entityplayer, double range, double collideRadius, boolean nonCollide) {
Entity pointedEntity = null;
double d = range;
Vec3 vec3d = Vec3.createVectorHelper(entityplayer.posX, entityplayer.posY + entityplayer.getEyeHeight(), entityplayer.posZ);
Vec3 vec3d1 = entityplayer.getLookVec();
Vec3 vec3d2 = vec3d.addVector(vec3d1.xCoord * d, vec3d1.yCoord * d, vec3d1.zCoord * d);
double f1 = collideRadius;
List list = world.getEntitiesWithinAABBExcludingEntity(entityplayer, entityplayer.boundingBox.addCoord(vec3d1.xCoord * d, vec3d1.yCoord * d, vec3d1.zCoord * d).expand(f1, f1, f1));
double d2 = 0.0D;
for (int i = 0; i < list.size(); i++) {
Entity entity = (Entity) list.get(i);
MovingObjectPosition mop = world.rayTraceBlocks(Vec3.createVectorHelper(entityplayer.posX, entityplayer.posY + entityplayer.getEyeHeight(), entityplayer.posZ), Vec3.createVectorHelper(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ), false);
if (((entity.canBeCollidedWith()) || (nonCollide)) && mop == null) {
float f2 = Math.max(0.8F, entity.getCollisionBorderSize());
AxisAlignedBB axisalignedbb = entity.boundingBox.expand(f2, f2, f2);
MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3d, vec3d2);
if (axisalignedbb.isVecInside(vec3d)) {
if ((0.0D < d2) || (d2 == 0.0D)) {
pointedEntity = entity;
d2 = 0.0D;
}
} else if (movingobjectposition != null) {
double d3 = vec3d.distanceTo(movingobjectposition.hitVec);
if ((d3 < d2) || (d2 == 0.0D)) {
pointedEntity = entity;
d2 = d3;
}
}
}
}
return pointedEntity;
}
Aggregations