Java Code Examples for net.minecraft.util.math.MathHelper

The following examples show how to use net.minecraft.util.math.MathHelper. These examples are extracted from open source projects.
Example 1
Project: bleachhack-1.14   File: BleachFileHelper.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static void readSettings() {
	List<String> lines = BleachFileMang.readFileLines("settings.txt");
	
	for (Module m: ModuleManager.getModules()) {
		for (String s: lines) {
			String[] line = s.split(":");
			if (!line[0].startsWith(m.getName())) continue;
			int count = 0;
			
			for (SettingBase set: m.getSettings()) {
				try {
					if (set instanceof SettingSlider) {
						m.getSettings().get(count).toSlider().setValue(Double.parseDouble(line[count+1]));}
					if (set instanceof SettingMode) {
						m.getSettings().get(count).toMode().mode = MathHelper.clamp(Integer.parseInt(line[count+1]),
								0, m.getSettings().get(count).toMode().modes.length - 1);}
					if (set instanceof SettingToggle) {
						m.getSettings().get(count).toToggle().state = Boolean.parseBoolean(line[count+1]);}
				} catch (Exception e) {}
				count++;
			}
		}
	}
}
 
Example 2
Project: Cyberware   File: SwitchHeldItemAndRotationPacket.java    License: MIT License 6 votes vote down vote up
public static void faceEntity(Entity player, Entity entityIn)
{
	double d0 = entityIn.posX - player.posX;
	double d2 = entityIn.posZ - player.posZ;
	double d1;

	if (entityIn instanceof EntityLivingBase)
	{
		EntityLivingBase entitylivingbase = (EntityLivingBase)entityIn;
		d1 = entitylivingbase.posY + (double)entitylivingbase.getEyeHeight() - (player.posY + (double)player.getEyeHeight());
	}
	else
	{
		d1 = (entityIn.getEntityBoundingBox().minY + entityIn.getEntityBoundingBox().maxY) / 2.0D - (player.posY + (double)player.getEyeHeight());
	}

	double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2);
	float f = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F;
	float f1 = (float)(-(MathHelper.atan2(d1, d3) * (180D / Math.PI)));
	player.rotationPitch = f1;
	player.rotationYaw = f;
}
 
Example 3
Project: TofuCraftReload   File: EntityTofuFish.java    License: MIT License 6 votes vote down vote up
public void onUpdateMoveHelper() {
    if (this.fish.isInWater()) {
        this.fish.motionY += 0.005D;
    }

    if (this.action == EntityMoveHelper.Action.MOVE_TO && !this.fish.getNavigator().noPath()) {
        double d0 = this.posX - this.fish.posX;
        double d1 = this.posY - this.fish.posY;
        double d2 = this.posZ - this.fish.posZ;
        double d3 = (double) MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
        d1 = d1 / d3;
        float f = (float)(MathHelper.atan2(d2, d0) * (double)(180F / (float)Math.PI)) - 90.0F;
        this.fish.rotationYaw = this.limitAngle(this.fish.rotationYaw, f, 90.0F);
        this.fish.renderYawOffset = this.fish.rotationYaw;
        float f1 = (float)(this.speed * this.fish.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getBaseValue());
        this.fish.setAIMoveSpeed(this.fish.getAIMoveSpeed() + (f1 - this.fish.getAIMoveSpeed()) * 0.125F);
        this.fish.motionY += (double)this.fish.getAIMoveSpeed() * d1 * 0.1D;
    } else {
        this.fish.setAIMoveSpeed(0.0F);
    }
}
 
Example 4
Project: Wizardry   File: RenderCodex.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void renderItemInFirstPerson(AbstractClientPlayer player, EnumHand hand, float swingProgress, ItemStack stack, float equipProgress) {
	// Cherry picked from ItemRenderer.renderItemInFirstPerson
	boolean flag = hand == EnumHand.MAIN_HAND;
	EnumHandSide enumhandside = flag ? player.getPrimaryHand() : player.getPrimaryHand().opposite();
	GlStateManager.pushMatrix();
	boolean flag1 = enumhandside == EnumHandSide.RIGHT;
	float f = -0.4F * MathHelper.sin(MathHelper.sqrt(swingProgress) * (float) Math.PI);
	float f1 = 0.2F * MathHelper.sin(MathHelper.sqrt(swingProgress) * ((float) Math.PI * 2F));
	float f2 = -0.2F * MathHelper.sin(swingProgress * (float) Math.PI);
	int i = flag1 ? 1 : -1;
	GlStateManager.translate(i * f, f1, f2);
	transformSideFirstPerson(enumhandside, equipProgress);
	transformFirstPerson(enumhandside, swingProgress);
	RenderCodex.INSTANCE.doRender(enumhandside, stack);
	GlStateManager.popMatrix();
}
 
Example 5
Project: ForgeHax   File: EntityUtils.java    License: MIT License 6 votes vote down vote up
public static boolean isInWater(Entity entity) {
  if (entity == null) {
    return false;
  }
  
  double y = entity.posY + 0.01;
  
  for (int x = MathHelper.floor(entity.posX); x < MathHelper.ceil(entity.posX); x++) {
    for (int z = MathHelper.floor(entity.posZ); z < MathHelper.ceil(entity.posZ); z++) {
      BlockPos pos = new BlockPos(x, (int) y, z);
      
      if (getWorld().getBlockState(pos).getBlock() instanceof BlockLiquid) {
        return true;
      }
    }
  }
  
  return false;
}
 
Example 6
Project: CommunityMod   File: ModelDabSquirrel.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) {
	float f = limbSwing;
	float f1 = limbSwingAmount;

	this.lArm01.rotateAngleX = MathHelper.cos(f * 0.6662F) * 0.5F * f1 - 0.20943951023931953F;
	this.rArm01.rotateAngleX = MathHelper.cos(f * 0.6662F + (float) Math.PI) * 0.5F * f1 - 0.20943951023931953F;
	this.rLeg01.rotateAngleX = MathHelper.cos(f * 0.6662F) * 0.5F * f1 - 0.17453292519943295F;
	this.lLeg01.rotateAngleX = MathHelper.cos(f * 0.6662F + (float) Math.PI) * 0.5F * f1 - 0.17453292519943295F;
	this.tail01.rotateAngleX = MathHelper.sin(f * 0.2F) * 0.5F * f1 - (float) Math.toRadians(30);

	if (entityIn instanceof EntityLiving) {
		EntityLiving e = (EntityLiving) entityIn;
		float yawOffset = interpolateRotation(e.prevRenderYawOffset, e.renderYawOffset, Minecraft.getMinecraft().getRenderPartialTicks());
		float yawHead = interpolateRotation(e.prevRotationYawHead, e.rotationYawHead, Minecraft.getMinecraft().getRenderPartialTicks());

		this.neck.rotateAngleX = (e.prevRotationPitch + (e.rotationPitch - e.prevRotationPitch) * Minecraft.getMinecraft().getRenderPartialTicks()) * 0.017453292F - 13;
		this.neck.rotateAngleY = (yawHead - yawOffset) * 0.017453292F * 0.5F;
		//if (entityIn instanceof EntityDabSquirrel) {
			//EntityDabSquirrel ent = (EntityDabSquirrel) e;
			//this.chest.rotateAngleX = ent.isBesideClimbableBlock() ? (float) Math.toRadians(-90) : 0.10471975511965977F;
		//}
	}

	super.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn);
}
 
Example 7
Project: GregTech   File: MetaTileEntityTank.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private double getFluidLevelForTank(BlockPos tankPos) {
    if (!isTankController()) {
        MetaTileEntityTank controller = getControllerEntity();
        return controller == null ? 0.0 : controller.getFluidLevelForTank(tankPos);
    }
    FluidStack fluidStack = multiblockFluidTank.getFluid();
    if (fluidStack == null) {
        return 0.0;
    }
    double fluidLevel = multiblockFluidTank.getFluidAmount() / (1.0 * multiblockFluidTank.getCapacity());
    double resultLevel;
    if (fluidStack.getFluid().isGaseous(fluidStack)) {
        resultLevel = fluidLevel;
    } else {
        int tankOffset = (tankPos.getY() - getPos().getY());
        resultLevel = fluidLevel * multiblockSize.getY() - tankOffset;
    }
    return MathHelper.clamp(resultLevel, 0.0, 1.0);
}
 
Example 8
Project: seppuku   File: SpeedComponent.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
    super.render(mouseX, mouseY, partialTicks);
    final DecimalFormat df = new DecimalFormat("#.#");

    final double deltaX = Minecraft.getMinecraft().player.posX - Minecraft.getMinecraft().player.prevPosX;
    final double deltaZ = Minecraft.getMinecraft().player.posZ - Minecraft.getMinecraft().player.prevPosZ;
    final float tickRate = (Minecraft.getMinecraft().timer.tickLength / 1000.0f);

    final String bps = "BPS: " + df.format((MathHelper.sqrt(deltaX * deltaX + deltaZ * deltaZ) / tickRate));

    this.setW(Minecraft.getMinecraft().fontRenderer.getStringWidth(bps));
    this.setH(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT);

    //RenderUtil.drawRect(this.getX(), this.getY(), this.getX() + this.getW(), this.getY() + this.getH(), 0x90222222);
    Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(bps, this.getX(), this.getY(), -1);
}
 
Example 9
Project: enderutilities   File: ItemEnderTool.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean useHoeArea(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, int rWidth, int rHeight)
{
    boolean northSouth = (((int)MathHelper.floor(player.rotationYaw * 4.0f / 360.0f + 0.5f)) & 1) == 0;
    boolean retValue = false;

    if (northSouth == false)
    {
        int tmp = rWidth;
        rWidth = rHeight;
        rHeight = tmp;
    }

    for (int x = pos.getX() - rWidth; x <= (pos.getX() + rWidth); ++x)
    {
        for (int z = pos.getZ() - rHeight; z <= (pos.getZ() + rHeight); ++z)
        {
            retValue |= this.useHoe(stack, player, world, new BlockPos(x, pos.getY(), z), side);
        }
    }

    return retValue;
}
 
Example 10
Project: GokiStats   File: TickHandler.java    License: MIT License 6 votes vote down vote up
private void handleFurnace(EntityPlayer player) {
    if (DataHelper.getPlayerStatLevel(player, Stats.FURNACE_FINESSE) > 0) {
        ArrayList<TileEntityFurnace> furnacesAroundPlayer = new ArrayList<>();

        for (TileEntity listEntity : player.world.loadedTileEntityList) {
            if (listEntity != null) {
                TileEntity tileEntity = listEntity;
                BlockPos pos = tileEntity.getPos();
                if (tileEntity instanceof TileEntityFurnace && MathHelper.sqrt(player.getDistanceSq(pos)) < 4.0D) {
                    // TODO work out alter way to do tileEntity
                    furnacesAroundPlayer.add((TileEntityFurnace) tileEntity);
                }
            }
        }

        // FIXME Laggy
        for (TileEntityFurnace furnace : furnacesAroundPlayer)
            if (furnace.isBurning())
                for (int i = 0; i < Stats.FURNACE_FINESSE.getBonus(player); i++) // Intend to "mount" ticks, same as Torcherino.
                    furnace.update();
    }

}
 
Example 11
Project: the-hallow   File: CrowEntityModel.java    License: MIT License 6 votes vote down vote up
@Override
public void setAngles(CrowEntity crow, float limbAngle, float limbDistance, float age, float headYaw, float headPitch) {
	
	head.pitch = headPitch * 0.017453292F;
	head.yaw = headYaw * 0.017453292F;
	
	if (crow.isInAir()) {
		leftLeg.pitch = 0.55F;
		rightLeg.pitch = 0.55F;
		this.leftWing.roll = 0.0873F + age;
		this.rightWing.roll = -0.0873F - age;
	} else {
		leftLeg.pitch = -0.6109F + MathHelper.cos(limbAngle * 0.6662F) * 1.4F * limbDistance;
		rightLeg.pitch = -0.6109F + MathHelper.cos(limbAngle * 0.6662F + 3.1415927F) * 1.4F * limbDistance;
		leftWing.roll = 0F;
		rightWing.roll = 0F;
	}
}
 
Example 12
private Vec3d getBlockBelowCartOffset(){
    BlockState blockState_1 = this.world.getBlockState(new BlockPos(MathHelper.floor(this.getX()), MathHelper.floor(this.getY()), MathHelper.floor(this.getZ())));
    if (blockState_1.matches(BlockTags.RAILS)) {
        RailShape railShape = (RailShape)blockState_1.get(((AbstractRailBlock)blockState_1.getBlock()).getShapeProperty());
        switch (railShape){
            case ASCENDING_EAST:
                return ascending_east_offset;
            case ASCENDING_WEST:
                return ascending_west_offset;
            case ASCENDING_NORTH:
                return ascending_north_offset;
            case ASCENDING_SOUTH:
                return ascending_south_offset;
            default:
                return upwardVec;
        }
    }
    return upwardVec;
}
 
Example 13
Project: Galacticraft-Rewoven   File: GCOreFeature.java    License: MIT License 5 votes vote down vote up
@Override
public boolean generate(ServerWorldAccess serverWorldAccess, StructureAccessor structureAccessor, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, GCOreFeatureConfig oreFeatureConfig) {
    float f = random.nextFloat() * 3.1415927F;
    float g = (float) oreFeatureConfig.size / 8.0F;
    int i = MathHelper.ceil(((float) oreFeatureConfig.size / 16.0F * 2.0F + 1.0F) / 2.0F);
    double d = (float) blockPos.getX() + MathHelper.sin(f) * g;
    double e = (float) blockPos.getX() - MathHelper.sin(f) * g;
    double h = (float) blockPos.getZ() + MathHelper.cos(f) * g;
    double j = (float) blockPos.getZ() - MathHelper.cos(f) * g;
    double l = blockPos.getY() + random.nextInt(3) - 2;
    double m = blockPos.getY() + random.nextInt(3) - 2;
    int n = blockPos.getX() - MathHelper.ceil(g) - i;
    int o = blockPos.getY() - 2 - i;
    int p = blockPos.getZ() - MathHelper.ceil(g) - i;
    int q = 2 * (MathHelper.ceil(g) + i);
    int r = 2 * (2 + i);

    for (int s = n; s <= n + q; ++s) {
        for (int t = p; t <= p + q; ++t) {
            if (o <= serverWorldAccess.getTopY(Heightmap.Type.OCEAN_FLOOR_WG, s, t)) {
                return this.generateVeinPart(serverWorldAccess, random, oreFeatureConfig, d, e, h, j, l, m, n, o, p, q, r);
            }
        }
    }

    return false;
}
 
Example 14
Project: Wizardry   File: ModuleEffectTimeSlow.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public void renderSpell(World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
	Entity victim = spell.getVictim(world);

	if (victim == null) return;

	ParticleBuilder glitter = new ParticleBuilder(30);
	glitter.setColorFunction(new InterpColorHSV(instance.getPrimaryColor(), instance.getSecondaryColor()));
	glitter.setRender(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
	glitter.setScaleFunction(new InterpScale(1, 0));
	glitter.setCollision(true);
	glitter.enableMotionCalculation();
	glitter.setAcceleration(new Vec3d(0, RandUtil.nextBoolean() ? -0.0001 : 0.0001, 0));
	glitter.disableRandom();

	ParticleSpawner.spawn(glitter, world, new StaticInterp<>(victim.getPositionVector().add(0, victim.height / 2, 0)), 5, 0, (aFloat, particleBuilder) -> {
		glitter.setLifetime(RandUtil.nextInt(40, 80));
		glitter.setScaleFunction(new InterpScale(RandUtil.nextFloat(0.5f, 1f), 0f));
		glitter.setAlphaFunction(new InterpFloatInOut(0.5f, 0.5f));

		double radius = RandUtil.nextDouble(0, 2);
		double theta = 2.0f * (float) Math.PI * RandUtil.nextFloat();
		double r = radius * RandUtil.nextFloat();
		double x = r * MathHelper.cos((float) theta);
		double z = r * MathHelper.sin((float) theta);
		Vec3d dest = new Vec3d(x, RandUtil.nextDouble(-radius, radius), z);
		glitter.setPositionOffset(dest);
		glitter.setMotion(new Vec3d(RandUtil.nextDouble(-0.001, 0.001), 0, RandUtil.nextDouble(-0.001, 0.001)));

		//glitter.setPositionFunction(new InterpSlowDown(Vec3d.ZERO, new Vec3d(0, RandUtil.nextDouble(-1, 1), 0)));
		//glitter.setPositionFunction(new InterpBezier3D(Vec3d.ZERO, position.subtract(dest), dest.scale(2), new Vec3d(position.x, radius, position.z)));
	});
}
 
Example 15
Project: Wurst7   File: KillauraLegitHack.java    License: GNU General Public License v3.0 5 votes vote down vote up
private float limitAngleChange(float current, float intended,
	float maxChange)
{
	float change = MathHelper.wrapDegrees(intended - current);
	change = MathHelper.clamp(change, -maxChange, maxChange);
	return MathHelper.wrapDegrees(current + change);
}
 
Example 16
Project: ForgeHax   File: AntiAfkMod.java    License: MIT License 5 votes vote down vote up
@Override
public void onTick() {
  setViewAngles(
      MathHelper.clamp(
          getLocalPlayer().rotationPitch + MathHelper.cos(ang += 0.1f), -90.f, 90.f),
      getLocalPlayer().rotationYaw + 1.8f);
}
 
Example 17
Project: EnderZoo   File: ModelWitherCat.java    License: Creative Commons Zero v1.0 Universal 5 votes vote down vote up
/**
 * Sets the model's various rotation angles. For bipeds, par1 and par2 are
 * used for animating the movement of arms and legs, where par1 represents the
 * time(so that arms and legs swing back and forth) and par2 represents how
 * "far" arms and legs can swing at most.
 */
@Override
public void setRotationAngles(float p_78087_1_, float p_78087_2_, float p_78087_3_, float p_78087_4_, float p_78087_5_, float p_78087_6_, Entity p_78087_7_) {

  ocelotHead.rotateAngleX = p_78087_5_ / (180F / (float) Math.PI);
  ocelotHead.rotateAngleY = p_78087_4_ / (180F / (float) Math.PI);

  if (field_78163_i != 3) {
    ocelotBody.rotateAngleX = ((float) Math.PI / 2F);

    if (field_78163_i == 2) {
      ocelotBackLeftLeg.rotateAngleX = MathHelper.cos(p_78087_1_ * 0.6662F) * 1.0F * p_78087_2_;
      ocelotBackRightLeg.rotateAngleX = MathHelper.cos(p_78087_1_ * 0.6662F + 0.3F) * 1.0F * p_78087_2_;
      ocelotFrontLeftLeg.rotateAngleX = MathHelper.cos(p_78087_1_ * 0.6662F + (float) Math.PI + 0.3F) * 1.0F * p_78087_2_;
      ocelotFrontRightLeg.rotateAngleX = MathHelper.cos(p_78087_1_ * 0.6662F + (float) Math.PI) * 1.0F * p_78087_2_;
      ocelotTail2.rotateAngleX = 1.7278761F + ((float) Math.PI / 10F) * MathHelper.cos(p_78087_1_) * p_78087_2_;
    } else {
      ocelotBackLeftLeg.rotateAngleX = MathHelper.cos(p_78087_1_ * 0.6662F) * 1.0F * p_78087_2_;
      ocelotBackRightLeg.rotateAngleX = MathHelper.cos(p_78087_1_ * 0.6662F + (float) Math.PI) * 1.0F * p_78087_2_;
      ocelotFrontLeftLeg.rotateAngleX = MathHelper.cos(p_78087_1_ * 0.6662F + (float) Math.PI) * 1.0F * p_78087_2_;
      ocelotFrontRightLeg.rotateAngleX = MathHelper.cos(p_78087_1_ * 0.6662F) * 1.0F * p_78087_2_;

      if (field_78163_i == 1) {
        ocelotTail2.rotateAngleX = 1.7278761F + ((float) Math.PI / 4F) * MathHelper.cos(p_78087_1_) * p_78087_2_;
      } else {
        ocelotTail2.rotateAngleX = 1.7278761F + 0.47123894F * MathHelper.cos(p_78087_1_) * p_78087_2_;
      }
    }
  }
}
 
Example 18
Project: CodeChickenLib   File: Quad.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Clamps the Quad inside the box.
 *
 * @param bb The box.
 */
public void clamp(AxisAlignedBB bb) {
    for (Vertex vertex : vertices) {
        float[] vec = vertex.vec;
        vec[0] = (float) MathHelper.clamp(vec[0], bb.minX, bb.maxX);
        vec[1] = (float) MathHelper.clamp(vec[1], bb.minY, bb.maxY);
        vec[2] = (float) MathHelper.clamp(vec[2], bb.minZ, bb.maxZ);
    }
    calculateOrientation(true);
}
 
Example 19
Project: MineLittlePony   File: SeaponyTail.java    License: MIT License 5 votes vote down vote up
@Override
public void setRotationAndAngles(boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float ticks) {
    float rotation = model.getAttributes().isSleeping ? 0 : MathHelper.sin(ticks * 0.536f) / 4;

    tailBase.pitch = TAIL_ROTX + rotation;
    tailTip.pitch = rotation;
    tailFins.pitch = rotation - TAIL_ROTX;
}
 
Example 20
Project: enderutilities   File: ScrollBar.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean move(int amount, boolean playSound)
{
    this.position = MathHelper.clamp(this.position + amount, 0, this.positionMax);
    this.parent.scrollbarAction(this.id, ScrollbarAction.MOVE, -1);

    if (playSound)
    {
        this.playPressSound();
    }

    return true;
}
 
Example 21
Project: Wizardry   File: TileManaMagnetRenderer.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void render(TileManaMagnet te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
	if (te.manaOrb != null) {
		GlStateManager.pushMatrix();
		GlStateManager.enableBlend();
		GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

		GlStateManager.translate(x + 0.5, y + 0.5, z + 0.5);
		GlStateManager.translate(0, MathHelper.sin(ClientTickHandler.getTicks()) / 2.0, 0);
		GlStateManager.disableRescaleNormal();
		{
			GlStateManager.enableRescaleNormal();
			GlStateManager.disableCull();
			GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
			GlStateManager.enableLighting();
			GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
			RenderHelper.disableStandardItemLighting();

			Minecraft.getMinecraft().getTextureManager().bindTexture(manaPearlCubeTexture);
			TileOrbHolderRenderer.renderCube(0.1, Color.WHITE);

			GlStateManager.disableRescaleNormal();
		}

		GlStateManager.disableBlend();
		GlStateManager.popMatrix();
	}
}
 
Example 22
Project: MiningGadgets   File: RenderMiningLaser.java    License: MIT License 5 votes vote down vote up
private static float getSpeedModifier(ItemStack stack) {
    if (UpgradeTools.containsUpgrade(stack, Upgrade.EFFICIENCY_1)) {
        double efficiency = UpgradeTools.getUpgradeFromGadget(stack, Upgrade.EFFICIENCY_1).get().getTier() / 5f;
        double speedModifier = MathHelper.lerp(efficiency, 0.02, 0.05);
        return (float) -speedModifier;
    } else {
        return -0.02f;
    }
}
 
Example 23
Project: AdvancedRocketry   File: WorldProviderPlanet.java    License: MIT License 5 votes vote down vote up
@Override
public float getSunBrightness(float partialTicks) {
	
	float atmosphere = getAtmosphereDensity(new BlockPos(0,0,0));
	Math.abs(1-atmosphere);
	//calculateCelestialAngle(p_76563_1_, p_76563_3_)
	float f1 = world.getCelestialAngle(partialTicks);
	float f2 = 1.0F - (MathHelper.cos(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.2F) - atmosphere/4f;

	if (f2 < 0.0F)
	{
		f2 = 0.0F ;
	}

	if (f2 > 1.0F)
	{
		f2 = 1.0F;
	}

	f2 = 1.0F - f2;

	//Eclipse handling
	if(this.world.isRemote) {
		DimensionProperties properties = getDimensionProperties(Minecraft.getMinecraft().player.getPosition());
		if(properties.isMoon()) {
			f2 = eclipseValue(properties, f2, partialTicks);
		}
		else {
			for(int i : properties.getChildPlanets()) {
				DimensionProperties childProps = DimensionManager.getInstance().getDimensionProperties(i);
				f2 = eclipseValue(childProps, f2, partialTicks);
			}
		}
	}

	return f2*super.getSunBrightness(partialTicks);
}
 
Example 24
Project: Wizardry   File: ManaManager.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public CapManagerBuilder setBurnout(double burnout) {
	if (cap == null) return this;
	double clamped = MathHelper.clamp(burnout, 0, getMaxBurnout());

	if (cap.getBurnout() != clamped) {
		cap.setBurnout(clamped);
		somethingChanged = true;
	}
	return this;
}
 
Example 25
Project: Wizardry   File: ModuleEffectGravityWell.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public void renderSpell(World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
	Vec3d position = spell.getTarget(world);

	if (position == null) return;

	double potency = spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell);
	double maxPotency = spellRing.getModule() != null ? spellRing.getModule().getAttributeRanges().get(AttributeRegistry.POTENCY).max : 1;

	ParticleBuilder glitter = new ParticleBuilder(0);
	glitter.setColorFunction(new InterpColorHSV(instance.getPrimaryColor(), instance.getSecondaryColor()));
	ParticleSpawner.spawn(glitter, world, new StaticInterp<>(position), 10, 10, (aFloat, particleBuilder) -> {
		particleBuilder.setScale((float) RandUtil.nextDouble(0.3, 1));
		particleBuilder.setAlphaFunction(new InterpFloatInOut(0.3f, (float) RandUtil.nextDouble(0.6, 1)));
		particleBuilder.setRender(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
		particleBuilder.setLifetime(RandUtil.nextInt(20, 30));
		particleBuilder.setScaleFunction(new InterpScale(1, 0));

		double radius = 1;
		double theta = 2.0f * (float) Math.PI * RandUtil.nextFloat();
		double r = radius * RandUtil.nextFloat();
		double x = r * MathHelper.cos((float) theta);
		double z = r * MathHelper.sin((float) theta);
		particleBuilder.setPositionOffset(new Vec3d(x, RandUtil.nextDouble(-radius, radius), z).normalize().scale(RandUtil.nextFloat((float) ((maxPotency - potency) / maxPotency / 10.0))));
		particleBuilder.addMotion(particleBuilder.getPositionOffset().scale(-1.0 / RandUtil.nextDouble(10, 30)));
	});
}
 
Example 26
Project: enderutilities   File: TileEntityDrawbridge.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private void changeInventorySize(int changeAmount)
{
    int newSize = MathHelper.clamp(this.getSlotCount() + changeAmount, 1, MAX_LENGTH_ADVANCED);

    // Shrinking the inventory, only allowed if there are no items in the slots-to-be-removed
    if (changeAmount < 0)
    {
        int changeFinal = 0;

        for (int slot = this.getSlotCount() - 1; slot >= newSize && slot >= 1; slot--)
        {
            if (this.itemHandlerDrawbridge.getStackInSlot(slot).isEmpty())
            {
                changeFinal--;
            }
            else
            {
                break;
            }
        }

        newSize = MathHelper.clamp(this.getSlotCount() + changeFinal, 1, MAX_LENGTH_ADVANCED);
    }

    if (newSize >= 1 && newSize <= MAX_LENGTH_ADVANCED)
    {
        this.setMaxLength(newSize);
    }
}
 
Example 27
Project: enderutilities   File: TileEntityHandyChest.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setStorageTier(World world, int tier)
{
    this.chestTier = MathHelper.clamp(tier, 0, MAX_TIER);
    this.invSize = INV_SIZES[this.chestTier];

    this.initStorage(this.invSize, world.isRemote);
}
 
Example 28
Project: Valkyrien-Skies   File: MixinEntity.java    License: Apache License 2.0 5 votes vote down vote up
@Redirect(method = "createRunningParticles", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;floor(D)I", ordinal = 2))
public int runningParticlesThirdFloor(double d) {
    if (searchVector == null) {
        return MathHelper.floor(d);
    } else {
        return MathHelper.floor(searchVector.Z);
    }
}
 
Example 29
Project: AdvancedRocketry   File: TileRailgun.java    License: MIT License 5 votes vote down vote up
@Override
public void onModuleUpdated(ModuleBase module) {
	if(module == textBox) {
		if(textBox.getText().isEmpty())
			minStackTransferSize = 1;
		else
			minStackTransferSize = MathHelper.clamp(Integer.parseInt(textBox.getText()),1, 64);
		PacketHandler.sendToServer(new PacketMachine(this, (byte)4));
	}
}
 
Example 30
Project: Valkyrien-Skies   File: MixinEntity.java    License: Apache License 2.0 5 votes vote down vote up
@Redirect(method = "createRunningParticles", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;floor(D)I", ordinal = 0))
    public int runningParticlesFirstFloor(double d) {
        PhysicsWrapperEntity worldBelow = thisAsDraggable.getWorldBelowFeet();

        if (worldBelow == null) {
            searchVector = null;
            return MathHelper.floor(d);
        } else {
            searchVector = new Vector(this.posX, this.posY - 0.20000000298023224D, this.posZ);
//            searchVector.transform(worldBelow.wrapping.coordTransform.wToLTransform);
            worldBelow.getPhysicsObject().getShipTransformationManager().getCurrentTickTransform()
                .transform(searchVector, TransformType.GLOBAL_TO_SUBSPACE);
            return MathHelper.floor(searchVector.X);
        }
    }
 
Example 31
Project: Valkyrien-Skies   File: MixinEntityLivingBase.java    License: Apache License 2.0 5 votes vote down vote up
private boolean isOnLadderOriginalButSlightlyOptimized() {
    int i = MathHelper.floor(this.posX);
    int j = MathHelper.floor(this.getEntityBoundingBox().minY);
    int k = MathHelper.floor(this.posZ);
    BlockPos blockpos = new BlockPos(i, j, k);
    IBlockState iblockstate = this.world.getBlockState(blockpos);
    return net.minecraftforge.common.ForgeHooks
        .isLivingOnLadder(iblockstate, world, new BlockPos(i, j, k),
            EntityLivingBase.class.cast(this));
}
 
Example 32
Project: fabric-carpet   File: ShapesRenderer.java    License: MIT License 5 votes vote down vote up
public static void drawSphereFaces(Tessellator tessellator, BufferBuilder builder,
                                       float cx, float cy, float cz,
                                       float r, int subd,
                                       float red, float grn, float blu, float alpha)
{

    float step = (float)Math.PI / (subd/2);
    int num_steps180 = (int)(Math.PI / step)+1;
    int num_steps360 = (int)(2*Math.PI / step);
    for (int i = 0; i <= num_steps360; i++)
    {
        float theta = i * step;
        float thetaprime = theta+step;
        builder.begin(GL11.GL_QUAD_STRIP, VertexFormats.POSITION_COLOR);
        for (int j = 0; j <= num_steps180; j++)
        {
            float phi = j * step;
            float x = r * MathHelper.sin(phi) * MathHelper.cos(theta);
            float z = r * MathHelper.sin(phi) * MathHelper.sin(theta);
            float y = r * MathHelper.cos(phi);
            float xp = r * MathHelper.sin(phi) * MathHelper.cos(thetaprime);
            float zp = r * MathHelper.sin(phi) * MathHelper.sin(thetaprime);
            builder.vertex(x + cx, y + cy, z + cz).color(red, grn, blu, alpha).next();
            builder.vertex(xp + cx, y + cy, zp + cz).color(red, grn, blu, alpha).next();
        }
        tessellator.draw();
    }
}
 
Example 33
Project: Wizardry   File: SpellRing.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get a modifier in this ring between the range. Returns the attribute value, modified by burnout and multipliers, for use in a spell.
 *
 * @param world
 * @param attribute The attribute you want. List in {@link AttributeRegistry} for default attributeModifiers.
 * @param data      The data of the spell being cast, used to get caster-specific modifiers.
 * @return The {@code double} potency of a modifier.
 */
public final float getAttributeValue(World world, Attribute attribute, SpellData data) {
	if (module == null) return 0;

	float current = FixedPointUtils.getDoubleFromNBT(informationTag, attribute.getNbtName());

	AttributeRange range = module.getAttributeRanges().get(attribute);

	current = MathHelper.clamp(current, range.min, range.max);
	current = data.getCastTimeValue(attribute, current);
	current *= getPlayerBurnoutMultiplier(world, data);
	current *= getPowerMultiplier();

	return current;
}
 
Example 34
Project: MineLittlePony   File: IPegasus.java    License: MIT License 5 votes vote down vote up
/**
 * Determines angle used to animate wing flaps whilst flying/swimming.
 *
 * @param ticks Partial render ticks
 */
default float getWingRotationFactor(float ticks) {
    if (getAttributes().isSwimming) {
        return (MathHelper.sin(ticks * 0.136f) / 2) + ROTATE_270;
    }
    if (isFlying()) {
        return MathHelper.sin(ticks * 0.536f) + ROTATE_270 + 0.4f;
    }
    return WING_ROT_Z_SNEAK;
}
 
Example 35
Project: Signals   File: TileEntityTeleportRail.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Pair<MCPos, MCPos> getAllowedDestinationRange(World destinationDimension){
    if(destinationDimension == null) return null;

    double moveFactor = getWorld().provider.getMovementFactor() / destinationDimension.provider.getMovementFactor();
    double destX = MathHelper.clamp(getPos().getX() * moveFactor, destinationDimension.getWorldBorder().minX() + 16.0D, destinationDimension.getWorldBorder().maxX() - 16.0D);
    double destZ = MathHelper.clamp(getPos().getZ() * moveFactor, destinationDimension.getWorldBorder().minZ() + 16.0D, destinationDimension.getWorldBorder().maxZ() - 16.0D);
    destX = MathHelper.clamp((int)destX, -29999872, 29999872);
    destZ = MathHelper.clamp((int)destZ, -29999872, 29999872);

    int maxDiff = 8;
    MCPos min = new MCPos(destinationDimension, new BlockPos(destX - maxDiff, 0, destZ - maxDiff));
    MCPos max = new MCPos(destinationDimension, new BlockPos(destX + maxDiff, destinationDimension.getActualHeight(), destZ + maxDiff));
    return new ImmutablePair<MCPos, MCPos>(min, max);
}
 
Example 36
Project: ToroQuest   File: EntityMonolithEye.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void attackWithArrow(EntityLivingBase target) {

		int charge = 2 + rand.nextInt(10);

		EntityArrow entityarrow = new EntityTippedArrow(this.world, this);
		double d0 = target.posX - this.posX;
		double d1 = target.getEntityBoundingBox().minY + (double) (target.height / 3.0F) - entityarrow.posY;
		double d2 = target.posZ - this.posZ;
		double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2);
		entityarrow.shoot(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F,
				(float) (14 - this.world.getDifficulty().getDifficultyId() * 4));
		int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.POWER, this);
		int j = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.PUNCH, this);
		entityarrow.setDamage((double) (charge * 2.0F) + this.rand.nextGaussian() * 0.25D
				+ (double) ((float) this.world.getDifficulty().getDifficultyId() * 0.11F));

		if (i > 0) {
			entityarrow.setDamage(entityarrow.getDamage() + (double) i * 0.5D + 0.5D);
		}

		if (j > 0) {
			entityarrow.setKnockbackStrength(j);
		}

		if (rand.nextBoolean()) {
			entityarrow.setFire(100);
		}

		this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
		this.world.spawnEntity(entityarrow);
	}
 
Example 37
Project: Sakura_mod   File: BlockSakuraDiamondOre.java    License: MIT License 5 votes vote down vote up
@Override
public int getExpDrop(IBlockState state, net.minecraft.world.IBlockAccess world, BlockPos pos, int fortune) {
    Random rand = world instanceof World ? ((World) world).rand : new Random();
    if (this.getItemDropped(state, rand, fortune) != Item.getItemFromBlock(this)) {
        return MathHelper.getInt(rand, 3, 7);
    }
    return 0;
}
 
Example 38
Project: TFC2   File: ModelBigCat.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the model's various rotation angles. For bipeds, par1 and par2 are used for animating the movement of arms
 * and legs, where par1 represents the time(so that arms and legs swing back and forth) and par2 represents how
 * "far" arms and legs can swing at most.
 */
@Override
public void setRotationAngles(float p_78087_1_, float p_78087_2_, float p_78087_3_, float p_78087_4_, float p_78087_5_, float p_78087_6_, Entity p_78087_7_)
{
	float f6 = (180F / (float)Math.PI);
	this.HEAD.rotateAngleX = p_78087_5_ / (180F / (float)Math.PI);
	this.HEAD.rotateAngleY = p_78087_4_ / (180F / (float)Math.PI);
	this.LegLEFTFRONT.rotateAngleX = MathHelper.cos(p_78087_1_ * 0.6662F) * 1.0F * p_78087_2_;
	this.LegLEFTREAR.rotateAngleX = MathHelper.cos(p_78087_1_ * 0.4662F + (float)Math.PI) * 1.0F * p_78087_2_;
	this.LegRIGHTFRONT.rotateAngleX = MathHelper.cos(p_78087_1_ * 0.6662F + (float)Math.PI) * 1.0F * p_78087_2_;
	this.LegRIGHTREAR.rotateAngleX = MathHelper.cos(p_78087_1_ * 0.4662F) * 1.0F * p_78087_2_;
}
 
Example 39
Project: ToroQuest   File: TileEntityToroSpawner.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void spawnCreature() {
	EntityGuard entity = new EntityGuard(world);
	EntityLiving entityliving = (EntityLiving) entity;
	entity.setLocationAndAngles((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, MathHelper.wrapDegrees(world.rand.nextFloat() * 360.0F), 0.0F);
	entityliving.rotationYawHead = entityliving.rotationYaw;
	entityliving.renderYawOffset = entityliving.rotationYaw;
	entityliving.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(entityliving)), (IEntityLivingData) null);
	world.spawnEntity(entity);
}
 
Example 40
Project: Wurst7   File: ListWidget.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean mouseDragged(double mouseX, double mouseY, int button,
	double deltaX, double deltaY)
{
	if(super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY))
		return true;
	else if(isVisible() && button == 0 && scrolling)
	{
		if(mouseY < top)
			scrollAmount = 0.0D;
		else if(mouseY > bottom)
			scrollAmount = getMaxScroll();
		else
		{
			double d = getMaxScroll();
			if(d < 1.0D)
				d = 1.0D;
			
			int i = (int)((float)((bottom - top) * (bottom - top))
				/ (float)getMaxPosition());
			i = MathHelper.clamp(i, 32, bottom - top - 8);
			double e = d / (bottom - top - i);
			if(e < 1.0D)
				e = 1.0D;
			
			scrollAmount += deltaY * e;
			capYPosition();
		}
		
		return true;
	}else
		return false;
}