Search in sources :

Example 1 with RGBAValues

use of de.sanandrew.core.manpack.util.helpers.SAPUtils.RGBAValues in project ClaySoldiersMod by SanAndreasP.

the class RenderStatDisplayOverlay method getContrastTextColor.

private static int getContrastTextColor(int bkgColor) {
    RGBAValues splitClr = SAPUtils.getRgbaFromColorInt(bkgColor);
    int yiq = ((splitClr.getRed() * 299) + (splitClr.getGreen() * 587) + (splitClr.getBlue() * 144)) / 1000;
    return (yiq >= 128) ? 0x000000 : 0xFFFFFF;
}
Also used : RGBAValues(de.sanandrew.core.manpack.util.helpers.SAPUtils.RGBAValues)

Example 2 with RGBAValues

use of de.sanandrew.core.manpack.util.helpers.SAPUtils.RGBAValues in project ClaySoldiersMod by SanAndreasP.

the class TileEntityClayNexus method updateEntity.

@Override
public void updateEntity() {
    if (this.p_searchArea == null || this.p_damageArea == null) {
        this.p_searchArea = AxisAlignedBB.getBoundingBox(this.xCoord - 63.0D, this.yCoord - 63.0D, this.zCoord - 63.0D, this.xCoord + 64.0D, this.yCoord + 64.0D, this.zCoord + 64.0D);
        this.p_damageArea = AxisAlignedBB.getBoundingBox(this.xCoord + 0.1D, this.yCoord + 0.1D, this.zCoord + 0.1D, this.xCoord + 0.9D, this.yCoord + 0.9D, this.zCoord + 0.9D);
    }
    super.updateEntity();
    boolean isRsPowered = this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord) || this.worldObj.getIndirectPowerLevelTo(this.xCoord - 1, this.yCoord, this.zCoord, 1) > 0 || this.worldObj.getIndirectPowerLevelTo(this.xCoord, this.yCoord, this.zCoord + 1, 1) > 0 || this.worldObj.getIndirectPowerLevelTo(this.xCoord, this.yCoord, this.zCoord - 1, 1) > 0 || this.worldObj.getIndirectPowerLevelTo(this.xCoord + 1, this.yCoord, this.zCoord, 1) > 0;
    if (!this.worldObj.isRemote && !this.p_prevRsPowerState && isRsPowered) {
        this.isActive = !this.isActive;
        this.markDirty();
        this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
    }
    this.p_prevRsPowerState = isRsPowered;
    if (this.isActive) {
        if (this.p_health <= 0.0F) {
            this.isActive = false;
        } else {
            this.ticksActive++;
        }
        if (!this.worldObj.isRemote && this.p_health > 0.0F) {
            if (this.ticksActive % 20 == 0) {
                int dmgEnemies = this.countDamagingEnemies();
                if (dmgEnemies > 0) {
                    float healthDamage = 0.5F;
                    if (dmgEnemies > 1) {
                        healthDamage = 0.125F * dmgEnemies;
                    }
                    this.p_health -= healthDamage;
                    if (this.p_health < 0.0F) {
                        this.p_health = 0.0F;
                    }
                    this.markDirty();
                    this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
                }
                List<EntityClayMan> enemies = this.getEnemies(true);
                for (EntityClayMan dalek : enemies) {
                    if (!dalek.hasPath()) {
                        dalek.setPathToEntity(BugfixHelper.getEntityPathToXYZ(this.worldObj, dalek, this.xCoord, this.yCoord, this.zCoord, 64.0F, true, false, false, true));
                    }
                }
            }
            if (ticksActive % this.spawnThrowableInterval == 0 && this.p_throwableSlot != null) {
                List<EntityClayMan> clayMen = getEnemies(true);
                if (clayMen.size() > 0) {
                    EntityClayMan target = clayMen.get(SAPUtils.RNG.nextInt(clayMen.size()));
                    double deltaX = target.posX - this.xCoord + 0.5F;
                    double deltaZ = target.posZ - this.zCoord + 0.5F;
                    try {
                        ISoldierProjectile<? extends EntityThrowable> projectile = this.p_tempThrowableCls.getConstructor(World.class, double.class, double.class, double.class).newInstance(this.worldObj, this.xCoord + 0.5F, this.yCoord + 0.875F, this.zCoord + 0.5F);
                        projectile.initProjectile(target, true, this.p_tempClayTeam.getTeamName());
                        EntityThrowable throwable = projectile.getProjectileEntity();
                        double d2 = (target.posY + target.getEyeHeight()) - 0.10000000298023224D - throwable.posY;
                        float f1 = MathHelper.sqrt_double(deltaX * deltaX + deltaZ * deltaZ) * 0.2F;
                        this.worldObj.spawnEntityInWorld(throwable);
                        throwable.setThrowableHeading(deltaX, d2 + f1, deltaZ, 0.6F, 12.0F);
                    } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
                        FMLLog.log(ClaySoldiersMod.MOD_LOG, Level.ERROR, "%1$s cannot be instantiated! %1$s is not thrown to target!", this.p_tempThrowableCls.getName());
                        e.printStackTrace();
                    }
                }
            }
            if (this.p_soldierSlot != null) {
                if (this.ticksActive % this.spawnSoldierInterval == 0 && this.p_spawningSoldierCounter <= 0) {
                    this.p_spawningSoldierCounter = Math.min(this.soldierSpawnCount, this.maxSoldierCount - this.countTeammates());
                    this.p_prevSpawningSoldierCounter = this.p_spawningSoldierCounter;
                }
                if (ticksActive % 5 == 0) {
                    if (this.p_spawningSoldierCounter > 0) {
                        this.p_spawningSoldierCounter = Math.min(this.p_prevSpawningSoldierCounter, this.maxSoldierCount - this.countTeammates());
                        this.p_prevSpawningSoldierCounter = this.p_spawningSoldierCounter - 1;
                        if (this.p_spawningSoldierCounter > 0) {
                            ItemClayManDoll.spawnClayMan(this.worldObj, this.p_tempClayTeam.getTeamName(), this.xCoord + 0.5F, this.yCoord + 0.2D, this.zCoord + 0.5F).nexusSpawn = true;
                        }
                    }
                }
            }
        }
    }
    if (this.worldObj.isRemote) {
        this.prevSpinAngle = this.spinAngle;
        if (this.isActive && this.p_health > 0.0F) {
            this.spinAngle += 4;
            RGBAValues rgba = SAPUtils.getRgbaFromColorInt(ItemClayManDoll.getTeam(this.p_soldierSlot).getTeamColor());
            ClaySoldiersMod.proxy.spawnParticles(EnumParticleFx.FX_NEXUS, Sextet.with((double) this.xCoord, (double) this.yCoord, (double) this.zCoord, rgba.getRed() / 255.0F, rgba.getGreen() / 255.0F, rgba.getBlue() / 255.0F));
        } else if (this.spinAngle % 90 != 0) {
            this.spinAngle += 2;
        }
        if (this.spinAngle >= 360) {
            this.prevSpinAngle = -1;
            this.spinAngle = 0;
        }
    }
}
Also used : EntityThrowable(net.minecraft.entity.projectile.EntityThrowable) EntityClayMan(de.sanandrew.mods.claysoldiers.entity.EntityClayMan) World(net.minecraft.world.World) InvocationTargetException(java.lang.reflect.InvocationTargetException) RGBAValues(de.sanandrew.core.manpack.util.helpers.SAPUtils.RGBAValues)

Example 3 with RGBAValues

use of de.sanandrew.core.manpack.util.helpers.SAPUtils.RGBAValues in project ClaySoldiersMod by SanAndreasP.

the class RenderClayNexus method renderGlowmap.

private void renderGlowmap(TileEntityClayNexus nexus) {
    float[] colors = new float[] { 1.0F, 1.0F, 1.0F };
    if (nexus.getStackInSlot(0) != null) {
        RGBAValues rgba = SAPUtils.getRgbaFromColorInt(ItemClayManDoll.getTeam(nexus.getStackInSlot(0)).getIconColor());
        colors[0] = rgba.getRed() / 255.0F;
        colors[1] = rgba.getGreen() / 255.0F;
        colors[2] = rgba.getBlue() / 255.0F;
    }
    GL11.glEnable(GL11.GL_BLEND);
    OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
    GL11.glDisable(GL11.GL_ALPHA_TEST);
    float prevBrightX = OpenGlHelper.lastBrightnessX;
    float prevBrightY = OpenGlHelper.lastBrightnessY;
    if (nexus.isActive) {
        int brightness = 0xF0;
        int brightX = brightness % 65536;
        int brightY = brightness / 65536;
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, brightX, brightY);
    }
    this.bindTexture(Textures.NEXUS_GLOWING);
    GL11.glColor3f(colors[0], colors[1], colors[2]);
    this.nexusModel.renderTileEntityGlowmap();
    GL11.glColor3f(1.0F, 1.0F, 1.0F);
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, prevBrightX, prevBrightY);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glDisable(GL11.GL_BLEND);
}
Also used : RGBAValues(de.sanandrew.core.manpack.util.helpers.SAPUtils.RGBAValues)

Example 4 with RGBAValues

use of de.sanandrew.core.manpack.util.helpers.SAPUtils.RGBAValues in project ClaySoldiersMod by SanAndreasP.

the class RenderClayNexus method renderSoldierItem.

private static void renderSoldierItem(TileEntityClayNexus nexus, ItemStack stack, float partTicks) {
    float[] colors = new float[] { 1.0F, 1.0F, 1.0F };
    float itmAngle = nexus.prevSpinAngle + (nexus.spinAngle - nexus.prevSpinAngle) * partTicks - 45.0F;
    RGBAValues rgba = SAPUtils.getRgbaFromColorInt(ItemClayManDoll.getTeam(stack).getIconColor());
    colors[0] = rgba.getRed() / 255.0F;
    colors[1] = rgba.getGreen() / 255.0F;
    colors[2] = rgba.getBlue() / 255.0F;
    GL11.glPushMatrix();
    GL11.glTranslatef(0.0F, 1.225F, 0.0F);
    GL11.glRotatef(180.0F, 1.0F, 0.0F, 0.0F);
    GL11.glScalef(0.25F, 0.25F, 0.25F);
    GL11.glRotatef(itmAngle, 0.0F, 1.0F, 0.0F);
    GL11.glTranslatef(-0.5F, 0.0F, 0.0F);
    GL11.glColor3f(colors[0], colors[1], colors[2]);
    ItemRenderHelper.renderItemIn3D(stack);
    GL11.glColor3f(1.0F, 1.0F, 1.0F);
    GL11.glPopMatrix();
}
Also used : RGBAValues(de.sanandrew.core.manpack.util.helpers.SAPUtils.RGBAValues)

Aggregations

RGBAValues (de.sanandrew.core.manpack.util.helpers.SAPUtils.RGBAValues)4 EntityClayMan (de.sanandrew.mods.claysoldiers.entity.EntityClayMan)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 EntityThrowable (net.minecraft.entity.projectile.EntityThrowable)1 World (net.minecraft.world.World)1