Example usage for org.apache.commons.lang3.mutable MutableFloat MutableFloat

List of usage examples for org.apache.commons.lang3.mutable MutableFloat MutableFloat

Introduction

In this page you can find the example usage for org.apache.commons.lang3.mutable MutableFloat MutableFloat.

Prototype

public MutableFloat(final String value) throws NumberFormatException 

Source Link

Document

Constructs a new MutableFloat parsing the given string.

Usage

From source file:de.sanandrew.mods.particledeco.tileentity.TileEntityParticleBox.java

@Override
public void updateEntity() {
    this.ticksExisted++;

    if (this.worldObj.isRemote && this.ticksExisted % 2 == 0) {
        if (this.prevColor != this.particleData.particleColor) {
            this.particleColorSplit = SAPUtils.getRgbaFromColorInt(this.particleData.particleColor)
                    .getColorFloatArray();
            this.prevColor = this.particleData.particleColor;
        }/* ww  w . j ava 2s  . c o  m*/

        MutableFloat[] motions = new MutableFloat[] { new MutableFloat(0.0F), new MutableFloat(0.0F),
                new MutableFloat(0.0F) };
        this.changeDirection(motions[0], motions[1], motions[2]);

        EntityParticle particle = new EntityDustFX(this.worldObj, this.xCoord + 0.5F, this.yCoord + 0.5F,
                this.zCoord + 0.5F, this.particleData.particleHeight, this.particleData.particleSpeed,
                motions[0].getValue(), motions[1].getValue(), motions[2].getValue());
        particle.setParticleColorRNG(this.particleColorSplit[0], this.particleColorSplit[1],
                this.particleColorSplit[2]);
        particle.setBrightness(0xF0);
        SAPEffectRenderer.INSTANCE.addEffect(particle);
    }
}

From source file:com.norconex.collector.http.robot.impl.DefaultRobotsTxtProvider.java

@Override
public synchronized RobotsTxt getRobotsTxt(DefaultHttpClient httpClient, String url) {
    String baseURL = getBaseURL(url);
    RobotsTxt robotsTxt = robotsTxtCache.get(baseURL);
    if (robotsTxt != null) {
        return robotsTxt;
    }//from w w w.j a  va2s  . c o  m

    String userAgent = ((String) httpClient.getParams().getParameter(CoreProtocolPNames.USER_AGENT))
            .toLowerCase();
    String robotsURL = baseURL + "/robots.txt";
    HttpGet method = new HttpGet(robotsURL);
    List<String> sitemapLocations = new ArrayList<String>();
    List<IURLFilter> filters = new ArrayList<IURLFilter>();
    MutableFloat crawlDelay = new MutableFloat(RobotsTxt.UNSPECIFIED_CRAWL_DELAY);
    try {
        HttpResponse response = httpClient.execute(method);
        InputStreamReader isr = new InputStreamReader(response.getEntity().getContent());
        BufferedReader br = new BufferedReader(isr);
        boolean agentAlreadyMatched = false;
        boolean doneWithAgent = false;
        String line;
        while ((line = br.readLine()) != null) {
            String key = line.replaceFirst("(.*?)(:.*)", "$1").trim();
            String value = line.replaceFirst("(.*?:)(.*)", "$2").trim();
            if ("sitemap".equalsIgnoreCase(key)) {
                sitemapLocations.add(value);
            }
            if (!doneWithAgent) {
                if ("user-agent".equalsIgnoreCase(key)) {
                    if (matchesUserAgent(userAgent, value)) {
                        agentAlreadyMatched = true;
                    } else if (agentAlreadyMatched) {
                        doneWithAgent = true;
                    }
                }
                if (agentAlreadyMatched) {
                    parseAgentLines(baseURL, filters, crawlDelay, key, value);
                }
            }
        }
        isr.close();
    } catch (Exception e) {
        LOG.warn("Not able to obtain robots.txt at: " + robotsURL, e);
    }

    robotsTxt = new RobotsTxt(filters.toArray(new IURLFilter[] {}), crawlDelay.floatValue());
    robotsTxtCache.put(baseURL, robotsTxt);
    return robotsTxt;
}

From source file:de.sanandrew.mods.turretmod.client.render.world.RenderTurretPointed.java

private void renderLabel(EntityTurret turret, double x, double y, double z, LabelEntry lbl) {
    final Minecraft mc = Minecraft.getMinecraft();
    final FontRenderer fontrenderer = mc.fontRenderer;
    final float scale = 0.010F;
    final List<ILabelElement> fltElem = this.elements.stream().filter(el -> el.showElement(turret))
            .sorted((el1, el2) -> Integer.compare(el2.getPriority(), el1.getPriority()))
            .collect(Collectors.toList());

    lbl.maxWidth = fltElem.stream()//from   www.j av  a2  s  . c o m
            .collect(() -> new MutableFloat(MIN_WIDTH),
                    (f, l) -> f.setValue(Math.max(f.getValue(), l.getWidth(turret, fontrenderer))),
                    (f1, f2) -> f1.setValue(Math.max(f1.getValue(), f2.getValue())))
            .floatValue();
    lbl.maxHeight = fltElem.stream().collect(() -> new MutableFloat(0.0F),
            (f, l) -> f.add(l.getHeight(turret, fontrenderer)), (f1, f2) -> f1.add(f2.getValue())).floatValue();

    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder buffer = tessellator.getBuffer();

    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y + (turret.isUpsideDown() ? 1.4F : 0.7F), z);
    GlStateManager.glNormal3f(0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(lbl.angleY, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(lbl.angleX, 1.0F, 0.0F, 0.0F);
    GlStateManager.scale(-scale, -scale, scale);
    GlStateManager.translate(-lbl.maxWidth / 2.0D, -32.0D, 0.0D);
    GlStateManager.disableLighting();
    GlStateManager.depthMask(false);
    GlStateManager.disableDepth();
    GlStateManager.enableBlend();
    GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA,
            GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
    GlStateManager.disableTexture2D();
    GlStateManager.shadeModel(GL11.GL_SMOOTH);

    buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
    float alphaMulti = Math.min(1.0F, lbl.progress);
    ColorObj clrTop = new ColorObj(0x0050FF00 | (Math.max(Math.round(0xCC * alphaMulti), 4) << 24));
    ColorObj clrBottom = new ColorObj(0x00288000 | (Math.max(Math.round(0xCC * alphaMulti), 4) << 24));
    ColorObj clrMain = new ColorObj(0x00001000 | (Math.max(Math.round(0xA0 * alphaMulti), 4) << 24));

    // main bg
    addQuad(buffer, -2.0D, -2.0D, lbl.maxWidth + 2.0D, lbl.maxHeight + 2.0D, clrMain);

    // inner frame [top, bottom, left, right]
    addQuad(buffer, -3.0D, -3.0D, lbl.maxWidth + 3.0D, -2.0D, clrTop);
    addQuad(buffer, -3.0D, lbl.maxHeight + 2.0D, lbl.maxWidth + 3.0D, lbl.maxHeight + 3.0D, clrBottom);
    addQuad(buffer, -3.0D, -2.0D, -2.0D, lbl.maxHeight + 2.0D, clrTop, clrBottom);
    addQuad(buffer, lbl.maxWidth + 2.0D, -2.0D, lbl.maxWidth + 3.0D, lbl.maxHeight + 2.0D, clrTop, clrBottom);

    // outer frame [top, bottom, left, right]
    addQuad(buffer, -3.0D, -4.0D, lbl.maxWidth + 3.0D, -3.0D, clrMain);
    addQuad(buffer, -3.0D, lbl.maxHeight + 3.0D, lbl.maxWidth + 3.0D, lbl.maxHeight + 4.0D, clrMain);
    addQuad(buffer, -4.0D, -3.0D, -3.0D, lbl.maxHeight + 3.0D, clrMain);
    addQuad(buffer, lbl.maxWidth + 3.0D, -3.0D, lbl.maxWidth + 4.0D, lbl.maxHeight + 3.0D, clrMain);

    if (lbl.progress >= 1.0F) {
        final MutableFloat currHeight = new MutableFloat(0.0F);
        fltElem.forEach(elem -> {
            elem.doRenderQuads(turret, lbl.maxWidth, lbl.progress - 1.0F, fontrenderer, currHeight.floatValue(),
                    buffer);
            currHeight.add(elem.getHeight(turret, fontrenderer));
        });
    }

    tessellator.draw();
    GlStateManager.shadeModel(GL11.GL_FLAT);
    GlStateManager.enableTexture2D();

    if (lbl.progress >= 1.0F) {
        final MutableFloat currHeight = new MutableFloat(0.0F);
        fltElem.forEach(elem -> {
            GlStateManager.pushMatrix();
            GlStateManager.translate(0.0F, currHeight.floatValue(), 0.0F);
            elem.doRenderTextured(turret, lbl.maxWidth, lbl.progress - 1.0F, fontrenderer);
            GlStateManager.popMatrix();
            currHeight.add(elem.getHeight(turret, fontrenderer));
        });
    }

    GlStateManager.enableDepth();
    GlStateManager.depthMask(true);
    GlStateManager.disableBlend();
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.popMatrix();
}

From source file:de.sanandrew.mods.turretmod.entity.projectile.EntityTurretProjectile.java

private void doCollisionCheck() {
    Vec3d posVec = new Vec3d(this.posX, this.posY, this.posZ);
    Vec3d futurePosVec = new Vec3d(this.posX + this.motionX, this.posY + this.motionY,
            this.posZ + this.motionZ);
    RayTraceResult hitObj = this.world.rayTraceBlocks(posVec, futurePosVec, false, true, false);

    posVec = new Vec3d(this.posX, this.posY, this.posZ);
    futurePosVec = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);

    if (hitObj != null) {
        futurePosVec = new Vec3d(hitObj.hitVec.x, hitObj.hitVec.y, hitObj.hitVec.z);
    }/*from  w ww  . jav  a2  s  . c om*/

    Entity entity = null;
    AxisAlignedBB checkBB = this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ)
            .grow(1.0D);
    List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, checkBB);
    double minDist = 0.0D;

    for (Entity collidedEntity : list) {
        if (collidedEntity.canBeCollidedWith() && collidedEntity != this.shooterCache) {
            AxisAlignedBB collisionAABB = collidedEntity.getEntityBoundingBox().grow(0.3D);
            RayTraceResult interceptObj = collisionAABB.calculateIntercept(posVec, futurePosVec);

            if (interceptObj != null) {
                double vecDistance = posVec.distanceTo(interceptObj.hitVec);

                if (!EntityTurret.class.isAssignableFrom(collidedEntity.getClass())
                        && (vecDistance < minDist || minDist == 0.0D)) {
                    entity = collidedEntity;
                    minDist = vecDistance;
                }
            }
        }
    }

    if (entity != null) {
        hitObj = new RayTraceResult(entity);
    }

    if (hitObj != null && hitObj.entityHit != null && hitObj.entityHit instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) hitObj.entityHit;

        if (player.capabilities.disableDamage) {
            hitObj = null;
        }
    }

    if (hitObj != null) {
        if (hitObj.entityHit != null) {
            MutableFloat dmg = new MutableFloat(this.getDamage());

            DamageSource damagesource = this.getProjDamageSource(hitObj.entityHit);

            if (this.isBurning() && !(hitObj.entityHit instanceof EntityEnderman)) {
                hitObj.entityHit.setFire(5);
            }

            boolean preHitVelocityChanged = hitObj.entityHit.velocityChanged;
            boolean preHitAirBorne = hitObj.entityHit.isAirBorne;
            double preHitMotionX = hitObj.entityHit.motionX;
            double preHitMotionY = hitObj.entityHit.motionY;
            double preHitMotionZ = hitObj.entityHit.motionZ;
            if (this.onPreHit(hitObj.entityHit, damagesource, dmg)
                    && hitObj.entityHit.attackEntityFrom(damagesource, dmg.floatValue())) {
                hitObj.entityHit.velocityChanged = preHitVelocityChanged;
                hitObj.entityHit.isAirBorne = preHitAirBorne;
                hitObj.entityHit.motionX = preHitMotionX;
                hitObj.entityHit.motionY = preHitMotionY;
                hitObj.entityHit.motionZ = preHitMotionZ;

                this.onPostHit(hitObj.entityHit, damagesource);
                if (hitObj.entityHit instanceof EntityLivingBase) {
                    EntityLivingBase living = (EntityLivingBase) hitObj.entityHit;

                    if (!this.world.isRemote) {
                        living.setArrowCountInEntity(living.getArrowCountInEntity() + 1);
                    }

                    if (living instanceof EntityCreature && this.shooterCache instanceof EntityTurret) {
                        TmrUtils.INSTANCE.setEntityTarget((EntityCreature) living,
                                (EntityTurret) this.shooterCache);
                    }

                    double deltaX = this.posX - living.posX;
                    double deltaZ = this.posZ - living.posZ;

                    while (deltaX * deltaX + deltaZ * deltaZ < 0.0001D) {
                        deltaZ = (Math.random() - Math.random()) * 0.01D;
                        deltaX = (Math.random() - Math.random()) * 0.01D;
                    }

                    this.knockBackEntity(living, deltaX, deltaZ);

                    if (this.shooterCache instanceof EntityLivingBase) {
                        EnchantmentHelper.applyThornEnchantments(living, this.shooterCache);
                        EnchantmentHelper.applyArthropodEnchantments((EntityLivingBase) this.shooterCache,
                                living);
                    }
                }
            }
        } else {
            this.onBlockHit(hitObj.getBlockPos());
        }

        this.processHit(hitObj);
    }
}

From source file:de.sanandrew.mods.claysoldiers.entity.EntityClayMan.java

@Override
public boolean attackEntityFrom(DamageSource source, float damage) {
    if (!(source.getEntity() instanceof EntityPlayer) && source != IDisruptable.DISRUPT_DAMAGE) {
        if (this.ridingEntity != null && rand.nextInt(4) == 0) {
            this.ridingEntity.attackEntityFrom(source, damage);
            return false;
        }//from   www  .  ja  v  a2s .c o  m
    } else {
        damage = 10000.0F;
    }

    if (!this.worldObj.isRemote) {
        for (Entry<ASoldierUpgrade, SoldierUpgradeInst> upgrade : this.p_upgrades.entrySet()) {
            SoldierUpgradeInst upg = upgrade.getValue();
            MutableFloat newDamage = new MutableFloat(damage);
            if (upg.getUpgrade().onSoldierHurt(this, upg, source, newDamage)) {
                return false;
            } else {
                damage = newDamage.floatValue();
            }
        }
    }

    return super.attackEntityFrom(source, damage);
}

From source file:de.sanandrew.mods.claysoldiers.entity.EntityClayMan.java

@Override
public float getAIMoveSpeed() {
    MutableFloat speed = new MutableFloat(0.5F);

    for (SoldierUpgradeInst upg : this.p_upgrades.values()) {
        upg.getUpgrade().getAiMoveSpeed(this, upg, speed);
    }//from  w  w w.j av a 2  s  .  c  o  m
    for (SoldierEffectInst eff : this.p_effects.values()) {
        eff.getEffect().getAiMoveSpeed(this, eff, speed);
    }

    return speed.floatValue();
}

From source file:de.sanandrew.mods.claysoldiers.entity.EntityClayMan.java

@Override
protected void updateEntityActionState() {
    //BUGFIX: fixes movement in blocks w/o collision box (snow layer, torches, tall grass, possibly cobweb?, etc.)
    if (!this.hasPath()) {
        if (this.entityToAttack != null) {
            this.setPathToEntity(BugfixHelper.getPathEntityToEntity(this.worldObj, this, this.entityToAttack,
                    16.0F, true, false, false, true));
        } else if (this.p_targetFollow != null) {
            this.setPathToEntity(BugfixHelper.getPathEntityToEntity(this.worldObj, this, this.p_targetFollow,
                    16.0F, true, false, false, true));
        } else if ((this.rand.nextInt(180) == 0 || this.rand.nextInt(120) == 0 || this.fleeingTick > 0)
                && this.entityAge < 100) {
            this.updateWanderPath();
        }/*  www.j a  va 2  s  . c o  m*/
    }

    super.updateEntityActionState();

    if (!this.worldObj.isRemote) {
        this.p_entitiesInRange = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getTargetArea());

        if (this.entityToAttack == null) {
            if (rand.nextInt(4) != 0 && p_targetFollow == null) {
                Collection<EntityClayMan> claymen = this.getSoldiersInRange();
                for (EntityClayMan uberhaxornova : claymen) {
                    if (uberhaxornova.isDead || rand.nextInt(3) != 0) {
                        continue;
                    }

                    if (!this.checkIfValidTarget(uberhaxornova)) {
                        continue;
                    }

                    this.entityToAttack = uberhaxornova;

                    break;
                }
            } else {
                if (this.p_targetFollow == null) {
                    Collection<EntityItem> items = this.getItemsInRange();
                    items: for (EntityItem seamus : items) {
                        if (!this.canEntityBeSeen(seamus)) {
                            continue;
                        }

                        ASoldierUpgrade upgrade = SoldierUpgrades.getUpgrade(seamus.getEntityItem());
                        if (upgrade != null) {
                            if (this.hasUpgrade(upgrade)
                                    || !upgrade.canBePickedUp(this, seamus.getEntityItem(), null)) {
                                continue;
                            } else {
                                for (SoldierUpgradeInst upgradeInst : this.p_upgrades.values()) {
                                    if (upgrade == upgradeInst.getUpgrade() || !upgrade.canBePickedUp(this,
                                            seamus.getEntityItem(), upgradeInst.getUpgrade())) {
                                        continue items;
                                    }
                                }
                            }
                        } else {
                            continue;
                        }

                        this.p_targetFollow = seamus;

                        break;
                    }
                } else {
                    if (this.p_targetFollow.isDead) {
                        this.p_targetFollow = null;
                    } else if (!this.canEntityBeSeen(this.p_targetFollow)) {
                        this.p_targetFollow = null;
                    }

                    if (this.p_targetFollow instanceof EntityItem
                            && this.p_targetFollow.getDistanceToEntity(this) < 0.5F) {
                        EntityItem itemEntity = (EntityItem) this.p_targetFollow;
                        ASoldierUpgrade upgrade = SoldierUpgrades.getUpgrade(itemEntity.getEntityItem());
                        if (upgrade != null) {
                            this.addUpgrade(upgrade, itemEntity.getEntityItem());

                            if (itemEntity.getEntityItem().stackSize <= 0) {
                                itemEntity.setDead();
                            }

                            this.p_targetFollow = null;
                        }
                    } else if (this.p_targetFollow instanceof IMount) {
                        if (this.p_targetFollow.riddenByEntity != null) {
                            this.p_targetFollow = null;
                        } else if (this.p_targetFollow.getDistanceToEntity(this) < 0.5D) {
                            this.mountEntity(this.p_targetFollow);
                            this.p_targetFollow = null;
                        }
                    }
                }
                if (this.p_targetFollow == null && this.ridingEntity == null) {
                    Collection<IMount> items = this.getMountsInRange();
                    for (IMount mount : items) {
                        EntityLivingBase slyfox = (EntityLivingBase) mount;
                        if (this.rand.nextInt(4) != 0 || !this.canEntityBeSeen(slyfox)
                                || slyfox.riddenByEntity != null) {
                            continue;
                        }

                        this.p_targetFollow = slyfox;
                        break;
                    }
                }
            }
        } else {
            if (this.entityToAttack.isDead || !this.canEntityBeSeen(this.entityToAttack)
                    || (this.entityToAttack instanceof EntityClayMan
                            && !this.checkIfValidTarget((EntityClayMan) this.entityToAttack))) {
                this.entityToAttack = null;
            } else if (this.attackTime == 0) {
                this.attackTime = 5;

                MutableFloat atkRng = new MutableFloat(this.riddenByEntity != null ? 0.6F : 0.7F);

                for (SoldierUpgradeInst upg : this.p_upgrades.values()) {
                    upg.getUpgrade().getAttackRange(this, upg, this.entityToAttack, atkRng);
                }

                if (this.getDistanceToEntity(this.entityToAttack) < atkRng.floatValue()
                        && this.entityToAttack instanceof EntityLivingBase
                        && !this.entityToAttack.isEntityInvulnerable()) {
                    EntityLivingBase target = (EntityLivingBase) this.entityToAttack;
                    if (target.hurtTime == 0) {
                        MutableFloat damage = new MutableFloat(ModConfig.soldierBaseDamage);
                        if (target instanceof EntityClayMan) {
                            EntityClayMan soldierTarget = (EntityClayMan) target;
                            soldierTarget.knockBack = Triplet.with(0.8D, 0.8D, 0.8D);
                            for (SoldierUpgradeInst upg : this.p_upgrades.values()) {
                                upg.getUpgrade().onSoldierAttack(this, upg, soldierTarget, damage);
                            }
                        }

                        if (target.attackEntityFrom(DamageSource.causeMobDamage(this), damage.getValue())
                                && target instanceof EntityClayMan) {
                            for (SoldierUpgradeInst upg : this.p_upgrades.values()) {
                                upg.getUpgrade().onSoldierDamage(this, upg, (EntityClayMan) target);
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:org.apache.apex.malhar.lib.window.accumulation.SumFloat.java

@Override
public MutableFloat defaultAccumulatedValue() {
    return new MutableFloat(0.);
}

From source file:org.apache.apex.malhar.lib.window.accumulation.SumTest.java

@Test
public void SumTest() {
    SumInt si = new SumInt();
    SumLong sl = new SumLong();
    SumFloat sf = new SumFloat();
    SumDouble sd = new SumDouble();

    Assert.assertEquals(new MutableInt(10), si.accumulate(si.defaultAccumulatedValue(), 10));
    Assert.assertEquals(new MutableInt(11), si.accumulate(new MutableInt(1), 10));
    Assert.assertEquals(new MutableInt(22), si.merge(new MutableInt(1), new MutableInt(21)));

    Assert.assertEquals(new MutableLong(10L), sl.accumulate(sl.defaultAccumulatedValue(), 10L));
    Assert.assertEquals(new MutableLong(22L), sl.accumulate(new MutableLong(2L), 20L));
    Assert.assertEquals(new MutableLong(41L), sl.merge(new MutableLong(32L), new MutableLong(9L)));

    Assert.assertEquals(new MutableFloat(9.0F), sf.accumulate(sf.defaultAccumulatedValue(), 9.0F));
    Assert.assertEquals(new MutableFloat(22.5F), sf.accumulate(new MutableFloat(2.5F), 20F));
    Assert.assertEquals(new MutableFloat(41.0F), sf.merge(new MutableFloat(33.1F), new MutableFloat(7.9F)));

    Assert.assertEquals(new MutableDouble(9.0), sd.accumulate(sd.defaultAccumulatedValue(), 9.0));
    Assert.assertEquals(new MutableDouble(22.5), sd.accumulate(new MutableDouble(2.5), 20.0));
    Assert.assertEquals(new MutableDouble(41.0), sd.merge(new MutableDouble(33.1), new MutableDouble(7.9)));
}