use of net.minecraft.util.math.Vec3d in project ImmersiveEngineering by BluSunrize.
the class ItemChemthrower method onUsingTick.
@Override
public void onUsingTick(ItemStack stack, EntityLivingBase player, int count) {
FluidStack fs = this.getFluid(stack);
if (fs != null && fs.getFluid() != null) {
int duration = getMaxItemUseDuration(stack) - count;
int consumed = IEConfig.Tools.chemthrower_consumption;
if (consumed * duration <= fs.amount) {
Vec3d v = player.getLookVec();
int split = 8;
boolean isGas = fs.getFluid().isGaseous() || ChemthrowerHandler.isGas(fs.getFluid());
float scatter = isGas ? .15f : .05f;
float range = isGas ? .5f : 1f;
if (getUpgrades(stack).getBoolean("focus")) {
range += .25f;
scatter -= .025f;
}
boolean ignite = ChemthrowerHandler.isFlammable(fs.getFluid()) && ItemNBTHelper.getBoolean(stack, "ignite");
for (int i = 0; i < split; i++) {
Vec3d vecDir = v.addVector(player.getRNG().nextGaussian() * scatter, player.getRNG().nextGaussian() * scatter, player.getRNG().nextGaussian() * scatter);
EntityChemthrowerShot chem = new EntityChemthrowerShot(player.worldObj, player, vecDir.xCoord * 0.25, vecDir.yCoord * 0.25, vecDir.zCoord * 0.25, fs);
chem.motionX = vecDir.xCoord * range;
chem.motionY = vecDir.yCoord * range;
chem.motionZ = vecDir.zCoord * range;
if (ignite)
chem.setFire(10);
if (!player.worldObj.isRemote)
player.worldObj.spawnEntityInWorld(chem);
}
if (count % 4 == 0) {
if (ignite)
player.playSound(IESounds.sprayFire, .5f, 1.5f);
else
player.playSound(IESounds.spray, .5f, .75f);
}
} else
player.stopActiveHand();
} else
player.stopActiveHand();
}
use of net.minecraft.util.math.Vec3d in project ImmersiveEngineering by BluSunrize.
the class EntitySkylineHook method onUpdate.
@Override
public void onUpdate() {
EntityPlayer player = null;
// if(this.getControllingPassenger() instanceof EntityPlayer)
// player = ((EntityPlayer)this.getControllingPassenger());
List<Entity> list = this.getPassengers();
if (!list.isEmpty() && list.get(0) instanceof EntityPlayer)
player = (EntityPlayer) list.get(0);
if (this.ticksExisted == 1 && !worldObj.isRemote) {
IELogger.debug("init tick at " + System.currentTimeMillis());
if (player instanceof EntityPlayerMP)
ImmersiveEngineering.packetHandler.sendTo(new MessageSkyhookSync(this), (EntityPlayerMP) player);
}
super.onUpdate();
// return;
if (subPoints != null && targetPoint < subPoints.length - 1) {
double dist = subPoints[targetPoint].distanceTo(new Vec3d(posX, posY, posZ));
IELogger.debug("dist: " + dist);
if (dist <= 0) {
this.posX = subPoints[targetPoint].xCoord;
this.posY = subPoints[targetPoint].yCoord;
this.posZ = subPoints[targetPoint].zCoord;
targetPoint++;
if (player instanceof EntityPlayerMP)
ImmersiveEngineering.packetHandler.sendTo(new MessageSkyhookSync(this), (EntityPlayerMP) player);
IELogger.debug("next vertex: " + targetPoint);
return;
}
float speed = 2f;
if (player != null && player.getActiveItemStack() != null && player.getActiveItemStack().getItem() instanceof ItemSkyhook)
speed = ((ItemSkyhook) player.getActiveItemStack().getItem()).getSkylineSpeed(player.getActiveItemStack());
Vec3d moveVec = SkylineHelper.getSubMovementVector(new Vec3d(posX, posY, posZ), subPoints[targetPoint], speed);
//*speed;
motionX = moveVec.xCoord;
//*speed;
motionY = moveVec.yCoord;
//*speed;
motionZ = moveVec.zCoord;
}
if (target != null && targetPoint == subPoints.length - 1) {
TileEntity end = this.worldObj.getTileEntity(target);
IImmersiveConnectable iicEnd = ApiUtils.toIIC(end, worldObj);
if (iicEnd == null) {
this.setDead();
return;
}
Vec3d vEnd = new Vec3d(target.getX(), target.getY(), target.getZ());
vEnd = Utils.addVectors(vEnd, iicEnd.getConnectionOffset(connection));
double gDist = vEnd.distanceTo(new Vec3d(posX, posY, posZ));
IELogger.debug("distance to goal: " + gDist);
if (gDist <= .3) {
reachedTarget(end);
return;
} else if (gDist > 5) {
setDead();
return;
}
}
this.posX += this.motionX;
this.posY += this.motionY;
this.posZ += this.motionZ;
float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float) (Math.atan2(this.motionZ, this.motionX) * 180.0D / Math.PI) + 90.0F;
for (this.rotationPitch = (float) (Math.atan2((double) f1, this.motionY) * 180.0D / Math.PI) - 90.0F; 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;
if (this.isInWater()) {
for (int j = 0; j < 4; ++j) {
float f3 = 0.25F;
this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * (double) f3, this.posY - this.motionY * (double) f3, this.posZ - this.motionZ * (double) f3, this.motionX, this.motionY, this.motionZ);
}
}
if (player != null) {
double dx = this.posX - this.prevPosX;
double dy = this.posY - this.prevPosY;
double dz = this.posZ - this.prevPosZ;
int distTrvl = Math.round(MathHelper.sqrt_double(dx * dx + dy * dy + dz * dz) * 100.0F);
if (distTrvl > 0)
player.addStat(IEAchievements.statDistanceSkyhook, distTrvl);
if (!worldObj.isRemote && SkylineHelper.isInBlock(player, worldObj)) {
// setDead();
// player.setPosition(posX-3*dx, posY-3*dy+getMountedYOffset(),posZ-3*dz);
}
//TODO
// if(player instanceof EntityPlayerMP)
// if(((EntityPlayerMP)player).getStatFile().func_150870_b(IEAchievements.statDistanceSkyhook)>100000)
// player.triggerAchievement(IEAchievements.skyhookPro);
}
this.setPosition(this.posX, this.posY, this.posZ);
}
use of net.minecraft.util.math.Vec3d in project NetherEx by LogicTechCorp.
the class EntityEmber method updateAITasks.
@Override
public void updateAITasks() {
if (isWet()) {
attackEntityFrom(DamageSource.DROWN, 1.0F);
}
if (currentMoveTypeDuration > 0) {
--currentMoveTypeDuration;
}
if (onGround) {
if (!wasOnGround) {
setJumping(false);
checkLandingDelay();
}
JumpHelper helper = (JumpHelper) jumpHelper;
if (!helper.getIsJumping()) {
if (moveHelper.isUpdating() && currentMoveTypeDuration == 0) {
Path path = navigator.getPath();
Vec3d vec3d = new Vec3d(moveHelper.getX(), moveHelper.getY(), moveHelper.getZ());
if (path != null && path.getCurrentPathIndex() < path.getCurrentPathLength()) {
vec3d = path.getPosition(this);
}
calculateRotationYaw(vec3d.xCoord, vec3d.zCoord);
startJumping();
}
} else if (!helper.canJump()) {
enableJumpControl();
}
}
wasOnGround = onGround;
}
use of net.minecraft.util.math.Vec3d in project NetherEx by LogicTechCorp.
the class ItemObsidianBoat method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * 1.0F;
float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * 1.0F;
double d0 = player.prevPosX + (player.posX - player.prevPosX) * 1.0D;
double d1 = player.prevPosY + (player.posY - player.prevPosY) * 1.0D + (double) player.getEyeHeight();
double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * 1.0D;
Vec3d vec3d = new Vec3d(d0, d1, d2);
float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI);
float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI);
float f5 = -MathHelper.cos(-f1 * 0.017453292F);
float f6 = MathHelper.sin(-f1 * 0.017453292F);
float f7 = f4 * f5;
float f8 = f3 * f5;
Vec3d vec3d1 = vec3d.addVector((double) f7 * 5.0D, (double) f6 * 5.0D, (double) f8 * 5.0D);
RayTraceResult raytraceresult = world.rayTraceBlocks(vec3d, vec3d1, true);
if (raytraceresult == null) {
return new ActionResult(EnumActionResult.PASS, stack);
} else {
Vec3d vec3d2 = player.getLook(1.0F);
boolean flag = false;
List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(player, player.getEntityBoundingBox().addCoord(vec3d2.xCoord * 5.0D, vec3d2.yCoord * 5.0D, vec3d2.zCoord * 5.0D).expandXyz(1.0D));
for (Entity entity : entities) {
if (entity.canBeCollidedWith()) {
AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().expandXyz((double) entity.getCollisionBorderSize());
if (axisalignedbb.isVecInside(vec3d)) {
flag = true;
}
}
}
if (flag) {
return new ActionResult(EnumActionResult.PASS, stack);
} else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK) {
return new ActionResult(EnumActionResult.PASS, stack);
} else {
Block block = world.getBlockState(raytraceresult.getBlockPos()).getBlock();
boolean flag1 = block == Blocks.WATER || block == Blocks.FLOWING_WATER;
EntityObsidianBoat boat = new EntityObsidianBoat(world, raytraceresult.hitVec.xCoord, flag1 ? raytraceresult.hitVec.yCoord - 0.12D : raytraceresult.hitVec.yCoord, raytraceresult.hitVec.zCoord);
boat.rotationYaw = player.rotationYaw;
if (!world.getCollisionBoxes(boat, boat.getEntityBoundingBox().expandXyz(-0.1D)).isEmpty()) {
return new ActionResult(EnumActionResult.FAIL, stack);
} else {
if (!world.isRemote) {
world.spawnEntity(boat);
}
if (!player.capabilities.isCreativeMode) {
stack.shrink(1);
}
return new ActionResult(EnumActionResult.SUCCESS, stack);
}
}
}
}
use of net.minecraft.util.math.Vec3d in project minecolonies by Minecolonies.
the class RenderFishHook method doRender.
/**
* Render a fishing hook entity in the world
* This class uses some GL11 stuff
* and seems hard to document...
*
* @param entity the hook to render
* @param x the x position
* @param y the y position
* @param z the z position
* @param entityYaw the angle thrown
*/
@Override
public void doRender(@NotNull final EntityFishHook entity, final double x, final double y, final double z, final float entityYaw, final float partialTicks) {
GlStateManager.pushMatrix();
GlStateManager.translate((float) x, (float) y, (float) z);
GlStateManager.enableRescaleNormal();
GlStateManager.scale(0.5F, 0.5F, 0.5F);
this.bindEntityTexture(entity);
final Tessellator tessellator = Tessellator.getInstance();
final VertexBuffer vertexBuffer = tessellator.getBuffer();
GlStateManager.rotate((float) (180.0D - this.renderManager.playerViewY), 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
vertexBuffer.begin(7, DefaultVertexFormats.POSITION_TEX_NORMAL);
vertexBuffer.pos(-0.5D, -0.5D, 0.0D).tex(0.0625D, 0.1875D).normal(0.0F, 1.0F, 0.0F).endVertex();
vertexBuffer.pos(0.5D, -0.5D, 0.0D).tex(0.125D, 0.1875D).normal(0.0F, 1.0F, 0.0F).endVertex();
vertexBuffer.pos(0.5D, 0.5D, 0.0D).tex(0.125D, 0.125D).normal(0.0F, 1.0F, 0.0F).endVertex();
vertexBuffer.pos(-0.5D, 0.5D, 0.0D).tex(0.0625D, 0.125D).normal(0.0F, 1.0F, 0.0F).endVertex();
tessellator.draw();
GlStateManager.disableRescaleNormal();
GlStateManager.popMatrix();
EntityCitizen citizen = entity.getCitizen();
//Check if he is a fisherman -> Through his texture
if (citizen == null) {
for (@NotNull final Object citizenX : entity.world.getEntitiesWithinAABB(EntityCitizen.class, entity.getEntityBoundingBox().expand(10, 10, 10))) {
if (((EntityCitizen) citizenX).getModelID().textureBase.contains("Fisherman")) {
citizen = (EntityCitizen) citizenX;
break;
}
}
}
if (citizen != null) {
final double orientation = citizen.getSwingProgress(partialTicks);
final double finalOrientation = Math.sin(Math.sqrt(orientation) * Math.PI);
@NotNull final Vec3d Vec3d = new Vec3d(-0.36D, 0.03D, 0.35D);
Vec3d.rotatePitch((float) (-((double) citizen.prevRotationPitch + ((double) citizen.rotationPitch - (double) citizen.prevRotationPitch) * partialTicks) * Math.PI / Literals.HALF_CIRCLE));
Vec3d.rotateYaw((float) (-((double) citizen.prevRotationYaw + ((double) citizen.rotationYaw - (double) citizen.prevRotationYaw) * partialTicks) * Math.PI / Literals.HALF_CIRCLE));
Vec3d.rotateYaw((float) (finalOrientation * 0.5D));
Vec3d.rotatePitch((float) (-finalOrientation * 0.7D));
final double thirdPersonOffset = (citizen.prevRenderYawOffset + ((double) citizen.renderYawOffset - citizen.prevRenderYawOffset) * partialTicks) * Math.PI / Literals.HALF_CIRCLE;
final double correctedPosX = citizen.prevPosX + (citizen.posX - citizen.prevPosX) * (double) partialTicks - MathHelper.cos((float) thirdPersonOffset) * 0.35D - MathHelper.sin((float) thirdPersonOffset) * 0.8D;
final double correctedPosY = citizen.prevPosY + citizen.getEyeHeight() + (citizen.posY - citizen.prevPosY) * (double) partialTicks - 0.45D;
final double correctedPosZ = citizen.prevPosZ + (citizen.posZ - citizen.prevPosZ) * (double) partialTicks - MathHelper.sin((float) thirdPersonOffset) * 0.35D + MathHelper.cos((float) thirdPersonOffset) * 0.8D;
final double eyeHeight = citizen.isSneaking() ? -0.1875D : 0.0D;
final double distX = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks;
final double distY = entity.posY + 0.25;
final double distZ = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * partialTicks;
final double correctionX = correctedPosX - distX;
final double correctionY = correctedPosY - distY + eyeHeight;
final double correctionZ = correctedPosZ - distZ;
GlStateManager.disableTexture2D();
GlStateManager.disableLighting();
vertexBuffer.begin(3, DefaultVertexFormats.POSITION_COLOR);
for (int l = 0; l <= 16; ++l) {
final double var = (double) l / 16.0;
vertexBuffer.pos(x + correctionX * var, y + correctionY * (var * var + var) * 0.5D + 0.25D, z + correctionZ * var).color(0, 0, 0, 255).endVertex();
}
tessellator.draw();
GlStateManager.enableLighting();
GlStateManager.enableTexture2D();
super.doRender(entity, x, y, z, entityYaw, partialTicks);
}
}
Aggregations