Search in sources :

Example 11 with WorldProviderSpaceStation

use of micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation in project Galacticraft by micdoodle8.

the class TickHandlerClient method onClientTick.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onClientTick(ClientTickEvent event) {
    final Minecraft minecraft = FMLClientHandler.instance().getClient();
    final WorldClient world = minecraft.theWorld;
    final EntityPlayerSP player = minecraft.thePlayer;
    if (teleportingGui != null) {
        if (minecraft.currentScreen != teleportingGui) {
            minecraft.currentScreen = teleportingGui;
        }
    }
    if (menuReset) {
        TickHandlerClient.resetClient();
        menuReset = false;
    }
    if (event.phase == Phase.START && player != null) {
        if (ClientProxyCore.playerHead == null && player.getGameProfile() != null) {
            Map<Type, MinecraftProfileTexture> map = minecraft.getSkinManager().loadSkinFromCache(player.getGameProfile());
            if (map.containsKey(Type.SKIN)) {
                ClientProxyCore.playerHead = minecraft.getSkinManager().loadSkin((MinecraftProfileTexture) map.get(Type.SKIN), Type.SKIN);
            } else {
                ClientProxyCore.playerHead = DefaultPlayerSkin.getDefaultSkin(EntityPlayer.getUUID(player.getGameProfile()));
            }
        }
        TickHandlerClient.tickCount++;
        if (!GalacticraftCore.proxy.isPaused()) {
            Iterator<FluidNetwork> it = TickHandlerClient.fluidNetworks.iterator();
            while (it.hasNext()) {
                FluidNetwork network = it.next();
                if (network.getTransmitters().size() == 0) {
                    it.remove();
                } else {
                    network.clientTick();
                }
            }
        }
        if (TickHandlerClient.tickCount % 20 == 0) {
            if (updateJEIhiding) {
                updateJEIhiding = false;
                if (CompressorRecipes.steelIngotsPresent) {
                    // Update JEI to hide the ingot compressor recipe for GC steel in hard mode
                    GalacticraftJEI.updateHiddenSteel(ConfigManagerCore.hardMode && !ConfigManagerCore.challengeRecipes);
                }
                // Update JEI to hide adventure mode recipes when not in adventure mode
                GalacticraftJEI.updateHiddenAdventure(!ConfigManagerCore.challengeRecipes);
            }
            for (List<Footprint> fpList : FootprintRenderer.footprints.values()) {
                Iterator<Footprint> fpIt = fpList.iterator();
                while (fpIt.hasNext()) {
                    Footprint fp = fpIt.next();
                    fp.age += 20;
                    if (fp.age >= Footprint.MAX_AGE) {
                        fpIt.remove();
                    }
                }
            }
            if (player.inventory.armorItemInSlot(3) != null && player.inventory.armorItemInSlot(3).getItem() instanceof ItemSensorGlasses) {
                ClientProxyCore.valueableBlocks.clear();
                for (int i = -4; i < 5; i++) {
                    int x = MathHelper.floor_double(player.posX + i);
                    for (int j = -4; j < 5; j++) {
                        int y = MathHelper.floor_double(player.posY + j);
                        for (int k = -4; k < 5; k++) {
                            int z = MathHelper.floor_double(player.posZ + k);
                            BlockPos pos = new BlockPos(x, y, z);
                            IBlockState state = player.worldObj.getBlockState(pos);
                            final Block block = state.getBlock();
                            if (block.getMaterial() != Material.air) {
                                int metadata = block.getMetaFromState(state);
                                boolean isDetectable = false;
                                for (BlockMetaList blockMetaList : ClientProxyCore.detectableBlocks) {
                                    if (blockMetaList.getBlock() == block && blockMetaList.getMetaList().contains(metadata)) {
                                        isDetectable = true;
                                        break;
                                    }
                                }
                                if (isDetectable || (block instanceof IDetectableResource && ((IDetectableResource) block).isValueable(state))) {
                                    ClientProxyCore.valueableBlocks.add(new BlockVec3(x, y, z));
                                }
                            }
                        }
                    }
                }
                TileEntityOxygenSealer nearestSealer = TileEntityOxygenSealer.getNearestSealer(world, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ));
                if (nearestSealer != null && !nearestSealer.sealed) {
                    ClientProxyCore.leakTrace = nearestSealer.getLeakTraceClient();
                } else {
                    ClientProxyCore.leakTrace = null;
                }
            } else {
                ClientProxyCore.leakTrace = null;
            }
            if (world != null) {
                if (MapUtil.resetClientFlag.getAndSet(false)) {
                    MapUtil.resetClientBody();
                }
            }
        }
        if (ClientProxyCore.leakTrace != null)
            this.spawnLeakParticles();
        if (world != null && TickHandlerClient.spaceRaceGuiScheduled && minecraft.currentScreen == null && ConfigManagerCore.enableSpaceRaceManagerPopup) {
            player.openGui(GalacticraftCore.instance, GuiIdsCore.SPACE_RACE_START, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
            TickHandlerClient.spaceRaceGuiScheduled = false;
        }
        if (world != null && TickHandlerClient.checkedVersion) {
            ThreadVersionCheck.startCheck();
            TickHandlerClient.checkedVersion = false;
        }
        boolean inSpaceShip = false;
        if (player.ridingEntity instanceof EntitySpaceshipBase) {
            inSpaceShip = true;
            EntitySpaceshipBase rocket = (EntitySpaceshipBase) player.ridingEntity;
            if (rocket.prevRotationPitch != rocket.rotationPitch || rocket.prevRotationYaw != rocket.rotationYaw)
                GalacticraftCore.packetPipeline.sendToServer(new PacketRotateRocket(player.ridingEntity));
        }
        if (world != null) {
            if (world.provider instanceof WorldProviderSurface) {
                if (world.provider.getSkyRenderer() == null && inSpaceShip && player.ridingEntity.posY > Constants.OVERWORLD_SKYPROVIDER_STARTHEIGHT) {
                    world.provider.setSkyRenderer(new SkyProviderOverworld());
                } else if (world.provider.getSkyRenderer() instanceof SkyProviderOverworld && player.posY <= Constants.OVERWORLD_SKYPROVIDER_STARTHEIGHT) {
                    world.provider.setSkyRenderer(null);
                }
            } else if (world.provider instanceof WorldProviderSpaceStation) {
                if (world.provider.getSkyRenderer() == null) {
                    ((WorldProviderSpaceStation) world.provider).createSkyProvider();
                }
            } else if (world.provider instanceof WorldProviderMoon) {
                if (world.provider.getSkyRenderer() == null) {
                    world.provider.setSkyRenderer(new SkyProviderMoon());
                }
                if (world.provider.getCloudRenderer() == null) {
                    world.provider.setCloudRenderer(new CloudRenderer());
                }
            }
        }
        if (inSpaceShip) {
            final EntitySpaceshipBase ship = (EntitySpaceshipBase) player.ridingEntity;
            boolean hasChanged = false;
            if (minecraft.gameSettings.keyBindLeft.isKeyDown()) {
                ship.turnYaw(-1.0F);
                hasChanged = true;
            }
            if (minecraft.gameSettings.keyBindRight.isKeyDown()) {
                ship.turnYaw(1.0F);
                hasChanged = true;
            }
            if (minecraft.gameSettings.keyBindForward.isKeyDown()) {
                if (ship.getLaunched()) {
                    ship.turnPitch(-0.7F);
                    hasChanged = true;
                }
            }
            if (minecraft.gameSettings.keyBindBack.isKeyDown()) {
                if (ship.getLaunched()) {
                    ship.turnPitch(0.7F);
                    hasChanged = true;
                }
            }
            if (hasChanged) {
                GalacticraftCore.packetPipeline.sendToServer(new PacketRotateRocket(ship));
            }
        }
        if (world != null) {
            List entityList = world.loadedEntityList;
            for (Object e : entityList) {
                if (e instanceof IEntityNoisy) {
                    IEntityNoisy vehicle = (IEntityNoisy) e;
                    if (vehicle.getSoundUpdater() == null) {
                        ISound noise = vehicle.setSoundUpdater(FMLClientHandler.instance().getClient().thePlayer);
                        if (noise != null) {
                            FMLClientHandler.instance().getClient().getSoundHandler().playSound(noise);
                        }
                    }
                }
            }
        }
        if (FMLClientHandler.instance().getClient().currentScreen instanceof GuiCelestialSelection) {
            player.motionY = 0;
        }
        if (world != null && world.provider instanceof IGalacticraftWorldProvider && OxygenUtil.noAtmosphericCombustion(world.provider) && ((IGalacticraftWorldProvider) world.provider).shouldDisablePrecipitation()) {
            world.setRainStrength(0.0F);
        }
        boolean isPressed = KeyHandlerClient.spaceKey.isPressed();
        if (!isPressed) {
            ClientProxyCore.lastSpacebarDown = false;
        }
        if (player.ridingEntity != null && isPressed && !ClientProxyCore.lastSpacebarDown) {
            GalacticraftCore.packetPipeline.sendToServer(new PacketSimple(EnumSimplePacket.S_IGNITE_ROCKET, GCCoreUtil.getDimensionID(player.worldObj), new Object[] {}));
            ClientProxyCore.lastSpacebarDown = true;
        }
        if (!(this.screenConnectionsUpdateList.isEmpty())) {
            HashSet<TileEntityScreen> updateListCopy = (HashSet<TileEntityScreen>) screenConnectionsUpdateList.clone();
            screenConnectionsUpdateList.clear();
            for (TileEntityScreen te : updateListCopy) {
                if (te.getWorld().getBlockState(te.getPos()).getBlock() == GCBlocks.screen) {
                    if (te.refreshOnUpdate) {
                        te.refreshConnections(true);
                    }
                    te.getWorld().markBlockRangeForRenderUpdate(te.getPos(), te.getPos());
                }
            }
        }
    } else if (event.phase == Phase.END) {
        if (world != null) {
            for (GalacticraftPacketHandler handler : packetHandlers) {
                handler.tick(world);
            }
        }
    }
}
Also used : TileEntityOxygenSealer(micdoodle8.mods.galacticraft.core.tile.TileEntityOxygenSealer) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) IEntityNoisy(micdoodle8.mods.galacticraft.api.entity.IEntityNoisy) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) GalacticraftPacketHandler(micdoodle8.mods.galacticraft.core.network.GalacticraftPacketHandler) IDetectableResource(micdoodle8.mods.galacticraft.api.block.IDetectableResource) ISound(net.minecraft.client.audio.ISound) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) WorldProviderMoon(micdoodle8.mods.galacticraft.core.dimension.WorldProviderMoon) BlockPos(net.minecraft.util.BlockPos) PacketRotateRocket(micdoodle8.mods.galacticraft.core.network.PacketRotateRocket) BlockMetaList(micdoodle8.mods.galacticraft.core.wrappers.BlockMetaList) ItemSensorGlasses(micdoodle8.mods.galacticraft.core.items.ItemSensorGlasses) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3) TileEntityScreen(micdoodle8.mods.galacticraft.core.tile.TileEntityScreen) EntitySpaceshipBase(micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) WorldProviderSurface(net.minecraft.world.WorldProviderSurface) IBlockState(net.minecraft.block.state.IBlockState) FluidNetwork(micdoodle8.mods.galacticraft.core.fluid.FluidNetwork) MinecraftProfileTexture(com.mojang.authlib.minecraft.MinecraftProfileTexture) Minecraft(net.minecraft.client.Minecraft) WorldClient(net.minecraft.client.multiplayer.WorldClient) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) BlockMetaList(micdoodle8.mods.galacticraft.core.wrappers.BlockMetaList) Type(com.mojang.authlib.minecraft.MinecraftProfileTexture.Type) GuiCelestialSelection(micdoodle8.mods.galacticraft.core.client.gui.screen.GuiCelestialSelection) Block(net.minecraft.block.Block) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 12 with WorldProviderSpaceStation

use of micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation in project Galacticraft by micdoodle8.

the class WorldUtil method teleportEntitySimple.

public static Entity teleportEntitySimple(World worldNew, int dimID, EntityPlayerMP player, Vector3 spawnPos) {
    if (player.ridingEntity != null) {
        player.ridingEntity.setDead();
        player.mountEntity(null);
    }
    World worldOld = player.worldObj;
    int oldDimID = GCCoreUtil.getDimensionID(worldOld);
    boolean dimChange = worldOld != worldNew;
    // Make sure the entity is added to the correct chunk in the OLD world so that it will be properly removed later if it needs to be unloaded from that world
    worldOld.updateEntityWithOptionalForce(player, false);
    if (dimChange) {
        player.dimension = dimID;
        if (ConfigManagerCore.enableDebug) {
            GCLog.info("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) {
            if (WorldUtil.registeredSpaceStations.containsKey(dimID)) // TODO This has never been effective before due to the earlier bug - what does it actually do?
            {
                NBTTagCompound var2 = new NBTTagCompound();
                SpaceStationWorldData.getStationData(worldNew, dimID, player).writeToNBT(var2);
                GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_DATA, GCCoreUtil.getDimensionID(player.worldObj), new Object[] { dimID, var2 }), player);
            }
        }
        removeEntityFromWorld(worldOld, player, true);
        forceMoveEntityToPos(player, (WorldServer) worldNew, spawnPos, true);
        GCLog.info("Server attempting to transfer player " + PlayerUtil.getName(player) + " to dimension " + GCCoreUtil.getDimensionID(worldNew));
        player.mcServer.getConfigurationManager().preparePlayer(player, (WorldServer) worldOld);
        player.theItemInWorldManager.setWorld((WorldServer) worldNew);
        player.mcServer.getConfigurationManager().updateTimeAndWeatherForPlayer(player, (WorldServer) worldNew);
        player.mcServer.getConfigurationManager().syncPlayerInventory(player);
        for (Object o : player.getActivePotionEffects()) {
            PotionEffect var10 = (PotionEffect) o;
            player.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(player.getEntityId(), var10));
        }
        player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
        FMLCommonHandler.instance().firePlayerChangedDimensionEvent((EntityPlayerMP) player, oldDimID, dimID);
    } else {
        forceMoveEntityToPos(player, (WorldServer) worldNew, spawnPos, false);
        GCLog.info("Server attempting to transfer player " + PlayerUtil.getName(player) + " within same dimension " + GCCoreUtil.getDimensionID(worldNew));
    }
    player.capabilities.isFlying = false;
    GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(player.worldObj), new Object[] {}), player);
    // Update PlayerStatsGC
    GCPlayerStats stats = GCPlayerStats.get(player);
    GCPlayerHandler.setUsingParachute(player, stats, false);
    return player;
}
Also used : S07PacketRespawn(net.minecraft.network.play.server.S07PacketRespawn) PotionEffect(net.minecraft.potion.PotionEffect) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) S1FPacketSetExperience(net.minecraft.network.play.server.S1FPacketSetExperience) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) S1DPacketEntityEffect(net.minecraft.network.play.server.S1DPacketEntityEffect) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple)

Example 13 with WorldProviderSpaceStation

use of micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation in project Galacticraft by micdoodle8.

the class ItemAstroMiner method onItemUse.

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
    TileEntity tile = null;
    if (worldIn.isRemote || playerIn == null) {
        return false;
    } else {
        final Block id = worldIn.getBlockState(pos).getBlock();
        if (id == GCBlocks.fakeBlock) {
            tile = worldIn.getTileEntity(pos);
            if (tile instanceof TileEntityMulti) {
                tile = ((TileEntityMulti) tile).getMainBlockTile();
            }
        }
        if (id == AsteroidBlocks.minerBaseFull) {
            tile = worldIn.getTileEntity(pos);
        }
        if (tile instanceof TileEntityMinerBase) {
            if (worldIn.provider instanceof WorldProviderSpaceStation) {
                playerIn.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.message.astro_miner7.fail")));
                return false;
            }
            if (((TileEntityMinerBase) tile).getLinkedMiner() != null) {
                playerIn.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.message.astro_miner.fail")));
                return false;
            }
            // Gives a chance for any loaded Astro Miner to link itself
            if (((TileEntityMinerBase) tile).ticks < 15L) {
                return false;
            }
            EntityPlayerMP playerMP = (EntityPlayerMP) playerIn;
            GCPlayerStats stats = GCPlayerStats.get(playerIn);
            int astroCount = stats.getAstroMinerCount();
            if (astroCount >= ConfigManagerAsteroids.astroMinerMax && (!playerIn.capabilities.isCreativeMode)) {
                playerIn.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.message.astro_miner2.fail")));
                return false;
            }
            if (!((TileEntityMinerBase) tile).spawnMiner(playerMP)) {
                playerIn.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.message.astro_miner1.fail") + " " + GCCoreUtil.translate(EntityAstroMiner.blockingBlock.toString())));
                return false;
            }
            if (!playerIn.capabilities.isCreativeMode) {
                stats.setAstroMinerCount(stats.getAstroMinerCount() + 1);
                --stack.stackSize;
            }
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) Block(net.minecraft.block.Block) TileEntityMinerBase(micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TileEntityMulti(micdoodle8.mods.galacticraft.core.tile.TileEntityMulti) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 14 with WorldProviderSpaceStation

use of micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation 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 15 with WorldProviderSpaceStation

use of micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation in project Galacticraft by micdoodle8.

the class TileEntitySolar method update.

@Override
public void update() {
    if (!this.initialised) {
        int metadata = this.getBlockMetadata();
        if (metadata >= BlockSolar.ADVANCED_METADATA) {
            this.storage.setCapacity(30000);
            this.setTierGC(2);
        }
        this.initialised = true;
    }
    if (!this.initialisedMulti) {
        this.initialisedMulti = this.initialiseMultiTiles(this.getPos(), this.worldObj);
    }
    if (!this.worldObj.isRemote) {
        this.receiveEnergyGC(null, this.generateWatts, false);
    }
    super.update();
    if (!this.worldObj.isRemote) {
        this.recharge(this.containingItems[0]);
        if (this.disableCooldown > 0) {
            this.disableCooldown--;
        }
        if (!this.getDisabled(0) && this.ticks % 20 == 0) {
            this.solarStrength = 0;
            if (this.worldObj.isDaytime() && (this.worldObj.provider instanceof IGalacticraftWorldProvider || !this.worldObj.isRaining() && !this.worldObj.isThundering())) {
                double distance = 100.0D;
                double sinA = -Math.sin((this.currentAngle - 77.5D) / Constants.RADIANS_TO_DEGREES_D);
                double cosA = Math.abs(Math.cos((this.currentAngle - 77.5D) / Constants.RADIANS_TO_DEGREES_D));
                for (int x = -1; x <= 1; x++) {
                    for (int z = -1; z <= 1; z++) {
                        if (this.tierGC == 1) {
                            if (this.worldObj.canBlockSeeSky(this.getPos().add(x, 2, z))) {
                                boolean valid = true;
                                for (int y = this.getPos().getY() + 3; y < 256; y++) {
                                    Block block = this.worldObj.getBlockState(new BlockPos(this.getPos().getX() + x, y, this.getPos().getZ() + z)).getBlock();
                                    if (block.isOpaqueCube()) {
                                        valid = false;
                                        break;
                                    }
                                }
                                if (valid) {
                                    this.solarStrength++;
                                }
                            }
                        } else {
                            boolean valid = true;
                            BlockVec3 blockVec = new BlockVec3(this).translate(x, 3, z);
                            for (double d = 0.0D; d < distance; d++) {
                                BlockVec3 blockAt = blockVec.clone().translate((int) (d * sinA), (int) (d * cosA), 0);
                                Block block = blockAt.getBlock(this.worldObj);
                                if (block.isOpaqueCube()) {
                                    valid = false;
                                    break;
                                }
                            }
                            if (valid) {
                                this.solarStrength++;
                            }
                        }
                    }
                }
            }
        }
    }
    float angle = this.worldObj.getCelestialAngle(1.0F) - 0.7845194F < 0 ? 1.0F - 0.7845194F : -0.7845194F;
    float celestialAngle = (this.worldObj.getCelestialAngle(1.0F) + angle) * 360.0F;
    if (!(this.worldObj.provider instanceof WorldProviderSpaceStation))
        celestialAngle += 12.5F;
    if (GalacticraftCore.isPlanetsLoaded && this.worldObj.provider instanceof WorldProviderVenus)
        celestialAngle = 180F - celestialAngle;
    celestialAngle %= 360;
    boolean isDaytime = this.worldObj.isDaytime() && (celestialAngle < 180.5F || celestialAngle > 359.5F) || this.worldObj.provider instanceof WorldProviderSpaceStation;
    if (this.tierGC == 1) {
        if (!isDaytime || this.worldObj.isRaining() || this.worldObj.isThundering()) {
            this.targetAngle = 77.5F + 180.0F;
        } else {
            this.targetAngle = 77.5F;
        }
    } else {
        if (!isDaytime || this.worldObj.isRaining() || this.worldObj.isThundering()) {
            this.targetAngle = 77.5F + 180F;
        } else if (celestialAngle > 27.5F && celestialAngle < 152.5F) {
            float difference = this.targetAngle - celestialAngle + 12.5F;
            this.targetAngle -= difference / 20.0F;
        } else if (celestialAngle <= 27.5F || celestialAngle > 270F) {
            this.targetAngle = 15F;
        } else if (celestialAngle >= 152.5F) {
            this.targetAngle = 140F;
        }
    }
    float difference = this.targetAngle - this.currentAngle;
    this.currentAngle += difference / 20.0F;
    if (!this.worldObj.isRemote) {
        int generated = this.getGenerate();
        if (generated > 0) {
            this.generateWatts = Math.min(Math.max(generated, 0), TileEntitySolar.MAX_GENERATE_WATTS);
        } else {
            this.generateWatts = 0;
        }
    }
    this.produce();
}
Also used : IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) Block(net.minecraft.block.Block) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3) WorldProviderVenus(micdoodle8.mods.galacticraft.planets.venus.dimension.WorldProviderVenus)

Aggregations

WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)15 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)6 Block (net.minecraft.block.Block)6 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)5 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)4 World (net.minecraft.world.World)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)4 EntitySpaceshipBase (micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase)3 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)3 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)3 IZeroGDimension (micdoodle8.mods.galacticraft.api.world.IZeroGDimension)3 SpaceRace (micdoodle8.mods.galacticraft.core.dimension.SpaceRace)3 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)3 S07PacketRespawn (net.minecraft.network.play.server.S07PacketRespawn)3 TileEntity (net.minecraft.tileentity.TileEntity)3 WorldProvider (net.minecraft.world.WorldProvider)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 Field (java.lang.reflect.Field)2 ZeroGravityEvent (micdoodle8.mods.galacticraft.api.event.ZeroGravityEvent)2 GuiCelestialSelection (micdoodle8.mods.galacticraft.core.client.gui.screen.GuiCelestialSelection)2