Search in sources :

Example 66 with GCPlayerStats

use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.

the class GCPlayerHandler method updateFeet.

protected static void updateFeet(EntityPlayerMP player, double motionX, double motionZ) {
    double motionSqrd = motionX * motionX + motionZ * motionZ;
    if (motionSqrd > 0.001D && !player.capabilities.isFlying) {
        int iPosX = MathHelper.floor(player.posX);
        int iPosY = MathHelper.floor(player.posY - 0.05);
        int iPosZ = MathHelper.floor(player.posZ);
        // If the block below is the moon block
        IBlockState state = player.world.getBlockState(new BlockPos(iPosX, iPosY, iPosZ));
        if (state.getBlock() == GCBlocks.blockMoon) {
            // And is the correct metadata (moon turf)
            if (state.getValue(BlockBasicMoon.BASIC_TYPE_MOON) == BlockBasicMoon.EnumBlockBasicMoon.MOON_TURF) {
                GCPlayerStats stats = GCPlayerStats.get(player);
                // If it has been long enough since the last step
                if (stats.getDistanceSinceLastStep() > 0.35D) {
                    Vector3 pos = new Vector3(player);
                    // Set the footprint position to the block below and add random number to stop z-fighting
                    pos.y = MathHelper.floor(player.posY - 1D) + player.world.rand.nextFloat() / 100.0F;
                    // Adjust footprint to left or right depending on step count
                    switch(stats.getLastStep()) {
                        case 0:
                            float a = (-player.rotationYaw + 90F) / Constants.RADIANS_TO_DEGREES;
                            pos.translate(new Vector3(MathHelper.sin(a) * 0.25F, 0, MathHelper.cos(a) * 0.25F));
                            break;
                        case 1:
                            a = (-player.rotationYaw - 90F) / Constants.RADIANS_TO_DEGREES;
                            pos.translate(new Vector3(MathHelper.sin(a) * 0.25, 0, MathHelper.cos(a) * 0.25));
                            break;
                    }
                    float rotation = player.rotationYaw - 180;
                    pos = WorldUtil.getFootprintPosition(player.world, rotation, pos, new BlockVec3(player));
                    long chunkKey = ChunkPos.asLong(pos.intX() >> 4, pos.intZ() >> 4);
                    TickHandlerServer.addFootprint(chunkKey, new Footprint(GCCoreUtil.getDimensionID(player.world), pos, rotation, player.getName(), -1), GCCoreUtil.getDimensionID(player.world));
                    // Increment and cap step counter at 1
                    stats.setLastStep((stats.getLastStep() + 1) % 2);
                    stats.setDistanceSinceLastStep(0);
                } else {
                    stats.setDistanceSinceLastStep(stats.getDistanceSinceLastStep() + motionSqrd);
                }
            }
        }
    }
}
Also used : Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 67 with GCPlayerStats

use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.

the class GCPlayerHandler method checkThermalStatus.

protected void checkThermalStatus(EntityPlayerMP player, GCPlayerStats playerStats) {
    if (player.world.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.isEmpty() && !thermalPaddingChestplate.isEmpty() && !thermalPaddingLeggings.isEmpty() && !thermalPaddingBoots.isEmpty()) {
            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.world.provider;
        float thermalLevelMod = provider.getThermalLevelModifier();
        float absThermalLevelMod = Math.abs(thermalLevelMod);
        if (absThermalLevelMod > 0D) {
            int thermalLevelCooldownBase = Math.abs(MathHelper.floor(200 / thermalLevelMod));
            int normaliseCooldown = MathHelper.floor(150 / lowestThermalStrength);
            int thermalLevelTickCooldown = thermalLevelCooldownBase;
            if (thermalLevelTickCooldown < 1) {
                // Prevent divide by zero errors
                thermalLevelTickCooldown = 1;
            }
            if (!thermalPaddingHelm.isEmpty() && !thermalPaddingChestplate.isEmpty() && !thermalPaddingLeggings.isEmpty() && !thermalPaddingBoots.isEmpty()) {
                // 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(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.isEmpty()) {
                thermalLevelTickCooldown += thermalLevelCooldownBase;
            }
            if (!thermalPaddingChestplate.isEmpty()) {
                thermalLevelTickCooldown += thermalLevelCooldownBase;
            }
            if (!thermalPaddingLeggings.isEmpty()) {
                thermalLevelTickCooldown += thermalLevelCooldownBase;
            }
            if (!thermalPaddingBoots.isEmpty()) {
                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(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(last + (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.isEmpty() && !thermalPaddingChestplate.isEmpty() && !thermalPaddingLeggings.isEmpty() && !thermalPaddingBoots.isEmpty());
            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(MobEffects.SLOWNESS, 5, 2, true, true));
                }
                if (playerStats.getThermalLevel() > 15) {
                    player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 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)

Example 68 with GCPlayerStats

use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.

the class GCPlayerHandler method checkOxygen.

protected void checkOxygen(EntityPlayerMP player, GCPlayerStats stats) {
    if ((player.dimension == 0 || player.world.provider instanceof IGalacticraftWorldProvider) && (!(player.dimension == 0 || ((IGalacticraftWorldProvider) player.world.provider).hasBreathableAtmosphere()) || player.posY > GCPlayerHandler.OXYGENHEIGHTLIMIT) && !player.capabilities.isCreativeMode && !(player.getRidingEntity() instanceof EntityLanderBase) && !(player.getRidingEntity() instanceof EntityAutoRocket) && !(player.getRidingEntity() instanceof EntityCelestialFake) && !CompatibilityManager.isAndroid(player)) {
        final ItemStack tankInSlot = stats.getExtendedInventory().getStackInSlot(2);
        final ItemStack tankInSlot2 = stats.getExtendedInventory().getStackInSlot(3);
        final int drainSpacing = OxygenUtil.getDrainSpacing(tankInSlot, tankInSlot2);
        if (tankInSlot.isEmpty()) {
            stats.setAirRemaining(0);
        } else {
            stats.setAirRemaining(tankInSlot.getMaxDamage() - tankInSlot.getItemDamage());
        }
        if (tankInSlot2.isEmpty()) {
            stats.setAirRemaining2(0);
        } else {
            stats.setAirRemaining2(tankInSlot2.getMaxDamage() - tankInSlot2.getItemDamage());
        }
        if (drainSpacing > 0) {
            if ((player.ticksExisted - 1) % drainSpacing == 0 && !OxygenUtil.isAABBInBreathableAirBlock(player) && !stats.isUsingPlanetSelectionGui()) {
                int toTake = 1;
                // Take 1 oxygen from Tank 1
                if (stats.getAirRemaining() > 0) {
                    tankInSlot.damageItem(1, player);
                    stats.setAirRemaining(stats.getAirRemaining() - 1);
                    toTake = 0;
                }
                // Alternatively, take 1 oxygen from Tank 2
                if (toTake > 0 && stats.getAirRemaining2() > 0) {
                    tankInSlot2.damageItem(1, player);
                    stats.setAirRemaining2(stats.getAirRemaining2() - 1);
                    toTake = 0;
                }
            }
        } else {
            if ((player.ticksExisted - 1) % 60 == 0) {
                if (OxygenUtil.isAABBInBreathableAirBlock(player)) {
                    if (stats.getAirRemaining() < 90 && !tankInSlot.isEmpty()) {
                        stats.setAirRemaining(Math.min(stats.getAirRemaining() + 1, tankInSlot.getMaxDamage() - tankInSlot.getItemDamage()));
                    }
                    if (stats.getAirRemaining2() < 90 && !tankInSlot2.isEmpty()) {
                        stats.setAirRemaining2(Math.min(stats.getAirRemaining2() + 1, tankInSlot2.getMaxDamage() - tankInSlot2.getItemDamage()));
                    }
                } else {
                    if (stats.getAirRemaining() > 0) {
                        stats.setAirRemaining(stats.getAirRemaining() - 1);
                    }
                    if (stats.getAirRemaining2() > 0) {
                        stats.setAirRemaining2(stats.getAirRemaining2() - 1);
                    }
                }
            }
        }
        final boolean airEmpty = stats.getAirRemaining() <= 0 && stats.getAirRemaining2() <= 0;
        if (player.isOnLadder()) {
            stats.setOxygenSetupValid(stats.isLastOxygenSetupValid());
        } else {
            stats.setOxygenSetupValid(!((!OxygenUtil.hasValidOxygenSetup(player) || airEmpty) && !OxygenUtil.isAABBInBreathableAirBlock(player)));
        }
        if (!player.world.isRemote && player.isEntityAlive()) {
            if (!stats.isOxygenSetupValid()) {
                GCCoreOxygenSuffocationEvent suffocationEvent = new GCCoreOxygenSuffocationEvent.Pre(player);
                MinecraftForge.EVENT_BUS.post(suffocationEvent);
                if (!suffocationEvent.isCanceled()) {
                    if (stats.getDamageCounter() == 0) {
                        stats.setDamageCounter(ConfigManagerCore.suffocationCooldown);
                        player.attackEntityFrom(DamageSourceGC.oxygenSuffocation, ConfigManagerCore.suffocationDamage * (2 + stats.getIncrementalDamage()) / 2);
                        if (ConfigManagerCore.hardMode)
                            stats.setIncrementalDamage(stats.getIncrementalDamage() + 1);
                        GCCoreOxygenSuffocationEvent suffocationEventPost = new GCCoreOxygenSuffocationEvent.Post(player);
                        MinecraftForge.EVENT_BUS.post(suffocationEventPost);
                    }
                } else
                    stats.setOxygenSetupValid(true);
            } else
                stats.setIncrementalDamage(0);
        }
    } else if ((player.ticksExisted - 1) % 20 == 0 && !player.capabilities.isCreativeMode && stats.getAirRemaining() < 90) {
        stats.setAirRemaining(stats.getAirRemaining() + 1);
        stats.setAirRemaining2(stats.getAirRemaining2() + 1);
    } else if (player.capabilities.isCreativeMode) {
        stats.setAirRemaining(90);
        stats.setAirRemaining2(90);
    } else {
        stats.setOxygenSetupValid(true);
    }
}
Also used : EntityLanderBase(micdoodle8.mods.galacticraft.core.entities.EntityLanderBase) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) EntityCelestialFake(micdoodle8.mods.galacticraft.core.entities.EntityCelestialFake) GCCoreOxygenSuffocationEvent(micdoodle8.mods.galacticraft.api.event.oxygen.GCCoreOxygenSuffocationEvent) EntityAutoRocket(micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket) ItemStack(net.minecraft.item.ItemStack) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint)

Example 69 with GCPlayerStats

use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.

the class GCPlayerHandler method checkGear.

// private void onPlayerLogout(EntityPlayerMP player)
// {
// }
// 
// private void onPlayerRespawn(EntityPlayerMP player)
// {
// GCPlayerStats oldData = this.playerStatsMap.remove(player.getPersistentID());
// GCPlayerStats stats = GCPlayerStats.get(player);
// 
// if (oldData != null)
// {
// stats.copyFrom(oldData, false);
// }
// 
// stats.player = new WeakReference<EntityPlayerMP>(player);
// }
public static void checkGear(EntityPlayerMP player, GCPlayerStats stats, boolean forceSend) {
    stats.setMaskInSlot(stats.getExtendedInventory().getStackInSlot(0));
    stats.setGearInSlot(stats.getExtendedInventory().getStackInSlot(1));
    stats.setTankInSlot1(stats.getExtendedInventory().getStackInSlot(2));
    stats.setTankInSlot2(stats.getExtendedInventory().getStackInSlot(3));
    stats.setParachuteInSlot(stats.getExtendedInventory().getStackInSlot(4));
    stats.setFrequencyModuleInSlot(stats.getExtendedInventory().getStackInSlot(5));
    stats.setThermalHelmetInSlot(stats.getExtendedInventory().getStackInSlot(6));
    stats.setThermalChestplateInSlot(stats.getExtendedInventory().getStackInSlot(7));
    stats.setThermalLeggingsInSlot(stats.getExtendedInventory().getStackInSlot(8));
    stats.setThermalBootsInSlot(stats.getExtendedInventory().getStackInSlot(9));
    stats.setShieldControllerInSlot(stats.getExtendedInventory().getStackInSlot(10));
    if (stats.getFrequencyModuleInSlot() != stats.getLastFrequencyModuleInSlot() || forceSend) {
        if (player.mcServer != null) {
            if (stats.getFrequencyModuleInSlot().isEmpty()) {
                GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.REMOVE, EnumExtendedInventorySlot.FREQUENCY_MODULE);
                TileEntityTelemetry.frequencyModulePlayer(stats.getLastFrequencyModuleInSlot(), player, true);
            } else if (stats.getLastFrequencyModuleInSlot().isEmpty()) {
                int gearID = GalacticraftRegistry.findMatchingGearID(stats.getFrequencyModuleInSlot(), EnumExtendedInventorySlot.FREQUENCY_MODULE);
                if (gearID >= 0) {
                    GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.ADD, EnumExtendedInventorySlot.FREQUENCY_MODULE, gearID);
                    TileEntityTelemetry.frequencyModulePlayer(stats.getFrequencyModuleInSlot(), player, false);
                }
            }
        }
        stats.setLastFrequencyModuleInSlot(stats.getFrequencyModuleInSlot());
    }
    if (stats.getMaskInSlot() != stats.getLastMaskInSlot() || forceSend) {
        if (stats.getMaskInSlot().isEmpty()) {
            GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.REMOVE, EnumExtendedInventorySlot.MASK);
        } else if (stats.getLastMaskInSlot().isEmpty() || forceSend) {
            int gearID = GalacticraftRegistry.findMatchingGearID(stats.getMaskInSlot(), EnumExtendedInventorySlot.MASK);
            if (gearID >= 0) {
                GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.ADD, EnumExtendedInventorySlot.MASK, gearID);
            }
        }
        stats.setLastMaskInSlot(stats.getMaskInSlot());
    }
    if (stats.getGearInSlot() != stats.getLastGearInSlot() || forceSend) {
        if (stats.getGearInSlot().isEmpty()) {
            GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.REMOVE, EnumExtendedInventorySlot.GEAR);
        } else if (stats.getGearInSlot().getItem() == GCItems.oxygenGear && (stats.getLastGearInSlot().isEmpty() || forceSend)) {
            int gearID = GalacticraftRegistry.findMatchingGearID(stats.getGearInSlot(), EnumExtendedInventorySlot.GEAR);
            if (gearID >= 0) {
                GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.ADD, EnumExtendedInventorySlot.GEAR, gearID);
            }
        }
        stats.setLastGearInSlot(stats.getGearInSlot());
    }
    if (stats.getTankInSlot1() != stats.getLastTankInSlot1() || forceSend) {
        if (stats.getTankInSlot1().isEmpty()) {
            GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.REMOVE, EnumExtendedInventorySlot.LEFT_TANK);
            stats.setAirRemaining(0);
            GCPlayerHandler.sendAirRemainingPacket(player, stats);
        } else if (stats.getLastTankInSlot1().isEmpty() || forceSend) {
            int gearID = GalacticraftRegistry.findMatchingGearID(stats.getTankInSlot1(), EnumExtendedInventorySlot.LEFT_TANK);
            if (gearID >= 0) {
                GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.ADD, EnumExtendedInventorySlot.LEFT_TANK, gearID);
            }
            if (!stats.getMaskInSlot().isEmpty() && !stats.getGearInSlot().isEmpty()) {
                stats.setAirRemaining(stats.getTankInSlot1().getMaxDamage() - stats.getTankInSlot1().getItemDamage());
                GCPlayerHandler.sendAirRemainingPacket(player, stats);
            }
        } else // if the else is reached then both tankInSlot and lastTankInSlot are non-null
        if (stats.getTankInSlot1().getItem() != stats.getLastTankInSlot1().getItem()) {
            int gearID = GalacticraftRegistry.findMatchingGearID(stats.getTankInSlot1(), EnumExtendedInventorySlot.LEFT_TANK);
            if (gearID >= 0) {
                GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.ADD, EnumExtendedInventorySlot.LEFT_TANK, gearID);
            }
            if (!stats.getMaskInSlot().isEmpty() && !stats.getGearInSlot().isEmpty()) {
                stats.setAirRemaining(stats.getTankInSlot1().getMaxDamage() - stats.getTankInSlot1().getItemDamage());
                GCPlayerHandler.sendAirRemainingPacket(player, stats);
            }
        }
        stats.setLastTankInSlot1(stats.getTankInSlot1());
    }
    if (stats.getTankInSlot2() != stats.getLastTankInSlot2() || forceSend) {
        if (stats.getTankInSlot2().isEmpty()) {
            GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.REMOVE, EnumExtendedInventorySlot.RIGHT_TANK);
            stats.setAirRemaining2(0);
            GCPlayerHandler.sendAirRemainingPacket(player, stats);
        } else if (stats.getLastTankInSlot2().isEmpty() || forceSend) {
            int gearID = GalacticraftRegistry.findMatchingGearID(stats.getTankInSlot2(), EnumExtendedInventorySlot.RIGHT_TANK);
            if (gearID >= 0) {
                GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.ADD, EnumExtendedInventorySlot.RIGHT_TANK, gearID);
            }
            if (!stats.getMaskInSlot().isEmpty() && !stats.getGearInSlot().isEmpty()) {
                stats.setAirRemaining2(stats.getTankInSlot2().getMaxDamage() - stats.getTankInSlot2().getItemDamage());
                GCPlayerHandler.sendAirRemainingPacket(player, stats);
            }
        } else // if the else is reached then both tankInSlot and lastTankInSlot are non-null
        if (stats.getTankInSlot2().getItem() != stats.getLastTankInSlot2().getItem()) {
            int gearID = GalacticraftRegistry.findMatchingGearID(stats.getTankInSlot2(), EnumExtendedInventorySlot.RIGHT_TANK);
            if (gearID >= 0) {
                GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.ADD, EnumExtendedInventorySlot.RIGHT_TANK, gearID);
            }
            if (!stats.getMaskInSlot().isEmpty() && !stats.getGearInSlot().isEmpty()) {
                stats.setAirRemaining2(stats.getTankInSlot2().getMaxDamage() - stats.getTankInSlot2().getItemDamage());
                GCPlayerHandler.sendAirRemainingPacket(player, stats);
            }
        }
        stats.setLastTankInSlot2(stats.getTankInSlot2());
    }
    if (stats.getParachuteInSlot() != stats.getLastParachuteInSlot() || forceSend) {
        if (stats.isUsingParachute()) {
            if (stats.getParachuteInSlot().isEmpty()) {
                GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.REMOVE, EnumExtendedInventorySlot.PARACHUTE);
            } else if (forceSend || stats.getLastParachuteInSlot().isEmpty() || stats.getParachuteInSlot().getItemDamage() != stats.getLastParachuteInSlot().getItemDamage()) {
                int gearID = GalacticraftRegistry.findMatchingGearID(stats.getParachuteInSlot(), EnumExtendedInventorySlot.PARACHUTE);
                if (gearID >= 0) {
                    GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.ADD, EnumExtendedInventorySlot.PARACHUTE, stats.getParachuteInSlot().getItemDamage());
                }
            }
        }
        stats.setLastParachuteInSlot(stats.getParachuteInSlot());
    }
    if (stats.getThermalHelmetInSlot() != stats.getLastThermalHelmetInSlot() || forceSend) {
        ThermalArmorEvent armorEvent = new ThermalArmorEvent(0, stats.getThermalHelmetInSlot());
        MinecraftForge.EVENT_BUS.post(armorEvent);
        if (armorEvent.armorResult != ThermalArmorEvent.ArmorAddResult.NOTHING) {
            if (stats.getThermalHelmetInSlot().isEmpty() || armorEvent.armorResult == ThermalArmorEvent.ArmorAddResult.REMOVE) {
                GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.REMOVE, EnumExtendedInventorySlot.THERMAL_HELMET);
            } else if (armorEvent.armorResult == ThermalArmorEvent.ArmorAddResult.ADD && (stats.getLastThermalHelmetInSlot().isEmpty() || forceSend)) {
                int gearID = GalacticraftRegistry.findMatchingGearID(stats.getThermalHelmetInSlot(), EnumExtendedInventorySlot.THERMAL_HELMET);
                if (gearID >= 0) {
                    GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.ADD, EnumExtendedInventorySlot.THERMAL_HELMET, gearID);
                }
            }
        }
        stats.setLastThermalHelmetInSlot(stats.getThermalHelmetInSlot());
    }
    if (stats.getThermalChestplateInSlot() != stats.getLastThermalChestplateInSlot() || forceSend) {
        ThermalArmorEvent armorEvent = new ThermalArmorEvent(1, stats.getThermalChestplateInSlot());
        MinecraftForge.EVENT_BUS.post(armorEvent);
        if (armorEvent.armorResult != ThermalArmorEvent.ArmorAddResult.NOTHING) {
            if (stats.getThermalChestplateInSlot().isEmpty() || armorEvent.armorResult == ThermalArmorEvent.ArmorAddResult.REMOVE) {
                GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.REMOVE, EnumExtendedInventorySlot.THERMAL_CHESTPLATE);
            } else if (armorEvent.armorResult == ThermalArmorEvent.ArmorAddResult.ADD && (stats.getLastThermalChestplateInSlot().isEmpty() || forceSend)) {
                int gearID = GalacticraftRegistry.findMatchingGearID(stats.getThermalChestplateInSlot(), EnumExtendedInventorySlot.THERMAL_CHESTPLATE);
                if (gearID >= 0) {
                    GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.ADD, EnumExtendedInventorySlot.THERMAL_CHESTPLATE, gearID);
                }
            }
        }
        stats.setLastThermalChestplateInSlot(stats.getThermalChestplateInSlot());
    }
    if (stats.getThermalLeggingsInSlot() != stats.getLastThermalLeggingsInSlot() || forceSend) {
        ThermalArmorEvent armorEvent = new ThermalArmorEvent(2, stats.getThermalLeggingsInSlot());
        MinecraftForge.EVENT_BUS.post(armorEvent);
        if (armorEvent.armorResult != ThermalArmorEvent.ArmorAddResult.NOTHING) {
            if (stats.getThermalLeggingsInSlot().isEmpty() || armorEvent.armorResult == ThermalArmorEvent.ArmorAddResult.REMOVE) {
                GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.REMOVE, EnumExtendedInventorySlot.THERMAL_LEGGINGS);
            } else if (armorEvent.armorResult == ThermalArmorEvent.ArmorAddResult.ADD && (stats.getLastThermalLeggingsInSlot().isEmpty() || forceSend)) {
                int gearID = GalacticraftRegistry.findMatchingGearID(stats.getThermalLeggingsInSlot(), EnumExtendedInventorySlot.THERMAL_LEGGINGS);
                if (gearID >= 0) {
                    GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.ADD, EnumExtendedInventorySlot.THERMAL_LEGGINGS, gearID);
                }
            }
        }
        stats.setLastThermalLeggingsInSlot(stats.getThermalLeggingsInSlot());
    }
    if (stats.getThermalBootsInSlot() != stats.getLastThermalBootsInSlot() || forceSend) {
        ThermalArmorEvent armorEvent = new ThermalArmorEvent(3, stats.getThermalBootsInSlot());
        MinecraftForge.EVENT_BUS.post(armorEvent);
        if (armorEvent.armorResult != ThermalArmorEvent.ArmorAddResult.NOTHING) {
            if (stats.getThermalBootsInSlot().isEmpty() || armorEvent.armorResult == ThermalArmorEvent.ArmorAddResult.REMOVE) {
                GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.REMOVE, EnumExtendedInventorySlot.THERMAL_BOOTS);
            } else if (armorEvent.armorResult == ThermalArmorEvent.ArmorAddResult.ADD && (stats.getLastThermalBootsInSlot().isEmpty() || forceSend)) {
                int gearID = GalacticraftRegistry.findMatchingGearID(stats.getThermalBootsInSlot(), EnumExtendedInventorySlot.THERMAL_BOOTS);
                if (gearID >= 0) {
                    GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.ADD, EnumExtendedInventorySlot.THERMAL_BOOTS, gearID);
                }
            }
        }
        stats.setLastThermalBootsInSlot(stats.getThermalBootsInSlot());
    }
    if ((stats.getShieldControllerInSlot() != stats.getLastShieldControllerInSlot() || forceSend) && GalacticraftCore.isPlanetsLoaded) {
        if (stats.getShieldControllerInSlot().isEmpty()) {
            GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.REMOVE, EnumExtendedInventorySlot.SHIELD_CONTROLLER);
        } else if (stats.getShieldControllerInSlot().getItem() == VenusItems.basicItem && (stats.getLastShieldControllerInSlot().isEmpty() || forceSend)) {
            int gearID = GalacticraftRegistry.findMatchingGearID(stats.getShieldControllerInSlot(), EnumExtendedInventorySlot.SHIELD_CONTROLLER);
            if (gearID >= 0) {
                GCPlayerHandler.sendGearUpdatePacket(player, EnumModelPacketType.ADD, EnumExtendedInventorySlot.SHIELD_CONTROLLER, gearID);
            }
        }
        stats.setLastShieldControllerInSlot(stats.getShieldControllerInSlot());
    }
}
Also used : TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint)

Example 70 with GCPlayerStats

use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats in project Galacticraft by micdoodle8.

the class GCPlayerHandler method sendPlanetList.

protected void sendPlanetList(EntityPlayerMP player, GCPlayerStats stats) {
    HashMap<String, Integer> map;
    if (player.ticksExisted % 50 == 0) // Check for genuine update - e.g. maybe some other player created a space station or changed permissions
    // CAUTION: possible server load due to dimension loading, if any planets or moons were (contrary to GC default) set to hotload
    {
        map = WorldUtil.getArrayOfPossibleDimensions(stats.getSpaceshipTier(), player);
    } else {
        map = WorldUtil.getArrayOfPossibleDimensionsAgain(stats.getSpaceshipTier(), player);
    }
    String temp = "";
    int count = 0;
    for (Entry<String, Integer> entry : map.entrySet()) {
        temp = temp.concat(entry.getKey() + (count < map.entrySet().size() - 1 ? "?" : ""));
        count++;
    }
    if (!temp.equals(stats.getSavedPlanetList()) || (player.ticksExisted % 100 == 0)) {
        boolean canCreateStations = PermissionAPI.hasPermission(player, Constants.PERMISSION_CREATE_STATION);
        GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_DIMENSION_LIST, GCCoreUtil.getDimensionID(player.world), new Object[] { PlayerUtil.getName(player), temp, canCreateStations }), player);
        stats.setSavedPlanetList(temp);
    // GCLog.debug("Sending to " + PlayerUtil.getName(player) + ": " + temp);
    }
}
Also used : PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) TextComponentString(net.minecraft.util.text.TextComponentString) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint)

Aggregations

GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)88 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)55 ItemStack (net.minecraft.item.ItemStack)43 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)19 CommandException (net.minecraft.command.CommandException)16 WrongUsageException (net.minecraft.command.WrongUsageException)16 TextComponentString (net.minecraft.util.text.TextComponentString)16 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)14 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)12 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)12 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)12 SpaceStationWorldData (micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData)10 TileEntity (net.minecraft.tileentity.TileEntity)10 BlockPos (net.minecraft.util.math.BlockPos)10 WorldServer (net.minecraft.world.WorldServer)10 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)8 Entity (net.minecraft.entity.Entity)7 PotionEffect (net.minecraft.potion.PotionEffect)7 ChatComponentText (net.minecraft.util.ChatComponentText)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6