Search in sources :

Example 41 with IGalacticraftWorldProvider

use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider 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 42 with IGalacticraftWorldProvider

use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.

the class GCPlayerHandler method onPlayerCloned.

// @SubscribeEvent
// public void onPlayerLogout(PlayerLoggedOutEvent event)
// {
// if (event.player instanceof EntityPlayerMP)
// {
// this.onPlayerLogout((EntityPlayerMP) event.player);
// }
// }
// 
// @SubscribeEvent
// public void onPlayerRespawn(PlayerRespawnEvent event)
// {
// if (event.player instanceof EntityPlayerMP)
// {
// this.onPlayerRespawn((EntityPlayerMP) event.player);
// }
// }
@SubscribeEvent
public void onPlayerCloned(PlayerEvent.Clone event) {
    GCPlayerStats oldStats = GCPlayerStats.get(event.getOriginal());
    GCPlayerStats newStats = GCPlayerStats.get(event.getEntityPlayer());
    newStats.copyFrom(oldStats, !event.isWasDeath() || event.getOriginal().world.getGameRules().getBoolean("keepInventory"));
    if (event.getOriginal() instanceof EntityPlayerMP && event.getEntityPlayer() instanceof EntityPlayerMP) {
        TileEntityTelemetry.updateLinkedPlayer((EntityPlayerMP) event.getOriginal(), (EntityPlayerMP) event.getEntityPlayer());
    }
    if (event.isWasDeath() && event.getOriginal() instanceof EntityPlayerMP) {
        UUID uu = event.getOriginal().getPersistentID();
        if (event.getOriginal().world.provider instanceof IGalacticraftWorldProvider) {
            Integer timeA = deathTimes.get(uu);
            int bb = ((EntityPlayerMP) event.getOriginal()).mcServer.getTickCounter();
            if (timeA != null && (bb - timeA) < 1500) {
                String msg = EnumColor.YELLOW + GCCoreUtil.translate("commands.gchouston.help.1") + " " + EnumColor.WHITE + GCCoreUtil.translate("commands.gchouston.help.2");
                event.getOriginal().sendMessage(new TextComponentString(msg));
            }
            deathTimes.put(uu, bb);
        } else {
            deathTimes.remove(uu);
        }
    }
}
Also used : IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TextComponentString(net.minecraft.util.text.TextComponentString) UUID(java.util.UUID) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) TextComponentString(net.minecraft.util.text.TextComponentString) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 43 with IGalacticraftWorldProvider

use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.

the class GCPlayerHandler method checkShield.

protected void checkShield(EntityPlayerMP playerMP, GCPlayerStats playerStats) {
    if (playerMP.ticksExisted % 20 == 0 && playerMP.world.provider instanceof IGalacticraftWorldProvider) {
        if (((IGalacticraftWorldProvider) playerMP.world.provider).shouldCorrodeArmor()) {
            ItemStack shieldController = playerStats.getExtendedInventory().getStackInSlot(10);
            boolean valid = false;
            if (!shieldController.isEmpty()) {
                int gearID = GalacticraftRegistry.findMatchingGearID(shieldController, EnumExtendedInventorySlot.SHIELD_CONTROLLER);
                if (gearID != -1) {
                    valid = true;
                }
            }
            if (!valid) {
                for (ItemStack armor : playerMP.getArmorInventoryList()) {
                    if (!armor.isEmpty() && armor.getItem() instanceof ItemArmor && !(armor.getItem() instanceof IArmorCorrosionResistant)) {
                        armor.damageItem(1, playerMP);
                    }
                }
            }
        }
    }
}
Also used : IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) ItemArmor(net.minecraft.item.ItemArmor) ItemStack(net.minecraft.item.ItemStack) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) IArmorCorrosionResistant(micdoodle8.mods.galacticraft.api.item.IArmorCorrosionResistant)

Example 44 with IGalacticraftWorldProvider

use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.

the class EventHandlerGC method overrideSkyColor.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void overrideSkyColor(EntityViewRenderEvent.FogColors event) {
    // Disable any night vision effects on the sky, if the planet has no atmosphere
    if (event.getEntity() instanceof EntityLivingBase && ((EntityLivingBase) event.getEntity()).isPotionActive(MobEffects.NIGHT_VISION)) {
        WorldClient worldclient = Minecraft.getMinecraft().world;
        if (worldclient.provider instanceof IGalacticraftWorldProvider && ((IGalacticraftWorldProvider) worldclient.provider).hasNoAtmosphere() && event.getState().getMaterial() == Material.AIR && !((IGalacticraftWorldProvider) worldclient.provider).hasBreathableAtmosphere()) {
            Vec3d vec = worldclient.getFogColor(1.0F);
            event.setRed((float) vec.x);
            event.setGreen((float) vec.y);
            event.setBlue((float) vec.z);
            return;
        }
        if (worldclient.provider.getSkyRenderer() instanceof SkyProviderOverworld && event.getEntity().posY > Constants.OVERWORLD_SKYPROVIDER_STARTHEIGHT) {
            Vec3d vec = TransformerHooks.getFogColorHook(event.getEntity().world);
            event.setRed((float) vec.x);
            event.setGreen((float) vec.y);
            event.setBlue((float) vec.z);
            return;
        }
    }
}
Also used : IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) EntityLivingBase(net.minecraft.entity.EntityLivingBase) SkyProviderOverworld(micdoodle8.mods.galacticraft.core.client.SkyProviderOverworld) WorldClient(net.minecraft.client.multiplayer.WorldClient) Vec3d(net.minecraft.util.math.Vec3d) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 45 with IGalacticraftWorldProvider

use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.

the class EventHandlerGC method onEntityFall.

@SubscribeEvent
public void onEntityFall(LivingFallEvent event) {
    if (event.getEntityLiving() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getEntityLiving();
        if (player.getRidingEntity() instanceof EntityAutoRocket || player.getRidingEntity() instanceof EntityLanderBase) {
            event.setDistance(0.0F);
            event.setCanceled(true);
            return;
        }
    }
    if (event.getEntityLiving().world.provider instanceof IGalacticraftWorldProvider) {
        event.setDistance(event.getDistance() * ((IGalacticraftWorldProvider) event.getEntityLiving().world.provider).getFallDamageModifier());
    }
}
Also used : EntityLanderBase(micdoodle8.mods.galacticraft.core.entities.EntityLanderBase) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityAutoRocket(micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)52 ItemStack (net.minecraft.item.ItemStack)16 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)14 BlockPos (net.minecraft.util.math.BlockPos)13 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)9 EntityPlayer (net.minecraft.entity.player.EntityPlayer)9 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)8 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)7 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)7 ResourceLocation (net.minecraft.util.ResourceLocation)7 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)6 IBlockState (net.minecraft.block.state.IBlockState)6 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)6 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 Block (net.minecraft.block.Block)5 WorldClient (net.minecraft.client.multiplayer.WorldClient)5 EnumFacing (net.minecraft.util.EnumFacing)5 WorldServer (net.minecraft.world.WorldServer)5 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)4 TileEntity (net.minecraft.tileentity.TileEntity)4