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

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

Introduction

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

Prototype

@Override
public float floatValue() 

Source Link

Document

Returns the value of this MutableFloat as a float.

Usage

From source file:de.sanandrew.mods.claysoldiers.util.soldier.upgrade.misc.UpgradeLeather.java

@Override
public boolean onSoldierHurt(EntityClayMan clayMan, SoldierUpgradeInst upgradeInst, DamageSource source,
        MutableFloat damage) {
    if (!source.isUnblockable()) {
        upgradeInst.getNbtTag().setShort(NBT_USES, (short) (upgradeInst.getNbtTag().getShort(NBT_USES) - 1));
        damage.setValue(Math.max(0.25F, damage.floatValue() / 2.0F));
    }//from w  w  w . j a  va 2 s .co  m

    return false;
}

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   w ww. j  a v a  2s. c  om*/
            .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:com.norconex.collector.http.robot.impl.DefaultRobotsTxtProvider.java

private void parseAgentLines(String baseURL, List<IURLFilter> filters, MutableFloat crawlDelay, String key,
        String value) {/*  w ww.  ja  v  a2s  .  c  om*/
    if ("disallow".equalsIgnoreCase(key)) {
        filters.add(buildURLFilter(baseURL, value, OnMatch.EXCLUDE));
    } else if ("allow".equalsIgnoreCase(key)) {
        filters.add(buildURLFilter(baseURL, value, OnMatch.INCLUDE));
    } else if ("crawl-delay".equalsIgnoreCase(key)) {
        crawlDelay.setValue(NumberUtils.toFloat(value, crawlDelay.floatValue()));
    }
    //note that sitemap directives are handled by ISitemapsResolver
}

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

@Override
public boolean onPreHit(Entity e, DamageSource dmgSource, MutableFloat dmg) {
    if (super.onPreHit(e, dmgSource, dmg)) {
        if (e instanceof EntityLivingBase) {
            EntityLivingBase elb = ((EntityLivingBase) e);

            if (!(this.shooterCache instanceof ITurretInst && ((ITurretInst) this.shooterCache)
                    .getUpgradeProcessor().hasUpgrade(Upgrades.ENDER_MEDIUM))) {
                if (elb.isImmuneToFire()) {
                    return false;
                }/*from w w  w. j a va2 s  .  c  o  m*/
            } else {
                if (!elb.isImmuneToFire()) {
                    dmg.setValue(dmg.floatValue() * 1.25F);
                }
            }

            this.prevMaxHurtResistantTime = elb.maxHurtResistantTime;
            elb.maxHurtResistantTime = 10;
        }

        return true;
    } else {
        return false;
    }
}

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;
        }/*w w w  .  j  a 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.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 ww  w  .j  a  v  a  2  s . com*/

    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 float getAIMoveSpeed() {
    MutableFloat speed = new MutableFloat(0.5F);

    for (SoldierUpgradeInst upg : this.p_upgrades.values()) {
        upg.getUpgrade().getAiMoveSpeed(this, upg, speed);
    }//from w  ww.j  a  v a 2s  . 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();
        }/*  w w w.j  a v  a2  s .  com*/
    }

    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: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 va  2  s.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:org.apache.apex.malhar.lib.window.accumulation.SumFloat.java

@Override
public Float getOutput(MutableFloat accumulatedValue) {
    return accumulatedValue.floatValue();
}