use of net.minecraft.util.MovingObjectPosition in project MineFactoryReloaded by powercrystals.
the class ItemSpyglass method rayTrace.
private MovingObjectPosition rayTrace() {
if (Minecraft.getMinecraft().renderViewEntity == null || Minecraft.getMinecraft().theWorld == null) {
return null;
}
double range = MFRConfig.spyglassRange.getInt();
MovingObjectPosition objHit = Minecraft.getMinecraft().renderViewEntity.rayTrace(range, 1.0F);
double blockDist = range;
Vec3 playerPos = Minecraft.getMinecraft().renderViewEntity.getPosition(1.0F);
if (objHit != null) {
blockDist = objHit.hitVec.distanceTo(playerPos);
}
Vec3 playerLook = Minecraft.getMinecraft().renderViewEntity.getLook(1.0F);
Vec3 playerLookRel = playerPos.addVector(playerLook.xCoord * range, playerLook.yCoord * range, playerLook.zCoord * range);
List<?> list = Minecraft.getMinecraft().theWorld.getEntitiesWithinAABBExcludingEntity(Minecraft.getMinecraft().renderViewEntity, Minecraft.getMinecraft().renderViewEntity.boundingBox.addCoord(playerLook.xCoord * range, playerLook.yCoord * range, playerLook.zCoord * range).expand(1, 1, 1));
double entityDistTotal = blockDist;
Entity pointedEntity = null;
for (int i = 0; i < list.size(); ++i) {
Entity entity = (Entity) list.get(i);
if (entity.canBeCollidedWith()) {
double entitySize = entity.getCollisionBorderSize();
AxisAlignedBB axisalignedbb = entity.boundingBox.expand(entitySize, entitySize, entitySize);
MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(playerPos, playerLookRel);
if (axisalignedbb.isVecInside(playerPos)) {
if (0.0D < entityDistTotal || entityDistTotal == 0.0D) {
pointedEntity = entity;
entityDistTotal = 0.0D;
}
} else if (movingobjectposition != null) {
double entityDist = playerPos.distanceTo(movingobjectposition.hitVec);
if (entityDist < entityDistTotal || entityDistTotal == 0.0D) {
pointedEntity = entity;
entityDistTotal = entityDist;
}
}
}
}
if (pointedEntity != null && (entityDistTotal < blockDist || objHit == null)) {
objHit = new MovingObjectPosition(pointedEntity);
}
return objHit;
}
use of net.minecraft.util.MovingObjectPosition in project ArsMagica2 by Mithion.
the class TileEntityBlackAurem method updateEntity.
@Override
public void updateEntity() {
if (worldObj.isRemote) {
this.rotation += this.rotationIncrement;
} else {
surroundingCheckTicks++;
}
if (worldObj.isRemote || ticksSinceLastEntityScan++ > 25) {
updateNearbyEntities();
ticksSinceLastEntityScan = 0;
}
Iterator<EntityLivingBase> it = cachedEntities.iterator();
while (it.hasNext()) {
EntityLivingBase ent = it.next();
if (ent.isDead) {
it.remove();
continue;
}
MovingObjectPosition mop = this.worldObj.rayTraceBlocks(Vec3.createVectorHelper(xCoord + 0.5, yCoord + 1.5, zCoord + 0.5), Vec3.createVectorHelper(ent.posX, ent.posY + ent.getEyeHeight(), ent.posZ), false);
if (EntityUtilities.isSummon(ent) || mop != null) {
continue;
}
ent.motionY = 0;
ent.motionX = 0;
ent.motionZ = 0;
double deltaX = this.xCoord + 0.5f - ent.posX;
double deltaZ = this.zCoord + 0.5f - ent.posZ;
double deltaY = this.yCoord - ent.posY;
double angle = Math.atan2(deltaZ, deltaX);
double offsetX = Math.cos(angle) * 0.1;
double offsetZ = Math.sin(angle) * 0.1;
double offsetY = 0.05f;
double distanceHorizontal = deltaX * deltaX + deltaZ * deltaZ;
double distanceVertical = this.yCoord - ent.posY;
boolean spawnedParticles = false;
if (distanceHorizontal < 1.3) {
if (distanceVertical < -1.5) {
if (worldObj.isRemote && worldObj.rand.nextInt(10) < 3) {
AMCore.proxy.particleManager.BoltFromPointToPoint(worldObj, xCoord + 0.5, yCoord + 1.3, zCoord + 0.5, ent.posX, ent.posY, ent.posZ, 4, 0x000000);
}
}
if (distanceVertical < -2) {
offsetY = 0;
if (!worldObj.isRemote) {
if (ent.attackEntityFrom(DamageSources.darkNexus, 4)) {
if (ent.getHealth() <= 0) {
ent.setDead();
float power = ((int) Math.ceil((ent.getMaxHealth() * (ent.ticksExisted / 20)) % 5000)) * this.powerMultiplier;
PowerNodeRegistry.For(this.worldObj).insertPower(this, PowerTypes.DARK, power);
}
}
}
}
}
if (worldObj.isRemote) {
if (!arcs.containsKey(ent)) {
AMLineArc arc = (AMLineArc) AMCore.proxy.particleManager.spawn(worldObj, "textures/blocks/oreblocksunstone.png", xCoord + 0.5, yCoord + 1.3, zCoord + 0.5, ent);
if (arc != null) {
arc.setExtendToTarget();
arc.setRBGColorF(1, 1, 1);
}
arcs.put(ent, arc);
}
Iterator arcIterator = arcs.keySet().iterator();
ArrayList<Entity> toRemove = new ArrayList<Entity>();
while (arcIterator.hasNext()) {
Entity arcEnt = (Entity) arcIterator.next();
AMLineArc arc = (AMLineArc) arcs.get(arcEnt);
if (arcEnt == null || arcEnt.isDead || arc == null || arc.isDead || new AMVector3(ent).distanceSqTo(new AMVector3(xCoord, yCoord, zCoord)) > 100)
toRemove.add(arcEnt);
}
for (Entity e : toRemove) {
arcs.remove(e);
}
}
if (!worldObj.isRemote)
ent.moveEntity(offsetX, offsetY, offsetZ);
}
if (surroundingCheckTicks % 100 == 0) {
checkNearbyBlockState();
surroundingCheckTicks = 1;
if (!worldObj.isRemote && PowerNodeRegistry.For(this.worldObj).checkPower(this, this.capacity * 0.1f)) {
List<EntityPlayer> nearbyPlayers = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(this.xCoord - 2, this.yCoord, this.zCoord - 2, this.xCoord + 2, this.yCoord + 3, this.zCoord + 2));
for (EntityPlayer p : nearbyPlayers) {
if (p.isPotionActive(BuffList.manaRegen.id))
continue;
p.addPotionEffect(new BuffEffectManaRegen(600, 3));
}
}
//TODO:
/*if (rand.nextDouble() < (this.getCharge() / this.getCapacity()) * 0.01){
int maxSev = (int)Math.ceil((this.getCharge() / this.getCapacity()) * 2) + rand.nextInt(2);
IllEffectsManager.instance.ApplyRandomBadThing(this, IllEffectSeverity.values()[maxSev], BadThingTypes.DARKNEXUS);
}*/
}
super.callSuperUpdate();
}
use of net.minecraft.util.MovingObjectPosition in project ArsMagica2 by Mithion.
the class ItemMagicBroom method onItemUseFirst.
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(world, player, true);
if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) {
TileEntity te = world.getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
if (te instanceof IInventory) {
EntityBroom broom = new EntityBroom(world);
broom.setPosition(player.posX, player.posY, player.posZ);
broom.setChestLocation(new AMVector3(mop.blockX, mop.blockY, mop.blockZ));
world.spawnEntityInWorld(broom);
stack.stackSize--;
if (stack.stackSize == 0) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
return true;
}
}
}
return false;
}
use of net.minecraft.util.MovingObjectPosition in project ArsMagica2 by Mithion.
the class Attract 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);
}
}
EntityLivingBase target = getClosestEntityToPointWithin(caster, world, new AMVector3(impactX, impactY, impactZ), 16);
if (target == null)
return false;
int hDist = 3;
AMVector3 movement = MathUtilities.GetMovementVectorBetweenPoints(new AMVector3(target), new AMVector3(impactX, impactY, impactZ));
if (!world.isRemote) {
float factor = 0.75f;
double x = -(movement.x * factor);
double y = -(movement.y * factor);
double z = -(movement.z * factor);
target.addVelocity(x, y, z);
if (Math.abs(target.motionX) > Math.abs(x * 2)) {
target.motionX = x * (target.motionX / target.motionX);
}
if (Math.abs(target.motionY) > Math.abs(y * 2)) {
target.motionY = y * (target.motionY / target.motionY);
}
if (Math.abs(target.motionZ) > Math.abs(z * 2)) {
target.motionZ = z * (target.motionZ / target.motionZ);
}
}
return true;
}
use of net.minecraft.util.MovingObjectPosition in project ArsMagica2 by Mithion.
the class Chain 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) {
MovingObjectPosition mop = item.getMovingObjectPosition(caster, world, 8.0f, true, false);
double range = SpellUtils.instance.getModifiedDouble_Mul(4, stack, caster, target, world, 0, SpellModifiers.RANGE);
int num_targets = SpellUtils.instance.getModifiedInt_Add(3, stack, caster, target, world, 0, SpellModifiers.PROCS);
ArrayList<EntityLivingBase> targets = new ArrayList<EntityLivingBase>();
if (target != null) {
mop = new MovingObjectPosition(target);
}
if (mop != null && mop.typeOfHit == MovingObjectType.ENTITY && mop.entityHit != null) {
Entity e = mop.entityHit;
if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
if (e instanceof EntityLivingBase) {
do {
targets.add((EntityLivingBase) e);
List<EntityLivingBase> nearby = world.getEntitiesWithinAABB(EntityLivingBase.class, e.boundingBox.expand(range, range, range));
EntityLivingBase closest = null;
for (EntityLivingBase near : nearby) {
if (targets.contains(near) || near == caster)
continue;
if (closest == null || closest.getDistanceSqToEntity(e) > near.getDistanceSqToEntity(e)) {
closest = near;
}
}
e = closest;
} while (e != null && targets.size() < num_targets);
}
}
ItemStack newItemStack = SpellUtils.instance.popStackStage(stack);
boolean atLeastOneApplication = false;
SpellCastResult result = SpellCastResult.SUCCESS;
EntityLivingBase prevEntity = null;
for (EntityLivingBase e : targets) {
if (e == caster)
continue;
result = SpellHelper.instance.applyStageToEntity(stack, caster, world, e, 0, giveXP);
SpellHelper.instance.applyStackStage(newItemStack, caster, e, e.posX, e.posY, e.posZ, 0, world, true, giveXP, 0);
if (world.isRemote) {
if (prevEntity == null)
spawnChainParticles(world, x, y, z, e.posX, e.posY + e.getEyeHeight(), e.posZ, stack);
else
spawnChainParticles(world, prevEntity.posX, prevEntity.posY + e.getEyeHeight(), prevEntity.posZ, e.posX, e.posY + e.getEyeHeight(), e.posZ, stack);
}
prevEntity = e;
if (result == SpellCastResult.SUCCESS) {
atLeastOneApplication = true;
}
}
if (atLeastOneApplication) {
return SpellCastResult.SUCCESS;
}
return result;
}
Aggregations