use of net.minecraft.util.Vec3 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.Vec3 in project MineFactoryReloaded by powercrystals.
the class EntityRocket method onUpdate.
@Override
public void onUpdate() {
super.onUpdate();
_ticksAlive++;
if (_ticksAlive > 200) {
setDead();
}
if (worldObj.isRemote) {
for (int i = 0; i < 4; i++) {
worldObj.spawnParticle("smoke", posX + motionX * i / 4.0D, posY + motionY * i / 4.0D, posZ + motionZ * i / 4.0D, -motionX, -motionY + 0.2D, -motionZ);
}
}
if (!worldObj.isRemote) {
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 i = 0, end = list.size(); i < end; ++i) {
Entity e = (Entity) list.get(i);
if (e.canBeCollidedWith() && (e != _owner)) {
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 == 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 instanceof EntityPlayer && !((EntityPlayer) _owner).func_96122_a(entityplayer))) {
hit = null;
}
}
if (hit != null && !worldObj.isRemote) {
if (hit.entityHit != null) {
// why not spawn explosion at nextPos x/y/z?
worldObj.newExplosion(this, hit.entityHit.posX, hit.entityHit.posY, hit.entityHit.posZ, 4.0F, true, true);
} else {
worldObj.newExplosion(this, hit.blockX, hit.blockY, hit.blockZ, 4.0F, true, true);
}
setDead();
}
}
if (_target != null) {
// At this point, I suspect literally no one on this project actually understands what this does or how it works
Vec3 targetVector = worldObj.getWorldVec3Pool().getVecFromPool(_target.posX - posX, _target.posY - posY, _target.posZ - posZ);
float targetYaw = clampAngle(360 - (float) (Math.atan2(targetVector.xCoord, targetVector.zCoord) * 180.0D / Math.PI), 360, false);
float targetPitch = clampAngle(-(float) (Math.atan2(targetVector.yCoord, Math.sqrt(targetVector.xCoord * targetVector.xCoord + targetVector.zCoord * targetVector.zCoord)) * 180.0D / Math.PI), 360, false);
float yawDifference = clampAngle(targetYaw - rotationYaw, 3, true);
float pitchDifference = clampAngle(targetPitch - rotationPitch, 3, true);
float newYaw;
float newPitch;
if (Math.max(targetYaw, rotationYaw) - Math.min(targetYaw, rotationYaw) > 180) {
newYaw = rotationYaw - yawDifference;
} else {
newYaw = rotationYaw + yawDifference;
}
if (Math.max(targetPitch, rotationPitch) - Math.min(targetPitch, rotationPitch) > 180) {
newPitch = rotationPitch - pitchDifference;
} else {
newPitch = rotationPitch + pitchDifference;
}
rotationYaw = clampAngle(newYaw, 360F, false);
rotationPitch = clampAngle(newPitch, 360F, false);
recalculateVelocity();
}
setPosition(posX + motionX, posY + motionY, posZ + motionZ);
}
use of net.minecraft.util.Vec3 in project SimplyJetpacks by Tonius.
the class ClientProxy method showJetpackParticles.
@Override
public void showJetpackParticles(World world, EntityLivingBase wearer, ParticleType particle) {
if (mc.gameSettings.particleSetting == 0 || mc.gameSettings.particleSetting == 1 && mc.theWorld.getTotalWorldTime() % 4L == 0) {
Vec3 userPos = Vec3.createVectorHelper(wearer.posX, wearer.posY, wearer.posZ);
if (!wearer.equals(mc.thePlayer)) {
userPos = userPos.addVector(0, 1.6D, 0);
}
Random rand = MathHelper.RANDOM;
Vec3 vLeft = Vec3.createVectorHelper(-0.28D, -0.95D, -0.38D);
vLeft.rotateAroundY((float) Math.toRadians(-wearer.renderYawOffset));
Vec3 vRight = Vec3.createVectorHelper(0.28D, -0.95D, -0.38D);
vRight.rotateAroundY((float) Math.toRadians(-wearer.renderYawOffset));
Vec3 vCenter = Vec3.createVectorHelper((rand.nextFloat() - 0.5F) * 0.25F, -0.95D, -0.38D);
vCenter.rotateAroundY((float) Math.toRadians(-wearer.renderYawOffset));
vLeft = vLeft.addVector(-wearer.motionX * 0.2D, -wearer.motionY * 0.2D, -wearer.motionZ * 0.2D);
vRight = vRight.addVector(-wearer.motionX * 0.2D, -wearer.motionY * 0.2D, -wearer.motionZ * 0.2D);
vCenter = vCenter.addVector(-wearer.motionX * 0.2D, -wearer.motionY * 0.2D, -wearer.motionZ * 0.2D);
Vec3 v = userPos.addVector(vLeft.xCoord, vLeft.yCoord, vLeft.zCoord);
ParticleUtils.spawnParticle(particle, world, v.xCoord, v.yCoord, v.zCoord, rand.nextDouble() * 0.05D - 0.025D, -0.2D, rand.nextDouble() * 0.05D - 0.025D);
v = userPos.addVector(vRight.xCoord, vRight.yCoord, vRight.zCoord);
ParticleUtils.spawnParticle(particle, world, v.xCoord, v.yCoord, v.zCoord, rand.nextDouble() * 0.05D - 0.025D, -0.2D, rand.nextDouble() * 0.05D - 0.025D);
v = userPos.addVector(vCenter.xCoord, vCenter.yCoord, vCenter.zCoord);
ParticleUtils.spawnParticle(particle, world, v.xCoord, v.yCoord, v.zCoord, rand.nextDouble() * 0.05D - 0.025D, -0.2D, rand.nextDouble() * 0.05D - 0.025D);
}
}
use of net.minecraft.util.Vec3 in project NyaSamaRailway by NSDN.
the class NSPCT6W method updateRiderPosition.
@Override
public void updateRiderPosition() {
if (this.riddenByEntity != null) {
double x = this.posX, y = this.posY, z = this.posZ;
int bx = MathHelper.floor_double(x);
int by = MathHelper.floor_double(y);
int bz = MathHelper.floor_double(z);
Block block = worldObj.getBlock(bx, by, bz);
int meta = worldObj.getBlockMetadata(bx, by, bz);
double len = -1.0 + getShiftYCnt();
Vec3 mod = Vec3.createVectorHelper(0, len, 0);
mod.rotateAroundX(this.rotationPitch);
mod.rotateAroundY(this.rotationYaw);
x += mod.xCoord;
y += mod.yCoord;
z += mod.zCoord;
this.riddenByEntity.setPositionAndRotation(x, y + this.getMountedYOffset(), z, this.rotationYaw, 0.0F);
if (this.riddenByEntity instanceof Container && worldObj.isRemote) {
Container container = (Container) this.riddenByEntity;
container.setPositionAndRotation2(x, y + this.getMountedYOffset(), z, this.rotationYaw, 0.0F, -2);
boolean fix = true;
if (block instanceof BlockRailBase) {
fix = ((BlockRailBase) block).isPowered() || meta < 6 || meta > 9;
}
if ((((int) container.rotationYaw) % 90) != 0 && fix) {
container.prevRotationYaw = container.rotationYaw = (float) (MathHelper.floor_double((double) (this.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) * 90.0F;
}
}
}
}
use of net.minecraft.util.Vec3 in project NyaSamaRailway by NSDN.
the class NSPCT8JRenderer method doRender.
@Override
public void doRender(EntityMinecart minecart, double x, double y, double z, float Yaw, float p_doRender_9_) {
GL11.glPushMatrix();
this.bindEntityTexture(minecart);
long var10 = (long) minecart.getEntityId() * 493286711L;
var10 = var10 * var10 * 4392167121L + var10 * 98761L;
float var12 = (((float) (var10 >> 16 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
float var13 = (((float) (var10 >> 20 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
float var14 = (((float) (var10 >> 24 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
GL11.glTranslatef(var12, var13, var14);
double var15 = minecart.lastTickPosX + (minecart.posX - minecart.lastTickPosX) * (double) p_doRender_9_;
double var17 = minecart.lastTickPosY + (minecart.posY - minecart.lastTickPosY) * (double) p_doRender_9_;
double var19 = minecart.lastTickPosZ + (minecart.posZ - minecart.lastTickPosZ) * (double) p_doRender_9_;
double var21 = 0.30000001192092896D;
Vec3 var23 = minecart.func_70489_a(var15, var17, var19);
float var24 = minecart.prevRotationPitch + (minecart.rotationPitch - minecart.prevRotationPitch) * p_doRender_9_;
if (var23 != null) {
Vec3 var25 = minecart.func_70495_a(var15, var17, var19, var21);
Vec3 var26 = minecart.func_70495_a(var15, var17, var19, -var21);
if (var25 == null) {
var25 = var23;
}
if (var26 == null) {
var26 = var23;
}
x += var23.xCoord - var15;
y += (var25.yCoord + var26.yCoord) / 2.0D - var17;
z += var23.zCoord - var19;
Vec3 var27 = var26.addVector(-var25.xCoord, -var25.yCoord, -var25.zCoord);
if (var27.lengthVector() != 0.0D) {
var27 = var27.normalize();
Yaw = (float) (Math.atan2(var27.zCoord, var27.xCoord) * 180.0D / 3.141592653589793D);
var24 = (float) (Math.atan(var27.yCoord) * 73.0D);
}
}
GL11.glTranslatef((float) x, (float) y, (float) z);
GL11.glRotatef(180.0F - Yaw, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-var24, 0.0F, 0.0F, 1.0F);
float var31 = (float) minecart.getRollingAmplitude() - p_doRender_9_;
float var32 = minecart.getDamage() - p_doRender_9_;
if (var32 < 0.0F) {
var32 = 0.0F;
}
if (var31 > 0.0F) {
GL11.glRotatef(MathHelper.sin(var31) * var31 * var32 / 10.0F * (float) minecart.getRollingDirection(), 1.0F, 0.0F, 0.0F);
}
int var33 = minecart.getDisplayTileOffset();
Block var28 = minecart.func_145820_n();
int var29 = minecart.getDisplayTileData();
if (var28.getRenderType() != -1) {
GL11.glPushMatrix();
this.bindTexture(TextureMap.locationBlocksTexture);
float var30 = 0.75F;
GL11.glScalef(var30, var30, var30);
GL11.glTranslatef(0.0F, (float) var33 / 16.0F, 0.0F);
this.func_147910_a(minecart, p_doRender_9_, var28, var29);
GL11.glPopMatrix();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.bindEntityTexture(minecart);
}
RendererHelper.renderWithResource(modelBase, textureBase);
RendererHelper.renderWithResource(modelPrint, texturePrint);
RendererHelper.beginSpecialLightingNoDepth();
doRenderHUD(minecart);
GL11.glPushMatrix();
GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
doRenderHUD(minecart);
GL11.glPopMatrix();
RendererHelper.endSpecialLightingNoDepth();
GL11.glPopMatrix();
}
Aggregations