Search in sources :

Example 1 with IItemThermal

use of micdoodle8.mods.galacticraft.api.item.IItemThermal in project Galacticraft by micdoodle8.

the class GCPlayerHandler method checkThermalStatus.

protected void checkThermalStatus(EntityPlayerMP player, GCPlayerStats playerStats) {
    if (player.worldObj.provider instanceof IGalacticraftWorldProvider && !player.capabilities.isCreativeMode && !CompatibilityManager.isAndroid(player)) {
        final ItemStack thermalPaddingHelm = playerStats.getExtendedInventory().getStackInSlot(6);
        final ItemStack thermalPaddingChestplate = playerStats.getExtendedInventory().getStackInSlot(7);
        final ItemStack thermalPaddingLeggings = playerStats.getExtendedInventory().getStackInSlot(8);
        final ItemStack thermalPaddingBoots = playerStats.getExtendedInventory().getStackInSlot(9);
        float lowestThermalStrength = 0.0F;
        if (thermalPaddingHelm != null && thermalPaddingChestplate != null && thermalPaddingLeggings != null && thermalPaddingBoots != null) {
            if (thermalPaddingHelm.getItem() instanceof IItemThermal) {
                lowestThermalStrength += ((IItemThermal) thermalPaddingHelm.getItem()).getThermalStrength();
            }
            if (thermalPaddingChestplate.getItem() instanceof IItemThermal) {
                lowestThermalStrength += ((IItemThermal) thermalPaddingChestplate.getItem()).getThermalStrength();
            }
            if (thermalPaddingLeggings.getItem() instanceof IItemThermal) {
                lowestThermalStrength += ((IItemThermal) thermalPaddingLeggings.getItem()).getThermalStrength();
            }
            if (thermalPaddingBoots.getItem() instanceof IItemThermal) {
                lowestThermalStrength += ((IItemThermal) thermalPaddingBoots.getItem()).getThermalStrength();
            }
            lowestThermalStrength /= 4.0F;
            // It shouldn't be negative, but just in case!
            lowestThermalStrength = Math.abs(lowestThermalStrength);
        }
        IGalacticraftWorldProvider provider = (IGalacticraftWorldProvider) player.worldObj.provider;
        float thermalLevelMod = provider.getThermalLevelModifier();
        float absThermalLevelMod = Math.abs(thermalLevelMod);
        if (absThermalLevelMod > 0D) {
            int thermalLevelCooldownBase = Math.abs(MathHelper.floor_float(200 / thermalLevelMod));
            int normaliseCooldown = MathHelper.floor_float(150 / lowestThermalStrength);
            int thermalLevelTickCooldown = thermalLevelCooldownBase;
            if (thermalLevelTickCooldown < 1) {
                // Prevent divide by zero errors
                thermalLevelTickCooldown = 1;
            }
            if (thermalPaddingHelm != null && thermalPaddingChestplate != null && thermalPaddingLeggings != null && thermalPaddingBoots != null) {
                // If the thermal strength exceeds the dimension's thermal level mod, it can't improve the normalise
                // This factor of 1.5F is chosen so that a combination of Tier 1 and Tier 2 thermal isn't enough to normalise on Venus (three Tier 2, one Tier 1 stays roughly constant)
                float relativeFactor = Math.max(1.0F, absThermalLevelMod / lowestThermalStrength) / 1.5F;
                normaliseCooldown = MathHelper.floor_float(normaliseCooldown / absThermalLevelMod * relativeFactor);
                if (normaliseCooldown < 1) {
                    // Prevent divide by zero errors
                    normaliseCooldown = 1;
                }
                // Player is wearing all required thermal padding items
                if ((player.ticksExisted - 1) % normaliseCooldown == 0) {
                    this.normaliseThermalLevel(player, playerStats, 1);
                }
                thermalLevelMod /= Math.max(1.0F, lowestThermalStrength / 2.0F);
                absThermalLevelMod = Math.abs(thermalLevelMod);
            }
            if (OxygenUtil.isAABBInBreathableAirBlock(player, true)) {
                playerStats.setThermalLevelNormalising(true);
                this.normaliseThermalLevel(player, playerStats, 1);
                // If player is in ambient thermal area, slowly reset to normal
                return;
            }
            // For each piece of thermal equipment being used, slow down the the harmful thermal change slightly
            if (thermalPaddingHelm != null) {
                thermalLevelTickCooldown += thermalLevelCooldownBase;
            }
            if (thermalPaddingChestplate != null) {
                thermalLevelTickCooldown += thermalLevelCooldownBase;
            }
            if (thermalPaddingLeggings != null) {
                thermalLevelTickCooldown += thermalLevelCooldownBase;
            }
            if (thermalPaddingBoots != null) {
                thermalLevelTickCooldown += thermalLevelCooldownBase;
            }
            // Instead of increasing/decreasing the thermal level by a large amount every ~200 ticks, increase/decrease
            // by a small amount each time (still the same average increase/decrease)
            int thermalLevelTickCooldownSingle = MathHelper.floor_double(thermalLevelTickCooldown / absThermalLevelMod);
            if (thermalLevelTickCooldownSingle < 1) {
                // Prevent divide by zero errors
                thermalLevelTickCooldownSingle = 1;
            }
            if ((player.ticksExisted - 1) % thermalLevelTickCooldownSingle == 0) {
                int last = playerStats.getThermalLevel();
                playerStats.setThermalLevel((int) Math.min(Math.max(playerStats.getThermalLevel() + (thermalLevelMod < 0 ? -1 : 1), -22), 22));
                if (playerStats.getThermalLevel() != last) {
                    this.sendThermalLevelPacket(player, playerStats);
                }
            }
            // If the normalisation is outpacing the freeze/overheat
            playerStats.setThermalLevelNormalising(thermalLevelTickCooldownSingle > normaliseCooldown && thermalPaddingHelm != null && thermalPaddingChestplate != null && thermalPaddingLeggings != null && thermalPaddingBoots != null);
            if (!playerStats.isThermalLevelNormalising()) {
                if ((player.ticksExisted - 1) % thermalLevelTickCooldown == 0) {
                    if (Math.abs(playerStats.getThermalLevel()) >= 22) {
                        player.attackEntityFrom(DamageSourceGC.thermal, 1.5F);
                    }
                }
                if (playerStats.getThermalLevel() < -15) {
                    player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, 2, true, true));
                }
                if (playerStats.getThermalLevel() > 15) {
                    player.addPotionEffect(new PotionEffect(Potion.confusion.id, 5, 2, true, true));
                }
            }
        } else // Normalise thermal level if on Space Station or non-modifier planet
        {
            playerStats.setThermalLevelNormalising(true);
            this.normaliseThermalLevel(player, playerStats, 2);
        }
    } else // Normalise thermal level if on Overworld or any non-GC dimension
    {
        playerStats.setThermalLevelNormalising(true);
        this.normaliseThermalLevel(player, playerStats, 3);
    }
}
Also used : IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) IItemThermal(micdoodle8.mods.galacticraft.api.item.IItemThermal) PotionEffect(net.minecraft.potion.PotionEffect) ItemStack(net.minecraft.item.ItemStack) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint)

Aggregations

IItemThermal (micdoodle8.mods.galacticraft.api.item.IItemThermal)1 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)1 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)1 ItemStack (net.minecraft.item.ItemStack)1 PotionEffect (net.minecraft.potion.PotionEffect)1 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)1