Search in sources :

Example 1 with S07PacketRespawn

use of net.minecraft.network.play.server.S07PacketRespawn in project Galacticraft by micdoodle8.

the class WorldUtil method teleportEntity.

private static Entity teleportEntity(World worldNew, Entity entity, int dimID, ITeleportType type, boolean transferInv, EntityAutoRocket ridingRocket) {
    Entity otherRiddenEntity = null;
    if (entity.ridingEntity != null) {
        if (entity.ridingEntity instanceof EntitySpaceshipBase) {
            entity.mountEntity(entity.ridingEntity);
        } else if (entity.ridingEntity instanceof EntityCelestialFake) {
            entity.ridingEntity.setDead();
            entity.mountEntity(null);
        } else {
            otherRiddenEntity = entity.ridingEntity;
            entity.mountEntity(null);
        }
    }
    boolean dimChange = entity.worldObj != 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
    entity.worldObj.updateEntityWithOptionalForce(entity, false);
    EntityPlayerMP player = null;
    Vector3 spawnPos = null;
    int oldDimID = GCCoreUtil.getDimensionID(entity.worldObj);
    if (ridingRocket != null) {
        ArrayList<TileEntityTelemetry> tList = ridingRocket.getTelemetry();
        NBTTagCompound nbt = new NBTTagCompound();
        ridingRocket.isDead = false;
        ridingRocket.riddenByEntity = null;
        ridingRocket.writeToNBTOptional(nbt);
        ((WorldServer) ridingRocket.worldObj).getEntityTracker().untrackEntity(ridingRocket);
        removeEntityFromWorld(ridingRocket.worldObj, ridingRocket, true);
        ridingRocket = (EntityAutoRocket) EntityList.createEntityFromNBT(nbt, worldNew);
        if (ridingRocket != null) {
            ridingRocket.setWaitForPlayer(true);
            if (ridingRocket instanceof IWorldTransferCallback) {
                ((IWorldTransferCallback) ridingRocket).onWorldTransferred(worldNew);
            }
        }
    }
    if (dimChange) {
        if (entity instanceof EntityPlayerMP) {
            player = (EntityPlayerMP) entity;
            World worldOld = player.worldObj;
            GCPlayerStats stats = GCPlayerStats.get(player);
            stats.setUsingPlanetSelectionGui(false);
            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);
            if (ridingRocket != null) {
                spawnPos = new Vector3(ridingRocket);
            } else {
                spawnPos = type.getPlayerSpawnLocation((WorldServer) worldNew, player);
            }
            forceMoveEntityToPos(entity, (WorldServer) worldNew, spawnPos, true);
            GCLog.info("Server attempting to transfer player " + PlayerUtil.getName(player) + " to dimension " + GCCoreUtil.getDimensionID(worldNew));
            if (worldNew.provider instanceof WorldProviderSpaceStation) {
                GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(worldNew), new Object[] {}), player);
            }
            player.capabilities.isFlying = false;
            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));
        } else // Non-player entity transfer i.e. it's an EntityCargoRocket or an empty rocket
        {
            ArrayList<TileEntityTelemetry> tList = null;
            if (entity instanceof EntitySpaceshipBase) {
                tList = ((EntitySpaceshipBase) entity).getTelemetry();
            }
            WorldUtil.removeEntityFromWorld(entity.worldObj, entity, true);
            NBTTagCompound nbt = new NBTTagCompound();
            entity.isDead = false;
            entity.writeToNBTOptional(nbt);
            entity = EntityList.createEntityFromNBT(nbt, worldNew);
            if (entity == null) {
                return null;
            }
            if (entity instanceof IWorldTransferCallback) {
                ((IWorldTransferCallback) entity).onWorldTransferred(worldNew);
            }
            forceMoveEntityToPos(entity, (WorldServer) worldNew, new Vector3(entity), true);
            if (tList != null && tList.size() > 0) {
                for (TileEntityTelemetry t : tList) {
                    t.addTrackedEntity(entity);
                }
            }
        }
    } else {
        // Same dimension player transfer
        if (entity instanceof EntityPlayerMP) {
            player = (EntityPlayerMP) entity;
            player.closeScreen();
            GCPlayerStats stats = GCPlayerStats.get(player);
            stats.setUsingPlanetSelectionGui(false);
            if (ridingRocket != null) {
                spawnPos = new Vector3(ridingRocket);
            } else {
                spawnPos = type.getPlayerSpawnLocation((WorldServer) entity.worldObj, (EntityPlayerMP) entity);
            }
            forceMoveEntityToPos(entity, (WorldServer) worldNew, spawnPos, false);
            GCLog.info("Server attempting to transfer player " + PlayerUtil.getName(player) + " within same dimension " + GCCoreUtil.getDimensionID(worldNew));
            if (worldNew.provider instanceof WorldProviderSpaceStation) {
                GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(worldNew), new Object[] {}), player);
            }
            player.capabilities.isFlying = false;
        }
    // Cargo rocket does not needs its location setting here, it will do that itself
    }
    // Update PlayerStatsGC
    if (player != null) {
        GCPlayerStats stats = GCPlayerStats.get(player);
        if (ridingRocket == null && type.useParachute() && stats.getExtendedInventory().getStackInSlot(4) != null && stats.getExtendedInventory().getStackInSlot(4).getItem() instanceof ItemParaChute) {
            GCPlayerHandler.setUsingParachute(player, stats, true);
        } else {
            GCPlayerHandler.setUsingParachute(player, stats, false);
        }
        if (stats.getRocketStacks() != null && stats.getRocketStacks().length > 0) {
            for (int stack = 0; stack < stats.getRocketStacks().length; stack++) {
                if (transferInv) {
                    if (stats.getRocketStacks()[stack] == null) {
                        if (stack == stats.getRocketStacks().length - 1) {
                            if (stats.getRocketItem() != null) {
                                stats.getRocketStacks()[stack] = new ItemStack(stats.getRocketItem(), 1, stats.getRocketType());
                            }
                        } else if (stack == stats.getRocketStacks().length - 2) {
                            stats.getRocketStacks()[stack] = stats.getLaunchpadStack();
                            stats.setLaunchpadStack(null);
                        }
                    }
                } else {
                    stats.getRocketStacks()[stack] = null;
                }
            }
        }
        if (transferInv && stats.getChestSpawnCooldown() == 0) {
            stats.setChestSpawnVector(type.getParaChestSpawnLocation((WorldServer) entity.worldObj, player, new Random()));
            stats.setChestSpawnCooldown(200);
        }
    }
    if (ridingRocket != null) {
        ridingRocket.forceSpawn = true;
        worldNew.spawnEntityInWorld(ridingRocket);
        ridingRocket.setWorld(worldNew);
        worldNew.updateEntityWithOptionalForce(ridingRocket, true);
        entity.mountEntity(ridingRocket);
        GCLog.debug("Entering rocket at : " + entity.posX + "," + entity.posZ + " rocket at: " + ridingRocket.posX + "," + ridingRocket.posZ);
    } else if (otherRiddenEntity != null) {
        if (dimChange) {
            World worldOld = otherRiddenEntity.worldObj;
            NBTTagCompound nbt = new NBTTagCompound();
            otherRiddenEntity.writeToNBTOptional(nbt);
            removeEntityFromWorld(worldOld, otherRiddenEntity, true);
            otherRiddenEntity = EntityList.createEntityFromNBT(nbt, worldNew);
            worldNew.spawnEntityInWorld(otherRiddenEntity);
            otherRiddenEntity.setWorld(worldNew);
        }
        otherRiddenEntity.setPositionAndRotation(entity.posX, entity.posY - 10, entity.posZ, otherRiddenEntity.rotationYaw, otherRiddenEntity.rotationPitch);
        worldNew.updateEntityWithOptionalForce(otherRiddenEntity, true);
    }
    if (entity instanceof EntityPlayerMP) {
        if (dimChange)
            FMLCommonHandler.instance().firePlayerChangedDimensionEvent((EntityPlayerMP) entity, oldDimID, dimID);
        // Spawn in a lander if appropriate
        type.onSpaceDimensionChanged(worldNew, (EntityPlayerMP) entity, ridingRocket != null);
    }
    return entity;
}
Also used : EntitySpaceshipBase(micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase) Entity(net.minecraft.entity.Entity) TileEntityTelemetry(micdoodle8.mods.galacticraft.core.tile.TileEntityTelemetry) S07PacketRespawn(net.minecraft.network.play.server.S07PacketRespawn) PotionEffect(net.minecraft.potion.PotionEffect) EntityCelestialFake(micdoodle8.mods.galacticraft.core.entities.EntityCelestialFake) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) S1DPacketEntityEffect(net.minecraft.network.play.server.S1DPacketEntityEffect) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) ItemParaChute(micdoodle8.mods.galacticraft.core.items.ItemParaChute) IWorldTransferCallback(micdoodle8.mods.galacticraft.api.entity.IWorldTransferCallback) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) S1FPacketSetExperience(net.minecraft.network.play.server.S1FPacketSetExperience) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Example 2 with S07PacketRespawn

use of net.minecraft.network.play.server.S07PacketRespawn in project Galacticraft by micdoodle8.

the class PacketSimple method handleServerSide.

@Override
public void handleServerSide(EntityPlayer player) {
    final EntityPlayerMP playerBase = PlayerUtil.getPlayerBaseServerFromPlayer(player, false);
    if (playerBase == null) {
        return;
    }
    final MinecraftServer server = playerBase.mcServer;
    final GCPlayerStats stats = GCPlayerStats.get(playerBase);
    switch(this.type) {
        case S_RESPAWN_PLAYER:
            playerBase.playerNetServerHandler.sendPacket(new S07PacketRespawn(player.dimension, player.worldObj.getDifficulty(), player.worldObj.getWorldInfo().getTerrainType(), playerBase.theItemInWorldManager.getGameType()));
            break;
        case S_TELEPORT_ENTITY:
            TickHandlerServer.scheduleNewDimensionChange(new ScheduledDimensionChange(playerBase, (String) PacketSimple.this.data.get(0)));
            break;
        case S_IGNITE_ROCKET:
            if (!player.worldObj.isRemote && !player.isDead && player.ridingEntity != null && !player.ridingEntity.isDead && player.ridingEntity instanceof EntityTieredRocket) {
                final EntityTieredRocket ship = (EntityTieredRocket) player.ridingEntity;
                if (ship.launchPhase != EnumLaunchPhase.LANDING.ordinal()) {
                    if (ship.hasValidFuel()) {
                        ItemStack stack2 = stats.getExtendedInventory().getStackInSlot(4);
                        if (stack2 != null && stack2.getItem() instanceof ItemParaChute || stats.getLaunchAttempts() > 0) {
                            ship.igniteCheckingCooldown();
                            stats.setLaunchAttempts(0);
                        } else if (stats.getChatCooldown() == 0 && stats.getLaunchAttempts() == 0) {
                            player.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.rocket.warning.noparachute")));
                            stats.setChatCooldown(250);
                            stats.setLaunchAttempts(1);
                        }
                    } else if (stats.getChatCooldown() == 0) {
                        player.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.rocket.warning.nofuel")));
                        stats.setChatCooldown(250);
                    }
                }
            }
            break;
        case S_OPEN_SCHEMATIC_PAGE:
            if (player != null) {
                final ISchematicPage page = SchematicRegistry.getMatchingRecipeForID((Integer) this.data.get(0));
                player.openGui(GalacticraftCore.instance, page.getGuiID(), player.worldObj, (Integer) this.data.get(1), (Integer) this.data.get(2), (Integer) this.data.get(3));
            }
            break;
        case S_OPEN_FUEL_GUI:
            if (player.ridingEntity instanceof EntityBuggy) {
                GCCoreUtil.openBuggyInv(playerBase, (EntityBuggy) player.ridingEntity, ((EntityBuggy) player.ridingEntity).getType());
            } else if (player.ridingEntity instanceof EntitySpaceshipBase) {
                player.openGui(GalacticraftCore.instance, GuiIdsCore.ROCKET_INVENTORY, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
            }
            break;
        case S_UPDATE_SHIP_YAW:
            if (player.ridingEntity instanceof EntitySpaceshipBase) {
                final EntitySpaceshipBase ship = (EntitySpaceshipBase) player.ridingEntity;
                if (ship != null) {
                    ship.rotationYaw = (Float) this.data.get(0);
                }
            }
            break;
        case S_UPDATE_SHIP_PITCH:
            if (player.ridingEntity instanceof EntitySpaceshipBase) {
                final EntitySpaceshipBase ship = (EntitySpaceshipBase) player.ridingEntity;
                if (ship != null) {
                    ship.rotationPitch = (Float) this.data.get(0);
                }
            }
            break;
        case S_SET_ENTITY_FIRE:
            Entity entity = player.worldObj.getEntityByID((Integer) this.data.get(0));
            if (entity instanceof EntityLivingBase) {
                ((EntityLivingBase) entity).setFire(3);
            }
            break;
        case S_BIND_SPACE_STATION_ID:
            int homeID = (Integer) this.data.get(0);
            if ((!stats.getSpaceStationDimensionData().containsKey(homeID) || stats.getSpaceStationDimensionData().get(homeID) == -1 || stats.getSpaceStationDimensionData().get(homeID) == 0) && !ConfigManagerCore.disableSpaceStationCreation) {
                if (playerBase.capabilities.isCreativeMode || WorldUtil.getSpaceStationRecipe(homeID).matches(playerBase, true)) {
                    WorldUtil.bindSpaceStationToNewDimension(playerBase.worldObj, playerBase, homeID);
                }
            }
            break;
        case S_UNLOCK_NEW_SCHEMATIC:
            final Container container = player.openContainer;
            if (container instanceof ContainerSchematic) {
                final ContainerSchematic schematicContainer = (ContainerSchematic) container;
                ItemStack stack = schematicContainer.craftMatrix.getStackInSlot(0);
                if (stack != null) {
                    final ISchematicPage page = SchematicRegistry.getMatchingRecipeForItemStack(stack);
                    if (page != null) {
                        SchematicRegistry.unlockNewPage(playerBase, stack);
                        SpaceRaceManager.teamUnlockSchematic(playerBase, stack);
                        if (--stack.stackSize <= 0) {
                            stack = null;
                        }
                        schematicContainer.craftMatrix.setInventorySlotContents(0, stack);
                        schematicContainer.craftMatrix.markDirty();
                        GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_ADD_NEW_SCHEMATIC, getDimensionID(), new Object[] { page.getPageID() }), playerBase);
                    }
                }
            }
            break;
        case S_UPDATE_DISABLEABLE_BUTTON:
            final TileEntity tileAt = player.worldObj.getTileEntity((BlockPos) this.data.get(0));
            if (tileAt instanceof IDisableableMachine) {
                final IDisableableMachine machine = (IDisableableMachine) tileAt;
                machine.setDisabled((Integer) this.data.get(1), !machine.getDisabled((Integer) this.data.get(1)));
            }
            break;
        case S_ON_FAILED_CHEST_UNLOCK:
            if (stats.getChatCooldown() == 0) {
                player.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.chest.warning.wrongkey", this.data.get(0))));
                stats.setChatCooldown(100);
            }
            break;
        case S_RENAME_SPACE_STATION:
            final SpaceStationWorldData ssdata = SpaceStationWorldData.getStationData(playerBase.worldObj, (Integer) this.data.get(1), playerBase);
            if (ssdata != null && ssdata.getOwner().equalsIgnoreCase(PlayerUtil.getName(player))) {
                ssdata.setSpaceStationName((String) this.data.get(0));
                ssdata.setDirty(true);
            }
            break;
        case S_OPEN_EXTENDED_INVENTORY:
            player.openGui(GalacticraftCore.instance, GuiIdsCore.EXTENDED_INVENTORY, player.worldObj, 0, 0, 0);
            break;
        case S_ON_ADVANCED_GUI_CLICKED_INT:
            TileEntity tile1 = player.worldObj.getTileEntity((BlockPos) this.data.get(1));
            switch((Integer) this.data.get(0)) {
                case 0:
                    if (tile1 instanceof TileEntityAirLockController) {
                        TileEntityAirLockController airlockController = (TileEntityAirLockController) tile1;
                        airlockController.redstoneActivation = (Integer) this.data.get(2) == 1;
                    }
                    break;
                case 1:
                    if (tile1 instanceof TileEntityAirLockController) {
                        TileEntityAirLockController airlockController = (TileEntityAirLockController) tile1;
                        airlockController.playerDistanceActivation = (Integer) this.data.get(2) == 1;
                    }
                    break;
                case 2:
                    if (tile1 instanceof TileEntityAirLockController) {
                        TileEntityAirLockController airlockController = (TileEntityAirLockController) tile1;
                        airlockController.playerDistanceSelection = (Integer) this.data.get(2);
                    }
                    break;
                case 3:
                    if (tile1 instanceof TileEntityAirLockController) {
                        TileEntityAirLockController airlockController = (TileEntityAirLockController) tile1;
                        airlockController.playerNameMatches = (Integer) this.data.get(2) == 1;
                    }
                    break;
                case 4:
                    if (tile1 instanceof TileEntityAirLockController) {
                        TileEntityAirLockController airlockController = (TileEntityAirLockController) tile1;
                        airlockController.invertSelection = (Integer) this.data.get(2) == 1;
                    }
                    break;
                case 5:
                    if (tile1 instanceof TileEntityAirLockController) {
                        TileEntityAirLockController airlockController = (TileEntityAirLockController) tile1;
                        airlockController.lastHorizontalModeEnabled = airlockController.horizontalModeEnabled;
                        airlockController.horizontalModeEnabled = (Integer) this.data.get(2) == 1;
                    }
                    break;
                case 6:
                    if (tile1 instanceof IBubbleProvider) {
                        IBubbleProvider distributor = (IBubbleProvider) tile1;
                        distributor.setBubbleVisible((Integer) this.data.get(2) == 1);
                    }
                    break;
                default:
                    break;
            }
            break;
        case S_ON_ADVANCED_GUI_CLICKED_STRING:
            TileEntity tile2 = player.worldObj.getTileEntity((BlockPos) this.data.get(1));
            switch((Integer) this.data.get(0)) {
                case 0:
                    if (tile2 instanceof TileEntityAirLockController) {
                        TileEntityAirLockController airlockController = (TileEntityAirLockController) tile2;
                        airlockController.playerToOpenFor = (String) this.data.get(2);
                    }
                    break;
                default:
                    break;
            }
            break;
        case S_UPDATE_SHIP_MOTION_Y:
            int entityID = (Integer) this.data.get(0);
            boolean up = (Boolean) this.data.get(1);
            Entity entity2 = player.worldObj.getEntityByID(entityID);
            if (entity2 instanceof EntityAutoRocket) {
                EntityAutoRocket autoRocket = (EntityAutoRocket) entity2;
                autoRocket.motionY += up ? 0.02F : -0.02F;
            }
            break;
        case S_START_NEW_SPACE_RACE:
            Integer teamID = (Integer) this.data.get(0);
            String teamName = (String) this.data.get(1);
            FlagData flagData = (FlagData) this.data.get(2);
            Vector3 teamColor = (Vector3) this.data.get(3);
            List<String> playerList = new ArrayList<String>();
            for (int i = 4; i < this.data.size(); i++) {
                playerList.add((String) this.data.get(i));
            }
            boolean previousData = SpaceRaceManager.getSpaceRaceFromID(teamID) != null;
            SpaceRace newRace = new SpaceRace(playerList, teamName, flagData, teamColor);
            if (teamID > 0) {
                newRace.setSpaceRaceID(teamID);
            }
            SpaceRaceManager.addSpaceRace(newRace);
            if (previousData) {
                SpaceRaceManager.sendSpaceRaceData(server, null, SpaceRaceManager.getSpaceRaceFromPlayer(PlayerUtil.getName(playerBase)));
            }
            break;
        case S_REQUEST_FLAG_DATA:
            SpaceRaceManager.sendSpaceRaceData(server, playerBase, SpaceRaceManager.getSpaceRaceFromPlayer((String) this.data.get(0)));
            break;
        case S_INVITE_RACE_PLAYER:
            EntityPlayerMP playerInvited = PlayerUtil.getPlayerBaseServerFromPlayerUsername(server, (String) this.data.get(0), true);
            if (playerInvited != null) {
                Integer teamInvitedTo = (Integer) this.data.get(1);
                SpaceRace race = SpaceRaceManager.getSpaceRaceFromID(teamInvitedTo);
                if (race != null) {
                    GCPlayerStats.get(playerInvited).setSpaceRaceInviteTeamID(teamInvitedTo);
                    String dA = EnumColor.DARK_AQUA.getCode();
                    String bG = EnumColor.BRIGHT_GREEN.getCode();
                    String dB = EnumColor.PURPLE.getCode();
                    String teamNameTotal = "";
                    String[] teamNameSplit = race.getTeamName().split(" ");
                    for (String teamNamePart : teamNameSplit) {
                        teamNameTotal = teamNameTotal.concat(dB + teamNamePart + " ");
                    }
                    playerInvited.addChatMessage(new ChatComponentText(dA + GCCoreUtil.translateWithFormat("gui.space_race.chat.invite_received", bG + PlayerUtil.getName(player) + dA) + "  " + GCCoreUtil.translateWithFormat("gui.space_race.chat.to_join", teamNameTotal, EnumColor.AQUA + "/joinrace" + dA)).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_AQUA)));
                }
            }
            break;
        case S_REMOVE_RACE_PLAYER:
            Integer teamInvitedTo = (Integer) this.data.get(1);
            SpaceRace race = SpaceRaceManager.getSpaceRaceFromID(teamInvitedTo);
            if (race != null) {
                String playerToRemove = (String) this.data.get(0);
                if (!race.getPlayerNames().remove(playerToRemove)) {
                    player.addChatMessage(new ChatComponentText(GCCoreUtil.translateWithFormat("gui.space_race.chat.not_found", playerToRemove)));
                } else {
                    SpaceRaceManager.onPlayerRemoval(server, playerToRemove, race);
                }
            }
            break;
        case S_ADD_RACE_PLAYER:
            Integer teamToAddPlayer = (Integer) this.data.get(1);
            SpaceRace spaceRaceToAddPlayer = SpaceRaceManager.getSpaceRaceFromID(teamToAddPlayer);
            if (spaceRaceToAddPlayer != null) {
                String playerToAdd = (String) this.data.get(0);
                if (!spaceRaceToAddPlayer.getPlayerNames().contains(playerToAdd)) {
                    SpaceRace oldRace = null;
                    while ((oldRace = SpaceRaceManager.getSpaceRaceFromPlayer(playerToAdd)) != null) {
                        SpaceRaceManager.removeSpaceRace(oldRace);
                    }
                    spaceRaceToAddPlayer.getPlayerNames().add(playerToAdd);
                    SpaceRaceManager.sendSpaceRaceData(server, null, spaceRaceToAddPlayer);
                    for (String member : spaceRaceToAddPlayer.getPlayerNames()) {
                        EntityPlayerMP memberObj = PlayerUtil.getPlayerForUsernameVanilla(server, member);
                        if (memberObj != null) {
                            memberObj.addChatMessage(new ChatComponentText(EnumColor.DARK_AQUA + GCCoreUtil.translateWithFormat("gui.space_race.chat.add_success", EnumColor.BRIGHT_GREEN + playerToAdd + EnumColor.DARK_AQUA)).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_AQUA)));
                        }
                    }
                } else {
                    player.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.space_race.chat.already_part")).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_RED)));
                }
            }
            break;
        case S_COMPLETE_CBODY_HANDSHAKE:
            String completeList = (String) this.data.get(0);
            List<String> clientObjects = Arrays.asList(completeList.split(";"));
            List<String> serverObjects = Lists.newArrayList();
            String missingObjects = "";
            for (CelestialBody cBody : GalaxyRegistry.getRegisteredPlanets().values()) {
                serverObjects.add(cBody.getUnlocalizedName());
            }
            for (CelestialBody cBody : GalaxyRegistry.getRegisteredMoons().values()) {
                serverObjects.add(cBody.getUnlocalizedName());
            }
            for (CelestialBody cBody : GalaxyRegistry.getRegisteredSatellites().values()) {
                serverObjects.add(cBody.getUnlocalizedName());
            }
            for (SolarSystem solarSystem : GalaxyRegistry.getRegisteredSolarSystems().values()) {
                serverObjects.add(solarSystem.getUnlocalizedName());
            }
            for (String str : serverObjects) {
                if (!clientObjects.contains(str)) {
                    missingObjects = missingObjects.concat(str + "\n");
                }
            }
            if (missingObjects.length() > 0) {
                playerBase.playerNetServerHandler.kickPlayerFromServer("Missing Galacticraft Celestial Objects:\n\n " + missingObjects);
            }
            break;
        case S_REQUEST_GEAR_DATA:
            String name = (String) this.data.get(0);
            EntityPlayerMP e = PlayerUtil.getPlayerBaseServerFromPlayerUsername(name, true);
            if (e != null) {
                GCPlayerHandler.checkGear(e, GCPlayerStats.get(e), true);
            }
            break;
        case S_BUILDFLAGS_UPDATE:
            stats.setBuildFlags((Integer) this.data.get(0));
            break;
        case S_REQUEST_OVERWORLD_IMAGE:
            MapUtil.sendOverworldToClient(playerBase);
            break;
        case S_REQUEST_MAP_IMAGE:
            int dim = (Integer) this.data.get(0);
            int cx = (Integer) this.data.get(1);
            int cz = (Integer) this.data.get(2);
            MapUtil.sendOrCreateMap(WorldUtil.getProviderForDimensionServer(dim).worldObj, cx, cz, playerBase);
            break;
        case S_REQUEST_PLAYERSKIN:
            String strName = (String) this.data.get(0);
            EntityPlayerMP playerRequested = server.getConfigurationManager().getPlayerByUsername(strName);
            // Player not online
            if (playerRequested == null) {
                return;
            }
            GameProfile gp = playerRequested.getGameProfile();
            if (gp == null) {
                return;
            }
            Property property = (Property) Iterables.getFirst(gp.getProperties().get("textures"), (Object) null);
            if (property == null) {
                return;
            }
            GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_SEND_PLAYERSKIN, getDimensionID(), new Object[] { strName, property.getValue(), property.getSignature(), playerRequested.getUniqueID().toString() }), playerBase);
            break;
        case S_CONTROL_ENTITY:
            if (player.ridingEntity != null && player.ridingEntity instanceof IControllableEntity) {
                ((IControllableEntity) player.ridingEntity).pressKey((Integer) this.data.get(0));
            }
            break;
        case S_NOCLIP_PLAYER:
            boolean noClip = (Boolean) this.data.get(0);
            if (player instanceof GCEntityPlayerMP) {
                GalacticraftCore.proxy.player.setNoClip((EntityPlayerMP) player, noClip);
                if (noClip == false) {
                    player.fallDistance = 0.0F;
                    ((EntityPlayerMP) player).playerNetServerHandler.floatingTickCount = 0;
                }
            } else if (player instanceof EntityPlayerMP) {
                EntityPlayerMP emp = ((EntityPlayerMP) player);
                try {
                    Field f = emp.theItemInWorldManager.getClass().getDeclaredField(GCCoreUtil.isDeobfuscated() ? "gameType" : "field_73091_c");
                    f.setAccessible(true);
                    if (noClip == false) {
                        emp.fallDistance = 0.0F;
                        emp.playerNetServerHandler.floatingTickCount = 0;
                        WorldSettings.GameType gt = savedSettings.get(emp);
                        if (gt != null) {
                            savedSettings.remove(emp);
                            f.set(emp.theItemInWorldManager, gt);
                        }
                    } else {
                        savedSettings.put(emp, emp.theItemInWorldManager.getGameType());
                        f.set(emp.theItemInWorldManager, WorldSettings.GameType.SPECTATOR);
                    }
                } catch (Exception ee) {
                    ee.printStackTrace();
                }
            }
            break;
        case S_REQUEST_DATA:
            WorldServer worldServer = server.worldServerForDimension((Integer) this.data.get(0));
            if (worldServer != null) {
                TileEntity requestedTile = worldServer.getTileEntity((BlockPos) this.data.get(1));
                if (requestedTile instanceof INetworkProvider) {
                    if (((INetworkProvider) requestedTile).getNetwork() instanceof FluidNetwork) {
                        FluidNetwork network = (FluidNetwork) ((INetworkProvider) requestedTile).getNetwork();
                        network.addUpdate(playerBase);
                    }
                }
            }
            break;
        case S_UPDATE_CHECKLIST:
            ItemStack stack = player.getHeldItem();
            if (stack != null && stack.getItem() == GCItems.prelaunchChecklist) {
                NBTTagCompound tagCompound = stack.getTagCompound();
                if (tagCompound == null) {
                    tagCompound = new NBTTagCompound();
                }
                NBTTagCompound tagCompoundRead = (NBTTagCompound) this.data.get(0);
                tagCompound.setTag("checklistData", tagCompoundRead);
                stack.setTagCompound(tagCompound);
            }
            break;
        case S_REQUEST_MACHINE_DATA:
            TileEntity tile3 = player.worldObj.getTileEntity((BlockPos) this.data.get(0));
            if (tile3 instanceof ITileClientUpdates) {
                ((ITileClientUpdates) tile3).sendUpdateToClient(playerBase);
            }
            break;
        default:
            break;
    }
}
Also used : IControllableEntity(micdoodle8.mods.galacticraft.core.entities.IControllableEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityTieredRocket(micdoodle8.mods.galacticraft.api.prefab.entity.EntityTieredRocket) SolarSystem(micdoodle8.mods.galacticraft.api.galaxies.SolarSystem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) Container(net.minecraft.inventory.Container) EntityBuggy(micdoodle8.mods.galacticraft.core.entities.EntityBuggy) IControllableEntity(micdoodle8.mods.galacticraft.core.entities.IControllableEntity) IDisableableMachine(micdoodle8.mods.galacticraft.api.tile.IDisableableMachine) ContainerSchematic(micdoodle8.mods.galacticraft.core.inventory.ContainerSchematic) S07PacketRespawn(net.minecraft.network.play.server.S07PacketRespawn) EntityAutoRocket(micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket) GameProfile(com.mojang.authlib.GameProfile) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) SpaceRace(micdoodle8.mods.galacticraft.core.dimension.SpaceRace) ITileClientUpdates(micdoodle8.mods.galacticraft.api.tile.ITileClientUpdates) TileEntity(net.minecraft.tileentity.TileEntity) Field(java.lang.reflect.Field) ItemParaChute(micdoodle8.mods.galacticraft.core.items.ItemParaChute) FlagData(micdoodle8.mods.galacticraft.core.wrappers.FlagData) ScheduledDimensionChange(micdoodle8.mods.galacticraft.core.wrappers.ScheduledDimensionChange) CelestialBody(micdoodle8.mods.galacticraft.api.galaxies.CelestialBody) Property(com.mojang.authlib.properties.Property) EntitySpaceshipBase(micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase) SpaceStationWorldData(micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData) FluidNetwork(micdoodle8.mods.galacticraft.core.fluid.FluidNetwork) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) INetworkProvider(micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) IBubbleProvider(micdoodle8.mods.galacticraft.core.entities.IBubbleProvider) IOException(java.io.IOException) MinecraftServer(net.minecraft.server.MinecraftServer) ISchematicPage(micdoodle8.mods.galacticraft.api.recipe.ISchematicPage) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 3 with S07PacketRespawn

use of net.minecraft.network.play.server.S07PacketRespawn 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 4 with S07PacketRespawn

use of net.minecraft.network.play.server.S07PacketRespawn in project Galacticraft by micdoodle8.

the class WorldUtil method forceRespawnClient.

@SideOnly(Side.CLIENT)
public static EntityPlayer forceRespawnClient(int dimID, int par2, String par3, int par4) {
    S07PacketRespawn fakePacket = new S07PacketRespawn(dimID, EnumDifficulty.getDifficultyEnum(par2), WorldType.parseWorldType(par3), WorldSettings.GameType.getByID(par4));
    Minecraft.getMinecraft().getNetHandler().handleRespawn(fakePacket);
    return FMLClientHandler.instance().getClientPlayerEntity();
}
Also used : S07PacketRespawn(net.minecraft.network.play.server.S07PacketRespawn) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with S07PacketRespawn

use of net.minecraft.network.play.server.S07PacketRespawn 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)

Aggregations

S07PacketRespawn (net.minecraft.network.play.server.S07PacketRespawn)5 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)3 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)3 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)3 ItemStack (net.minecraft.item.ItemStack)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 Field (java.lang.reflect.Field)2 EntitySpaceshipBase (micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase)2 SpaceRace (micdoodle8.mods.galacticraft.core.dimension.SpaceRace)2 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)2 ItemParaChute (micdoodle8.mods.galacticraft.core.items.ItemParaChute)2 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)2 Entity (net.minecraft.entity.Entity)2 WorldServer (net.minecraft.world.WorldServer)2 GameProfile (com.mojang.authlib.GameProfile)1 Property (com.mojang.authlib.properties.Property)1 IOException (java.io.IOException)1 IWorldTransferCallback (micdoodle8.mods.galacticraft.api.entity.IWorldTransferCallback)1 CelestialBody (micdoodle8.mods.galacticraft.api.galaxies.CelestialBody)1 SolarSystem (micdoodle8.mods.galacticraft.api.galaxies.SolarSystem)1