Search in sources :

Example 1 with EntityLanderBase

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

the class GCCoreUtil method openParachestInv.

public static void openParachestInv(EntityPlayerMP player, EntityLanderBase landerInv) {
    player.getNextWindowId();
    player.closeContainer();
    int windowId = player.currentWindowId;
    GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_OPEN_PARACHEST_GUI, GCCoreUtil.getDimensionID(player.worldObj), new Object[] { windowId, 1, landerInv.getEntityId() }), player);
    player.openContainer = new ContainerParaChest(player.inventory, landerInv, player);
    player.openContainer.windowId = windowId;
    player.openContainer.onCraftGuiOpened(player);
}
Also used : PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) ContainerParaChest(micdoodle8.mods.galacticraft.core.inventory.ContainerParaChest)

Example 2 with EntityLanderBase

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

the class FreefallHandler method testFreefall.

@SideOnly(Side.CLIENT)
private boolean testFreefall(EntityPlayerSP p, boolean flag) {
    World world = p.worldObj;
    WorldProvider worldProvider = world.provider;
    if (!(worldProvider instanceof IZeroGDimension)) {
        return false;
    }
    ZeroGravityEvent zeroGEvent = new ZeroGravityEvent.InFreefall(p);
    MinecraftForge.EVENT_BUS.post(zeroGEvent);
    if (zeroGEvent.isCanceled()) {
        return false;
    }
    if (this.pjumpticks > 0 || (stats.isSsOnGroundLast() && p.movementInput.jump)) {
        return false;
    }
    if (p.ridingEntity != null) {
        Entity e = p.ridingEntity;
        if (e instanceof EntitySpaceshipBase) {
            return ((EntitySpaceshipBase) e).getLaunched();
        }
        if (e instanceof EntityLanderBase) {
            return false;
        }
    // TODO: should check whether lander has landed (whatever that means)
    // TODO: could check other ridden entities - every entity should have its own freefall check :(
    }
    // This is an "on the ground" check
    if (!flag) {
        return false;
    } else {
        float rY = p.rotationYaw % 360F;
        double zreach = 0D;
        double xreach = 0D;
        if (rY < 80F || rY > 280F) {
            zreach = 0.2D;
        }
        if (rY < 170F && rY > 10F) {
            xreach = 0.2D;
        }
        if (rY < 260F && rY > 100F) {
            zreach = -0.2D;
        }
        if (rY < 350F && rY > 190F) {
            xreach = -0.2D;
        }
        AxisAlignedBB playerReach = p.getEntityBoundingBox().addCoord(xreach, 0, zreach);
        boolean checkBlockWithinReach;
        if (worldProvider instanceof WorldProviderSpaceStation) {
            SpinManager spinManager = ((WorldProviderSpaceStation) worldProvider).getSpinManager();
            checkBlockWithinReach = playerReach.maxX >= spinManager.ssBoundsMinX && playerReach.minX <= spinManager.ssBoundsMaxX && playerReach.maxY >= spinManager.ssBoundsMinY && playerReach.minY <= spinManager.ssBoundsMaxY && playerReach.maxZ >= spinManager.ssBoundsMinZ && playerReach.minZ <= spinManager.ssBoundsMaxZ;
        // Player is somewhere within the space station boundaries
        } else {
            checkBlockWithinReach = true;
        }
        if (checkBlockWithinReach) {
            // Check if the player's bounding box is in the same block coordinates as any non-vacuum block (including torches etc)
            // If so, it's assumed the player has something close enough to grab onto, so is not in freefall
            // Note: breatheable air here means the player is definitely not in freefall
            int xm = MathHelper.floor_double(playerReach.minX);
            int xx = MathHelper.floor_double(playerReach.maxX);
            int ym = MathHelper.floor_double(playerReach.minY);
            int yy = MathHelper.floor_double(playerReach.maxY);
            int zm = MathHelper.floor_double(playerReach.minZ);
            int zz = MathHelper.floor_double(playerReach.maxZ);
            for (int x = xm; x <= xx; x++) {
                for (int y = ym; y <= yy; y++) {
                    for (int z = zm; z <= zz; z++) {
                        // Blocks.air is hard vacuum - we want to check for that, here
                        Block b = world.getBlockState(new BlockPos(x, y, z)).getBlock();
                        if (Blocks.air != b && GCBlocks.brightAir != b) {
                            this.onWall = true;
                            return false;
                        }
                    }
                }
            }
        }
    }
    /*
        if (freefall)
        {
            //If that check didn't produce a result, see if the player is inside the walls
            //TODO: could apply special weightless movement here like Coriolis force - the player is inside the walls,  not touching them, and in a vacuum
            int quadrant = 0;
            double xd = p.posX - this.spinCentreX;
            double zd = p.posZ - this.spinCentreZ;
            if (xd<0)
            {
                if (xd<-Math.abs(zd))
                {
                    quadrant = 2;
                } else
                    quadrant = (zd<0) ? 3 : 1;
            } else
                if (xd>Math.abs(zd))
                {
                    quadrant = 0;
                } else
                    quadrant = (zd<0) ? 3 : 1;

            int ymin = MathHelper.floor_double(p.boundingBox.minY)-1;
            int ymax = MathHelper.floor_double(p.boundingBox.maxY);
            int xmin, xmax, zmin, zmax;

            switch (quadrant)
            {
            case 0:
                xmin = MathHelper.floor_double(p.boundingBox.maxX);
                xmax = this.ssBoundsMaxX - 1;
                zmin = MathHelper.floor_double(p.boundingBox.minZ)-1;
                zmax = MathHelper.floor_double(p.boundingBox.maxZ)+1;
                break;
            case 1:
                xmin = MathHelper.floor_double(p.boundingBox.minX)-1;
                xmax = MathHelper.floor_double(p.boundingBox.maxX)+1;
                zmin = MathHelper.floor_double(p.boundingBox.maxZ);
                zmax = this.ssBoundsMaxZ - 1;
                break;
            case 2:
                zmin = MathHelper.floor_double(p.boundingBox.minZ)-1;
                zmax = MathHelper.floor_double(p.boundingBox.maxZ)+1;
                xmin = this.ssBoundsMinX;
                xmax = MathHelper.floor_double(p.boundingBox.minX);
                break;
            case 3:
            default:
                xmin = MathHelper.floor_double(p.boundingBox.minX)-1;
                xmax = MathHelper.floor_double(p.boundingBox.maxX)+1;
                zmin = this.ssBoundsMinZ;
                zmax = MathHelper.floor_double(p.boundingBox.minZ);
                break;
            }

            //This block search could cost a lot of CPU (but client side) - maybe optimise later
            BLOCKCHECK0:
            for(int x = xmin; x <= xmax; x++)
                for (int z = zmin; z <= zmax; z++)
                    for (int y = ymin; y <= ymax; y++)
                        if (Blocks.air != this.worldProvider.worldObj.getBlock(x, y, z))
                        {
                            freefall = false;
                            break BLOCKCHECK0;
                        }
        }*/
    this.onWall = false;
    return true;
}
Also used : ZeroGravityEvent(micdoodle8.mods.galacticraft.api.event.ZeroGravityEvent) EntitySpaceshipBase(micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase) AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) World(net.minecraft.world.World) SpinManager(micdoodle8.mods.galacticraft.core.dimension.SpinManager) EntityLanderBase(micdoodle8.mods.galacticraft.core.entities.EntityLanderBase) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) WorldProvider(net.minecraft.world.WorldProvider) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.BlockPos) IZeroGDimension(micdoodle8.mods.galacticraft.api.world.IZeroGDimension) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with EntityLanderBase

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

the class GCPlayerHandler method onPlayerUpdate.

public void onPlayerUpdate(EntityPlayerMP player) {
    int tick = player.ticksExisted - 1;
    // This will speed things up a little
    GCPlayerStats stats = GCPlayerStats.get(player);
    if ((ConfigManagerCore.challengeSpawnHandling) && stats.getUnlockedSchematics().size() == 0) {
        if (stats.getStartDimension().length() > 0) {
            stats.setStartDimension("");
        } else {
            // PlayerAPI is installed
            WorldServer worldOld = (WorldServer) player.worldObj;
            try {
                worldOld.getPlayerManager().removePlayer(player);
            } catch (Exception e) {
            }
            worldOld.playerEntities.remove(player);
            worldOld.updateAllPlayersSleepingFlag();
            worldOld.loadedEntityList.remove(player);
            worldOld.onEntityRemoved(player);
            worldOld.getEntityTracker().untrackEntity(player);
            if (player.addedToChunk && worldOld.getChunkProvider().chunkExists(player.chunkCoordX, player.chunkCoordZ)) {
                Chunk chunkOld = worldOld.getChunkFromChunkCoords(player.chunkCoordX, player.chunkCoordZ);
                chunkOld.removeEntity(player);
                chunkOld.setChunkModified();
            }
            WorldServer worldNew = WorldUtil.getStartWorld(worldOld);
            int dimID = GCCoreUtil.getDimensionID(worldNew);
            player.dimension = dimID;
            GCLog.debug("DEBUG: Sending respawn packet to player for dim " + dimID);
            player.playerNetServerHandler.sendPacket(new S07PacketRespawn(dimID, player.worldObj.getDifficulty(), player.worldObj.getWorldInfo().getTerrainType(), player.theItemInWorldManager.getGameType()));
            if (worldNew.provider instanceof WorldProviderSpaceStation) {
                GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(player.worldObj), new Object[] {}), player);
            }
            worldNew.spawnEntityInWorld(player);
            player.setWorld(worldNew);
            player.mcServer.getConfigurationManager().preparePlayer(player, (WorldServer) worldOld);
        }
        // This is a mini version of the code at WorldUtil.teleportEntity
        player.theItemInWorldManager.setWorld((WorldServer) player.worldObj);
        final ITeleportType type = GalacticraftRegistry.getTeleportTypeForDimension(player.worldObj.provider.getClass());
        Vector3 spawnPos = type.getPlayerSpawnLocation((WorldServer) player.worldObj, player);
        ChunkCoordIntPair pair = player.worldObj.getChunkFromChunkCoords(spawnPos.intX() >> 4, spawnPos.intZ() >> 4).getChunkCoordIntPair();
        GCLog.debug("Loading first chunk in new dimension.");
        ((WorldServer) player.worldObj).theChunkProviderServer.loadChunk(pair.chunkXPos, pair.chunkZPos);
        player.setLocationAndAngles(spawnPos.x, spawnPos.y, spawnPos.z, player.rotationYaw, player.rotationPitch);
        type.setupAdventureSpawn(player);
        type.onSpaceDimensionChanged(player.worldObj, player, false);
        player.setSpawnChunk(new BlockPos(spawnPos.intX(), spawnPos.intY(), spawnPos.intZ()), true, GCCoreUtil.getDimensionID(player.worldObj));
        stats.setNewAdventureSpawn(true);
    }
    final boolean isInGCDimension = player.worldObj.provider instanceof IGalacticraftWorldProvider;
    if (tick >= 25) {
        if (ConfigManagerCore.enableSpaceRaceManagerPopup && !stats.hasOpenedSpaceRaceManager()) {
            SpaceRace race = SpaceRaceManager.getSpaceRaceFromPlayer(PlayerUtil.getName(player));
            if (race == null || race.teamName.equals(SpaceRace.DEFAULT_NAME)) {
                GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_OPEN_SPACE_RACE_GUI, GCCoreUtil.getDimensionID(player.worldObj), new Object[] {}), player);
            }
            stats.setOpenedSpaceRaceManager(true);
        }
        if (!stats.hasSentFlags()) {
            GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_STATS, GCCoreUtil.getDimensionID(player.worldObj), stats.getMiscNetworkedStats()), player);
            stats.setSentFlags(true);
        }
    }
    if (stats.getCryogenicChamberCooldown() > 0) {
        stats.setCryogenicChamberCooldown(stats.getCryogenicChamberCooldown() - 1);
    }
    if (!player.onGround && stats.isLastOnGround()) {
        stats.setTouchedGround(true);
    }
    if (stats.getTeleportCooldown() > 0) {
        stats.setTeleportCooldown(stats.getTeleportCooldown() - 1);
    }
    if (stats.getChatCooldown() > 0) {
        stats.setChatCooldown(stats.getChatCooldown() - 1);
    }
    if (stats.getOpenPlanetSelectionGuiCooldown() > 0) {
        stats.setOpenPlanetSelectionGuiCooldown(stats.getOpenPlanetSelectionGuiCooldown() - 1);
        if (stats.getOpenPlanetSelectionGuiCooldown() == 1 && !stats.hasOpenedPlanetSelectionGui()) {
            WorldUtil.toCelestialSelection(player, stats, stats.getSpaceshipTier());
            stats.setHasOpenedPlanetSelectionGui(true);
        }
    }
    if (stats.isUsingParachute()) {
        if (stats.getLastParachuteInSlot() != null) {
            player.fallDistance = 0.0F;
        }
        if (player.onGround) {
            GCPlayerHandler.setUsingParachute(player, stats, false);
        }
    }
    this.checkCurrentItem(player);
    if (stats.isUsingPlanetSelectionGui()) {
        // This sends the planets list again periodically (forcing the Celestial Selection screen to open) in case of server/client lag
        // #PACKETSPAM
        this.sendPlanetList(player, stats);
    }
    /*		if (isInGCDimension || player.usingPlanetSelectionGui)
                {
					player.playerNetServerHandler.ticksForFloatKick = 0;
				}	
		*/
    if (stats.getDamageCounter() > 0) {
        stats.setDamageCounter(stats.getDamageCounter() - 1);
    }
    if (isInGCDimension) {
        if (tick % 10 == 0) {
            boolean doneDungeon = false;
            ItemStack current = player.inventory.getCurrentItem();
            if (current != null && current.getItem() == GCItems.dungeonFinder) {
                this.sendDungeonDirectionPacket(player, stats);
                doneDungeon = true;
            }
            if (tick % 30 == 0) {
                GCPlayerHandler.sendAirRemainingPacket(player, stats);
                this.sendThermalLevelPacket(player, stats);
                if (!doneDungeon) {
                    for (ItemStack stack : player.inventory.mainInventory) {
                        if (stack != null && stack.getItem() == GCItems.dungeonFinder) {
                            this.sendDungeonDirectionPacket(player, stats);
                            break;
                        }
                    }
                }
            }
        }
        if (player.ridingEntity instanceof EntityLanderBase) {
            stats.setInLander(true);
            stats.setJustLanded(false);
        } else {
            if (stats.isInLander()) {
                stats.setJustLanded(true);
            }
            stats.setInLander(false);
        }
        if (player.onGround && stats.hasJustLanded()) {
            stats.setJustLanded(false);
            // Set spawn point here if just descended from a lander for the first time
            if (player.getBedLocation(GCCoreUtil.getDimensionID(player.worldObj)) == null || stats.isNewAdventureSpawn()) {
                int i = 30000000;
                int j = Math.min(i, Math.max(-i, MathHelper.floor_double(player.posX + 0.5D)));
                int k = Math.min(256, Math.max(0, MathHelper.floor_double(player.posY + 1.5D)));
                int l = Math.min(i, Math.max(-i, MathHelper.floor_double(player.posZ + 0.5D)));
                BlockPos coords = new BlockPos(j, k, l);
                player.setSpawnChunk(coords, true, GCCoreUtil.getDimensionID(player.worldObj));
                stats.setNewAdventureSpawn(false);
            }
            GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(player.worldObj), new Object[] {}), player);
        }
        if (player.worldObj.provider instanceof WorldProviderSpaceStation || player.worldObj.provider instanceof IZeroGDimension || GalacticraftCore.isPlanetsLoaded && player.worldObj.provider instanceof WorldProviderAsteroids) {
            this.preventFlyingKicks(player);
            if (player.worldObj.provider instanceof WorldProviderSpaceStation && stats.isNewInOrbit()) {
                ((WorldProviderSpaceStation) player.worldObj.provider).getSpinManager().sendPackets(player);
                stats.setNewInOrbit(false);
            }
        } else {
            stats.setNewInOrbit(true);
        }
    } else {
        stats.setNewInOrbit(true);
    }
    checkGear(player, stats, false);
    if (stats.getChestSpawnCooldown() > 0) {
        stats.setChestSpawnCooldown(stats.getChestSpawnCooldown() - 1);
        if (stats.getChestSpawnCooldown() == 180) {
            if (stats.getChestSpawnVector() != null) {
                EntityParachest chest = new EntityParachest(player.worldObj, stats.getRocketStacks(), stats.getFuelLevel());
                chest.setPosition(stats.getChestSpawnVector().x, stats.getChestSpawnVector().y, stats.getChestSpawnVector().z);
                chest.color = stats.getParachuteInSlot() == null ? EnumDyeColor.WHITE : ItemParaChute.getDyeEnumFromParachuteDamage(stats.getParachuteInSlot().getItemDamage());
                if (!player.worldObj.isRemote) {
                    player.worldObj.spawnEntityInWorld(chest);
                }
            }
        }
    }
    if (stats.getLaunchAttempts() > 0 && player.ridingEntity == null) {
        stats.setLaunchAttempts(0);
    }
    this.checkThermalStatus(player, stats);
    this.checkOxygen(player, stats);
    this.checkShield(player, stats);
    if (isInGCDimension && (stats.isOxygenSetupValid() != stats.isLastOxygenSetupValid() || tick % 100 == 0)) {
        GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_OXYGEN_VALIDITY, GCCoreUtil.getDimensionID(player.worldObj), new Object[] { stats.isOxygenSetupValid() }), player);
    }
    this.throwMeteors(player);
    this.updateSchematics(player, stats);
    if (tick % 250 == 0 && stats.getFrequencyModuleInSlot() == null && !stats.hasReceivedSoundWarning() && isInGCDimension && player.onGround && tick > 0 && ((IGalacticraftWorldProvider) player.worldObj.provider).getSoundVolReductionAmount() > 1.0F) {
        String[] string2 = GCCoreUtil.translate("gui.frequencymodule.warning1").split(" ");
        StringBuilder sb = new StringBuilder();
        for (String aString2 : string2) {
            sb.append(" ").append(EnumColor.YELLOW).append(aString2);
        }
        player.addChatMessage(new ChatComponentText(EnumColor.YELLOW + GCCoreUtil.translate("gui.frequencymodule.warning0") + " " + EnumColor.AQUA + GCItems.basicItem.getItemStackDisplayName(new ItemStack(GCItems.basicItem, 1, 19)) + sb.toString()));
        stats.setReceivedSoundWarning(true);
    }
    // Player moves and sprints 18% faster with full set of Titanium Armor
    if (GalacticraftCore.isPlanetsLoaded && tick % 40 == 1 && player.inventory != null) {
        int titaniumCount = 0;
        for (int i = 0; i < 4; i++) {
            ItemStack armorPiece = player.getCurrentArmor(i);
            if (armorPiece != null && armorPiece.getItem() instanceof ItemArmorAsteroids) {
                titaniumCount++;
            }
        }
        if (stats.getSavedSpeed() == 0F) {
            if (titaniumCount == 4) {
                float speed = player.capabilities.getWalkSpeed();
                if (speed < 0.118F) {
                    try {
                        Field f = player.capabilities.getClass().getDeclaredField(GCCoreUtil.isDeobfuscated() ? "walkSpeed" : "field_75097_g");
                        f.setAccessible(true);
                        f.set(player.capabilities, 0.118F);
                        stats.setSavedSpeed(speed);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        } else if (titaniumCount < 4) {
            try {
                Field f = player.capabilities.getClass().getDeclaredField(GCCoreUtil.isDeobfuscated() ? "walkSpeed" : "field_75097_g");
                f.setAccessible(true);
                f.set(player.capabilities, stats.getSavedSpeed());
                stats.setSavedSpeed(0F);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    stats.setLastOxygenSetupValid(stats.isOxygenSetupValid());
    stats.setLastUnlockedSchematics(stats.getUnlockedSchematics());
    stats.setLastOnGround(player.onGround);
}
Also used : SpaceRace(micdoodle8.mods.galacticraft.core.dimension.SpaceRace) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) WorldServer(net.minecraft.world.WorldServer) WorldProviderAsteroids(micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids) ItemArmorAsteroids(micdoodle8.mods.galacticraft.planets.asteroids.items.ItemArmorAsteroids) Field(java.lang.reflect.Field) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) BlockPos(net.minecraft.util.BlockPos) ChatComponentText(net.minecraft.util.ChatComponentText) S07PacketRespawn(net.minecraft.network.play.server.S07PacketRespawn) ITeleportType(micdoodle8.mods.galacticraft.api.world.ITeleportType) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) Chunk(net.minecraft.world.chunk.Chunk) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) EntityLanderBase(micdoodle8.mods.galacticraft.core.entities.EntityLanderBase) EntityParachest(micdoodle8.mods.galacticraft.core.entities.EntityParachest) ItemStack(net.minecraft.item.ItemStack) IZeroGDimension(micdoodle8.mods.galacticraft.api.world.IZeroGDimension)

Example 4 with EntityLanderBase

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

the class GCPlayerHandler method checkOxygen.

protected void checkOxygen(EntityPlayerMP player, GCPlayerStats stats) {
    if ((player.dimension == 0 || player.worldObj.provider instanceof IGalacticraftWorldProvider) && (!(player.dimension == 0 || ((IGalacticraftWorldProvider) player.worldObj.provider).hasBreathableAtmosphere()) || player.posY > GCPlayerHandler.OXYGENHEIGHTLIMIT) && !player.capabilities.isCreativeMode && !(player.ridingEntity instanceof EntityLanderBase) && !(player.ridingEntity instanceof EntityAutoRocket) && !(player.ridingEntity 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 == null) {
            stats.setAirRemaining(0);
        } else {
            stats.setAirRemaining(tankInSlot.getMaxDamage() - tankInSlot.getItemDamage());
        }
        if (tankInSlot2 == null) {
            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 != null) {
                        stats.setAirRemaining(Math.min(stats.getAirRemaining() + 1, tankInSlot.getMaxDamage() - tankInSlot.getItemDamage()));
                    }
                    if (stats.getAirRemaining2() < 90 && tankInSlot2 != null) {
                        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.worldObj.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 5 with EntityLanderBase

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

the class EventHandlerGC method onEntityFall.

@SubscribeEvent
public void onEntityFall(LivingFallEvent event) {
    if (event.entityLiving instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.entityLiving;
        if (player.ridingEntity instanceof EntityAutoRocket || player.ridingEntity instanceof EntityLanderBase) {
            event.distance = 0.0F;
            event.setCanceled(true);
            return;
        }
    }
    if (event.entityLiving.worldObj.provider instanceof IGalacticraftWorldProvider) {
        event.distance *= ((IGalacticraftWorldProvider) event.entityLiving.worldObj.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

EntityLanderBase (micdoodle8.mods.galacticraft.core.entities.EntityLanderBase)4 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)3 EntityAutoRocket (micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket)2 IZeroGDimension (micdoodle8.mods.galacticraft.api.world.IZeroGDimension)2 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)2 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)2 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.BlockPos)2 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)2 Field (java.lang.reflect.Field)1 ZeroGravityEvent (micdoodle8.mods.galacticraft.api.event.ZeroGravityEvent)1 GCCoreOxygenSuffocationEvent (micdoodle8.mods.galacticraft.api.event.oxygen.GCCoreOxygenSuffocationEvent)1 EntitySpaceshipBase (micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase)1 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)1 ITeleportType (micdoodle8.mods.galacticraft.api.world.ITeleportType)1 SpaceRace (micdoodle8.mods.galacticraft.core.dimension.SpaceRace)1 SpinManager (micdoodle8.mods.galacticraft.core.dimension.SpinManager)1 EntityCelestialFake (micdoodle8.mods.galacticraft.core.entities.EntityCelestialFake)1 EntityParachest (micdoodle8.mods.galacticraft.core.entities.EntityParachest)1