Search in sources :

Example 41 with GCPlayerStats

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

the class WorldUtil method toCelestialSelection.

public static void toCelestialSelection(EntityPlayerMP player, GCPlayerStats stats, int tier) {
    player.dismountRidingEntity();
    stats.setSpaceshipTier(tier);
    HashMap<String, Integer> map = WorldUtil.getArrayOfPossibleDimensions(tier, player);
    String dimensionList = "";
    int count = 0;
    for (Entry<String, Integer> entry : map.entrySet()) {
        dimensionList = dimensionList.concat(entry.getKey() + (count < map.entrySet().size() - 1 ? "?" : ""));
        count++;
    }
    boolean canCreateStations = PermissionAPI.hasPermission(player, Constants.PERMISSION_CREATE_STATION);
    GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_DIMENSION_LIST, GCCoreUtil.getDimensionID(player.world), new Object[] { PlayerUtil.getName(player), dimensionList, canCreateStations }), player);
    stats.setUsingPlanetSelectionGui(true);
    stats.setSavedPlanetList(dimensionList);
    Entity fakeEntity = new EntityCelestialFake(player.world, player.posX, player.posY, player.posZ);
    player.world.spawnEntity(fakeEntity);
    player.startRiding(fakeEntity);
}
Also used : Entity(net.minecraft.entity.Entity) EntityCelestialFake(micdoodle8.mods.galacticraft.core.entities.EntityCelestialFake) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple)

Example 42 with GCPlayerStats

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

the class WorldUtil method bindSpaceStationToNewDimension.

public static SpaceStationWorldData bindSpaceStationToNewDimension(World world, EntityPlayerMP player, int homePlanetID) {
    int dynamicProviderID = -1;
    int staticProviderID = -1;
    for (Satellite satellite : GalaxyRegistry.getRegisteredSatellites().values()) {
        if (satellite.getParentPlanet().getDimensionID() == homePlanetID) {
            dynamicProviderID = satellite.getDimensionID();
            staticProviderID = satellite.getDimensionIdStatic();
        }
    }
    if (dynamicProviderID == -1 || staticProviderID == -1) {
        throw new RuntimeException("Space station being bound on bad provider IDs!");
    }
    int newID = DimensionManager.getNextFreeDimId();
    SpaceStationWorldData data = WorldUtil.createSpaceStation(world, newID, homePlanetID, dynamicProviderID, staticProviderID, player);
    dimNames.put(newID, "Space Station " + newID);
    GCPlayerStats stats = GCPlayerStats.get(player);
    stats.getSpaceStationDimensionData().put(homePlanetID, newID);
    GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_CLIENT_ID, GCCoreUtil.getDimensionID(player.world), new Object[] { WorldUtil.spaceStationDataToString(stats.getSpaceStationDimensionData()) }), player);
    return data;
}
Also used : SpaceStationWorldData(micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple)

Example 43 with GCPlayerStats

use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats 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.getRidingEntity() != null) {
        if (entity.getRidingEntity() instanceof EntitySpaceshipBase) {
            entity.startRiding(entity.getRidingEntity());
        } else if (entity.getRidingEntity() instanceof EntityCelestialFake) {
            Entity e = entity.getRidingEntity();
            e.removePassengers();
            e.setDead();
        } else {
            otherRiddenEntity = entity.getRidingEntity();
            entity.dismountRidingEntity();
        }
    }
    boolean dimChange = entity.world != 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.world.updateEntityWithOptionalForce(entity, false);
    EntityPlayerMP player = null;
    Vector3 spawnPos = null;
    int oldDimID = GCCoreUtil.getDimensionID(entity.world);
    if (ridingRocket != null) {
        ArrayList<TileEntityTelemetry> tList = ridingRocket.getTelemetry();
        NBTTagCompound nbt = new NBTTagCompound();
        ridingRocket.isDead = false;
        ridingRocket.removePassengers();
        ridingRocket.writeToNBTOptional(nbt);
        ((WorldServer) ridingRocket.world).getEntityTracker().untrack(ridingRocket);
        removeEntityFromWorld(ridingRocket.world, 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.world;
            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.connection.sendPacket(new SPacketRespawn(dimID, worldNew.getDifficulty(), worldNew.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
            player.mcServer.getPlayerList().updatePermissionLevel(player);
            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.world), 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.getPlayerList().preparePlayer(player, (WorldServer) worldOld);
            player.interactionManager.setWorld((WorldServer) worldNew);
            player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
            player.mcServer.getPlayerList().updateTimeAndWeatherForPlayer(player, (WorldServer) worldNew);
            player.mcServer.getPlayerList().syncPlayerInventory(player);
            for (Object o : player.getActivePotionEffects()) {
                PotionEffect var10 = (PotionEffect) o;
                player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), var10));
            }
            player.connection.sendPacket(new SPacketSetExperience(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.world, 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.world, (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().isEmpty()) {
            for (int stack = 0; stack < stats.getRocketStacks().size(); stack++) {
                if (transferInv) {
                    if (stats.getRocketStacks().get(stack).isEmpty()) {
                        if (stack == stats.getRocketStacks().size() - 1) {
                            if (stats.getRocketItem() != null) {
                                stats.getRocketStacks().set(stack, new ItemStack(stats.getRocketItem(), 1, stats.getRocketType()));
                            }
                        } else if (stack == stats.getRocketStacks().size() - 2) {
                            ItemStack launchpad = stats.getLaunchpadStack();
                            stats.getRocketStacks().set(stack, launchpad == null ? ItemStack.EMPTY : launchpad);
                            stats.setLaunchpadStack(null);
                        }
                    }
                } else {
                    stats.getRocketStacks().set(stack, ItemStack.EMPTY);
                }
            }
        }
        if (transferInv && stats.getChestSpawnCooldown() == 0) {
            stats.setChestSpawnVector(type.getParaChestSpawnLocation((WorldServer) entity.world, player, new Random()));
            stats.setChestSpawnCooldown(200);
        }
    }
    if (ridingRocket != null) {
        boolean previous = CompatibilityManager.forceLoadChunks((WorldServer) worldNew);
        ridingRocket.forceSpawn = true;
        worldNew.spawnEntity(ridingRocket);
        ridingRocket.setWorld(worldNew);
        worldNew.updateEntityWithOptionalForce(ridingRocket, true);
        CompatibilityManager.forceLoadChunksEnd((WorldServer) worldNew, previous);
        entity.startRiding(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.world;
            NBTTagCompound nbt = new NBTTagCompound();
            otherRiddenEntity.writeToNBTOptional(nbt);
            removeEntityFromWorld(worldOld, otherRiddenEntity, true);
            otherRiddenEntity = EntityList.createEntityFromNBT(nbt, worldNew);
            worldNew.spawnEntity(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 : Entity(net.minecraft.entity.Entity) SPacketPlayerAbilities(net.minecraft.network.play.server.SPacketPlayerAbilities) TileEntityTelemetry(micdoodle8.mods.galacticraft.core.tile.TileEntityTelemetry) 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) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) SPacketSetExperience(net.minecraft.network.play.server.SPacketSetExperience) ItemParaChute(micdoodle8.mods.galacticraft.core.items.ItemParaChute) IWorldTransferCallback(micdoodle8.mods.galacticraft.api.entity.IWorldTransferCallback) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) SPacketRespawn(net.minecraft.network.play.server.SPacketRespawn) EntitySpaceshipBase(micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SPacketEntityEffect(net.minecraft.network.play.server.SPacketEntityEffect) ItemStack(net.minecraft.item.ItemStack)

Example 44 with GCPlayerStats

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

the class TileEntityCryogenicChamber method sleepInBedAt.

public EntityPlayer.SleepResult sleepInBedAt(EntityPlayer entityPlayer, int par1, int par2, int par3) {
    if (!this.world.isRemote) {
        if (entityPlayer.isPlayerSleeping() || !entityPlayer.isEntityAlive()) {
            return EntityPlayer.SleepResult.OTHER_PROBLEM;
        }
        if (this.world.getBiome(new BlockPos(par1, par2, par3)) == Biomes.HELL) {
            return EntityPlayer.SleepResult.NOT_POSSIBLE_HERE;
        }
        GCPlayerStats stats = GCPlayerStats.get(entityPlayer);
        if (stats.getCryogenicChamberCooldown() > 0) {
            return EntityPlayer.SleepResult.NOT_POSSIBLE_NOW;
        }
    }
    if (entityPlayer.isRiding()) {
        entityPlayer.dismountRidingEntity();
    }
    entityPlayer.setPosition(this.getPos().getX() + 0.5F, this.getPos().getY() + 1.9F, this.getPos().getZ() + 0.5F);
    entityPlayer.sleeping = true;
    entityPlayer.sleepTimer = 0;
    entityPlayer.bedLocation = new BlockPos(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ());
    entityPlayer.motionX = entityPlayer.motionZ = entityPlayer.motionY = 0.0D;
    if (!this.world.isRemote) {
        this.world.updateAllPlayersSleepingFlag();
    }
    return EntityPlayer.SleepResult.OK;
}
Also used : GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) BlockPos(net.minecraft.util.math.BlockPos)

Example 45 with GCPlayerStats

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

the class TileEntityCryogenicChamber method onActivated.

@Override
public boolean onActivated(EntityPlayer entityPlayer) {
    if (this.world.isRemote) {
        return false;
    }
    EntityPlayer.SleepResult enumstatus = this.sleepInBedAt(entityPlayer, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ());
    switch(enumstatus) {
        case OK:
            ((EntityPlayerMP) entityPlayer).connection.setPlayerLocation(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, entityPlayer.rotationYaw, entityPlayer.rotationPitch);
            GalacticraftCore.packetPipeline.sendTo(new PacketSimpleMars(EnumSimplePacketMars.C_BEGIN_CRYOGENIC_SLEEP, GCCoreUtil.getDimensionID(entityPlayer.world), new Object[] { this.getPos() }), (EntityPlayerMP) entityPlayer);
            return true;
        case NOT_POSSIBLE_NOW:
            GCPlayerStats stats = GCPlayerStats.get(entityPlayer);
            entityPlayer.sendMessage(new TextComponentString(GCCoreUtil.translateWithFormat("gui.cryogenic.chat.cant_use", stats.getCryogenicChamberCooldown() / 20)));
            return false;
        default:
            return false;
    }
}
Also used : GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PacketSimpleMars(micdoodle8.mods.galacticraft.planets.mars.network.PacketSimpleMars) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

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