use of net.minecraft.util.MovingObjectPosition in project MineFactoryReloaded by powercrystals.
the class MineFactoryReloadedClient method rayTrace.
private Entity rayTrace() {
if (Minecraft.getMinecraft().renderViewEntity == null || Minecraft.getMinecraft().theWorld == null) {
return null;
}
double range = 64;
Vec3 playerPos = Minecraft.getMinecraft().renderViewEntity.getPosition(1.0F);
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 = range;
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) {
return pointedEntity;
}
return null;
}
use of net.minecraft.util.MovingObjectPosition in project MineFactoryReloaded by powercrystals.
the class EntityNeedle method onUpdate.
@Override
public void onUpdate() {
super.onUpdate();
if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
this.prevRotationPitch = this.rotationPitch = (float) (Math.atan2(this.motionY, f) * 180.0D / Math.PI);
}
++this.ticksInAir;
Vec3 pos = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX, this.posY, this.posZ);
Vec3 nextPos = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
MovingObjectPosition hit = this.worldObj.rayTraceBlocks_do_do(pos, nextPos, false, true);
pos = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX, this.posY, this.posZ);
nextPos = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
if (hit != null) {
nextPos = this.worldObj.getWorldVec3Pool().getVecFromPool(hit.hitVec.xCoord, hit.hitVec.yCoord, hit.hitVec.zCoord);
}
Entity entityHit = null;
List<?> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
double closestRange = 0.0D;
double collisionRange = 0.3D;
for (int l = 0; l < list.size(); ++l) {
Entity e = (Entity) list.get(l);
if (e.canBeCollidedWith() && (e != _owner || this.ticksInAir >= 5)) {
AxisAlignedBB entitybb = e.boundingBox.expand(collisionRange, collisionRange, collisionRange);
MovingObjectPosition entityHitPos = entitybb.calculateIntercept(pos, nextPos);
if (entityHitPos != null) {
double range = pos.distanceTo(entityHitPos.hitVec);
if (range < closestRange || closestRange == 0.0D) {
entityHit = e;
closestRange = range;
}
}
}
}
if (entityHit != null) {
hit = new MovingObjectPosition(entityHit);
}
if (hit != null && hit.entityHit != null && hit.entityHit instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) hit.entityHit;
if (entityplayer.capabilities.disableDamage || (_owner != null && !_owner.func_96122_a(entityplayer))) {
hit = null;
}
}
float speed = 0.0F;
if (hit != null && !worldObj.isRemote) {
if (hit.entityHit != null && MFRRegistry.getNeedleAmmoTypes().get(_ammoItemId) != null) {
MFRRegistry.getNeedleAmmoTypes().get(_ammoItemId).onHitEntity(_owner, hit.entityHit, Math.sqrt((_xStart - hit.blockX) * (_yStart - hit.blockY) * (_zStart - hit.blockZ)));
} else {
MFRRegistry.getNeedleAmmoTypes().get(_ammoItemId).onHitBlock(_owner, worldObj, hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, Math.sqrt((_xStart - hit.blockX) * (_yStart - hit.blockY) * (_zStart - hit.blockZ)));
}
setDead();
}
this.posX += this.motionX;
this.posY += this.motionY;
this.posZ += this.motionZ;
speed = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
for (this.rotationPitch = (float) (Math.atan2(this.motionY, speed) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) {
;
}
while (this.rotationPitch - this.prevRotationPitch >= 180.0F) {
this.prevRotationPitch += 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw < -180.0F) {
this.prevRotationYaw -= 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw >= 180.0F) {
this.prevRotationYaw += 360.0F;
}
this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
float speedDropoff = 0.99F;
collisionRange = 0.05F;
if (this.isInWater()) {
double particleOffset = 0.25D;
for (int i = 0; i < 4; ++i) {
this.worldObj.spawnParticle("bubble", this.posX - this.motionX * particleOffset, this.posY - this.motionY * particleOffset, this.posZ - this.motionZ * particleOffset, this.motionX, this.motionY, this.motionZ);
}
speedDropoff = 0.8F;
}
if (this.motionY < 0.05) {
this.motionY -= 0.01;
}
this.motionX *= speedDropoff;
this.motionY *= speedDropoff;
this.motionZ *= speedDropoff;
this.setPosition(this.posX, this.posY, this.posZ);
this.doBlockCollisions();
}
use of net.minecraft.util.MovingObjectPosition in project MineFactoryReloaded by powercrystals.
the class BlockRedNetCable method getPartClicked.
private int getPartClicked(EntityPlayer player, double reachDistance, TileEntityRedNetCable cable) {
AxisAlignedBB[] wireparts = getParts(cable);
Vec3 playerPosition = Vec3.createVectorHelper(player.posX - cable.xCoord, player.posY - cable.yCoord + player.getEyeHeight(), player.posZ - cable.zCoord);
Vec3 playerLook = player.getLookVec();
Vec3 playerViewOffset = Vec3.createVectorHelper(playerPosition.xCoord + playerLook.xCoord * reachDistance, playerPosition.yCoord + playerLook.yCoord * reachDistance, playerPosition.zCoord + playerLook.zCoord * reachDistance);
int closest = -1;
double closestdistance = Double.MAX_VALUE;
for (int i = 0; i < wireparts.length; i++) {
AxisAlignedBB part = wireparts[i];
if (part == null) {
continue;
}
MovingObjectPosition hit = part.calculateIntercept(playerPosition, playerViewOffset);
if (hit != null) {
double distance = playerPosition.distanceTo(hit.hitVec);
if (distance < closestdistance) {
closestdistance = distance;
closest = i;
}
}
}
return closest;
}
use of net.minecraft.util.MovingObjectPosition in project ICBM-Classic by BuiltBrokenModding.
the class ItemLaserDetonator method onItemRightClick.
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if (world.isRemote) {
MovingObjectPosition objectMouseOver = player.rayTrace(200, 1);
TileEntity tileEntity = world.getTileEntity(objectMouseOver.blockX, objectMouseOver.blockY, objectMouseOver.blockZ);
if (!(tileEntity instanceof ILauncherController)) {
Engine.instance.packetHandler.sendToServer(new PacketPlayerItem(player, objectMouseOver.blockX, objectMouseOver.blockY, objectMouseOver.blockZ));
}
}
return stack;
}
use of net.minecraft.util.MovingObjectPosition in project ArsMagica2 by Mithion.
the class Beam 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) {
boolean shouldApplyEffect = useCount % 10 == 0;
double range = SpellUtils.instance.getModifiedDouble_Add(SpellModifiers.RANGE, stack, caster, target, world, 0);
boolean targetWater = SpellUtils.instance.modifierIsPresent(SpellModifiers.TARGET_NONSOLID_BLOCKS, stack, 0);
MovingObjectPosition mop = item.getMovingObjectPosition(caster, world, range, true, targetWater);
SpellCastResult result = null;
Vec3 beamHitVec = null;
Vec3 spellVec = null;
if (mop == null) {
beamHitVec = MathUtilities.extrapolateEntityLook(world, caster, range);
spellVec = beamHitVec;
} else if (mop.typeOfHit == MovingObjectType.ENTITY) {
if (shouldApplyEffect) {
Entity e = mop.entityHit;
if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
result = SpellHelper.instance.applyStageToEntity(stack, caster, world, e, 0, giveXP);
if (result != SpellCastResult.SUCCESS) {
return result;
}
}
float rng = (float) mop.hitVec.distanceTo(Vec3.createVectorHelper(caster.posX, caster.posY, caster.posZ));
beamHitVec = MathUtilities.extrapolateEntityLook(world, caster, rng);
spellVec = beamHitVec;
} else {
if (shouldApplyEffect) {
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;
}
}
beamHitVec = mop.hitVec;
spellVec = Vec3.createVectorHelper(mop.blockX, mop.blockY, mop.blockZ);
}
if (world.isRemote && beamHitVec != null) {
AMBeam beam = (AMBeam) beams.get(caster.getEntityId());
double startX = caster.posX;
double startY = caster.posY + caster.getEyeHeight() - 0.2f;
double startZ = caster.posZ;
Affinity affinity = SpellUtils.instance.mainAffinityFor(stack);
int color = -1;
if (SpellUtils.instance.modifierIsPresent(SpellModifiers.COLOR, stack, 0)) {
ISpellModifier[] mods = SpellUtils.instance.getModifiersForStage(stack, 0);
int ordinalCount = 0;
for (ISpellModifier mod : mods) {
if (mod instanceof Colour) {
byte[] meta = SpellUtils.instance.getModifierMetadataFromStack(stack, mod, 0, ordinalCount++);
color = (int) mod.getModifier(SpellModifiers.COLOR, null, null, null, meta);
}
}
}
if (beam != null) {
if (beam.isDead || beam.getDistanceSqToEntity(caster) > 4) {
beams.remove(caster.getEntityId());
} else {
beam.setBeamLocationAndTarget(startX, startY, startZ, beamHitVec.xCoord, beamHitVec.yCoord, beamHitVec.zCoord);
}
} else {
if (affinity == Affinity.LIGHTNING) {
AMCore.instance.proxy.particleManager.BoltFromEntityToPoint(world, caster, beamHitVec.xCoord, beamHitVec.yCoord, beamHitVec.zCoord, 1, color == -1 ? affinity.color : color);
} else {
beam = (AMBeam) AMCore.instance.proxy.particleManager.BeamFromEntityToPoint(world, caster, beamHitVec.xCoord, beamHitVec.yCoord, beamHitVec.zCoord, color == -1 ? affinity.color : color);
if (beam != null) {
if (AMCore.instance.proxy.getProxyUtils().isLocalPlayerInFirstPerson())
beam.setFirstPersonPlayerCast();
beams.put(caster.getEntityId(), beam);
}
}
}
for (int i = 0; i < AMCore.config.getGFXLevel() + 1; ++i) {
AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(world, AMParticleIcons.instance.getParticleForAffinity(affinity), beamHitVec.xCoord, beamHitVec.yCoord, beamHitVec.zCoord);
if (particle != null) {
particle.setMaxAge(2);
particle.setParticleScale(0.1f);
particle.setIgnoreMaxAge(false);
if (color != -1)
particle.setRGBColorI(color);
particle.AddParticleController(new ParticleMoveOnHeading(particle, world.rand.nextDouble() * 360, world.rand.nextDouble() * 360, world.rand.nextDouble() * 0.2 + 0.02f, 1, false));
}
}
}
if (result != null && spellVec != null && shouldApplyEffect) {
ItemStack newItemStack = SpellUtils.instance.popStackStage(stack);
return SpellHelper.instance.applyStackStage(newItemStack, caster, target, spellVec.xCoord, spellVec.yCoord, spellVec.zCoord, mop != null ? mop.sideHit : 0, world, true, giveXP, 0);
} else {
return SpellCastResult.SUCCESS_REDUCE_MANA;
}
}
Aggregations