Search in sources :

Example 61 with GCPlayerStats

use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats 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 62 with GCPlayerStats

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

the class EntitySlimeling method interact.

@Override
public boolean interact(EntityPlayer par1EntityPlayer) {
    ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();
    if (this.isTamed()) {
        if (itemstack != null) {
            if (itemstack.getItem() == this.getFavoriteFood()) {
                if (this.isOwner(par1EntityPlayer)) {
                    --itemstack.stackSize;
                    if (itemstack.stackSize <= 0) {
                        par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, (ItemStack) null);
                    }
                    if (this.worldObj.isRemote) {
                        MarsModuleClient.openSlimelingGui(this, 1);
                    }
                    if (this.rand.nextInt(3) == 0) {
                        this.setRandomFavFood();
                    }
                } else {
                    if (par1EntityPlayer instanceof EntityPlayerMP) {
                        GCPlayerStats stats = GCPlayerStats.get(par1EntityPlayer);
                        if (stats.getChatCooldown() == 0) {
                            par1EntityPlayer.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.slimeling.chat.wrong_player")));
                            stats.setChatCooldown(100);
                        }
                    }
                }
            } else {
                if (this.worldObj.isRemote) {
                    MarsModuleClient.openSlimelingGui(this, 0);
                }
            }
        } else {
            if (this.worldObj.isRemote) {
                MarsModuleClient.openSlimelingGui(this, 0);
            }
        }
        return true;
    } else if (itemstack != null && itemstack.getItem() == Items.slime_ball) {
        if (!par1EntityPlayer.capabilities.isCreativeMode) {
            --itemstack.stackSize;
        }
        if (itemstack.stackSize <= 0) {
            par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, (ItemStack) null);
        }
        if (!this.worldObj.isRemote) {
            if (this.rand.nextInt(3) == 0) {
                this.setTamed(true);
                this.getNavigator().clearPathEntity();
                this.setAttackTarget(null);
                this.setSittingAI(true);
                this.setHealth(20.0F);
                this.setOwnerId(par1EntityPlayer.getUniqueID().toString());
                this.setOwnerUsername(par1EntityPlayer.getName());
                this.playTameEffect(true);
                this.worldObj.setEntityState(this, (byte) 7);
            } else {
                this.playTameEffect(false);
                this.worldObj.setEntityState(this, (byte) 6);
            }
        }
        return true;
    }
    return super.interact(par1EntityPlayer);
}
Also used : GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 63 with GCPlayerStats

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

the class TeleportUtils method teleportPlayerToPlanet.

public static EntityPlayer teleportPlayerToPlanet(EntityPlayerMP player, MinecraftServer server, int sourceDim, int targetDim) {
    WorldServer sourceWorld = server.getWorld(sourceDim);
    WorldServer targetWorld = server.getWorld(targetDim);
    BlockPos spawnPos = targetWorld.getTopSolidOrLiquidBlock(targetWorld.getSpawnPoint());
    PlayerList playerList = server.getPlayerList();
    GCPlayerStats stats = GCPlayerStats.get(player);
    InventoryExtended inv = stats.getExtendedInventory();
    player.dimension = targetDim;
    player.connection.sendPacket(new SPacketRespawn(player.dimension, targetWorld.getDifficulty(), targetWorld.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
    playerList.updatePermissionLevel(player);
    sourceWorld.removeEntityDangerously(player);
    player.isDead = false;
    // world transfer
    player.setLocationAndAngles(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), player.rotationYaw, player.rotationPitch);
    player.connection.setPlayerLocation(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), player.rotationYaw, player.rotationPitch);
    targetWorld.spawnEntity(player);
    targetWorld.updateEntityWithOptionalForce(player, false);
    player.setWorld(targetWorld);
    // prevent kicked from LAN or server world
    MorePlanetsMod.PROXY.resetFloatingTick(player);
    playerList.preparePlayer(player, sourceWorld);
    player.connection.setPlayerLocation(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), player.rotationYaw, player.rotationPitch);
    player.interactionManager.setWorld(targetWorld);
    player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
    playerList.updateTimeAndWeatherForPlayer(player, targetWorld);
    playerList.syncPlayerInventory(player);
    if (targetWorld.provider instanceof IStartedDimension) {
        IStartedDimension dimension = (IStartedDimension) targetWorld.provider;
        LoggerMP.info("Setting up survival player gear");
        dimension.setup(player);
    } else if (targetWorld.provider instanceof WorldProviderMoon) {
        LoggerMP.info("Setting up default survival player gear for Moon");
        inv.setInventorySlotContents(0, new ItemStack(GCItems.oxMask));
        inv.setInventorySlotContents(1, new ItemStack(GCItems.oxygenGear));
        inv.setInventorySlotContents(2, new ItemStack(GCItems.oxTankMedium));
        inv.setInventorySlotContents(3, new ItemStack(GCItems.oxTankMedium));
        inv.setInventorySlotContents(4, new ItemStack(GCItems.parachute));
        inv.setInventorySlotContents(5, new ItemStack(GCItems.basicItem, 1, 19));
        player.inventory.addItemStackToInventory(new ItemStack(Blocks.LOG, 32 + player.world.rand.nextInt(32)));
        player.inventory.addItemStackToInventory(new ItemStack(Blocks.COBBLESTONE, 32 + player.world.rand.nextInt(32)));
        player.inventory.addItemStackToInventory(new ItemStack(Blocks.DIRT, 16));
        player.inventory.addItemStackToInventory(new ItemStack(Blocks.SAPLING, 8 + player.world.rand.nextInt(8)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.IRON_INGOT, 32 + player.world.rand.nextInt(16)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.WHEAT_SEEDS, 16 + player.world.rand.nextInt(16)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.POTATO, 16 + player.world.rand.nextInt(16)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.CARROT, 16 + player.world.rand.nextInt(16)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
        player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
        player.inventory.addItemStackToInventory(new ItemStack(GCBlocks.landingPad, 9));
        ItemStack rocket = new ItemStack(GCItems.rocketTier1);
        rocket.setTagCompound(new NBTTagCompound());
        rocket.getTagCompound().setInteger("RocketFuel", 1000);
        player.inventory.addItemStackToInventory(rocket);
        player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
        player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
        player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
    } else if (targetWorld.provider instanceof WorldProviderMars) {
        LoggerMP.info("Setting up default survival player gear for Mars");
        // Knows how to build T2 rocket
        SchematicRegistry.unlockNewPage(player, new ItemStack(GCItems.schematic, 1, 1));
        inv.setInventorySlotContents(0, new ItemStack(GCItems.oxMask));
        inv.setInventorySlotContents(1, new ItemStack(GCItems.oxygenGear));
        inv.setInventorySlotContents(2, new ItemStack(GCItems.oxTankMedium));
        inv.setInventorySlotContents(3, new ItemStack(GCItems.oxTankMedium));
        inv.setInventorySlotContents(4, new ItemStack(GCItems.parachute));
        inv.setInventorySlotContents(5, new ItemStack(GCItems.basicItem, 1, 19));
        inv.setInventorySlotContents(6, new ItemStack(AsteroidsItems.thermalPadding));
        inv.setInventorySlotContents(7, new ItemStack(AsteroidsItems.thermalPadding, 1, 1));
        inv.setInventorySlotContents(8, new ItemStack(AsteroidsItems.thermalPadding, 1, 2));
        inv.setInventorySlotContents(9, new ItemStack(AsteroidsItems.thermalPadding, 1, 3));
        player.inventory.addItemStackToInventory(new ItemStack(Blocks.LOG, 32 + player.world.rand.nextInt(32)));
        player.inventory.addItemStackToInventory(new ItemStack(Blocks.COBBLESTONE, 32 + player.world.rand.nextInt(32)));
        player.inventory.addItemStackToInventory(new ItemStack(Blocks.DIRT, 16));
        player.inventory.addItemStackToInventory(new ItemStack(Blocks.SAPLING, 8 + player.world.rand.nextInt(8)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.IRON_INGOT, 32 + player.world.rand.nextInt(16)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.WHEAT_SEEDS, 16 + player.world.rand.nextInt(16)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.POTATO, 16 + player.world.rand.nextInt(16)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.CARROT, 16 + player.world.rand.nextInt(16)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
        player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
        player.inventory.addItemStackToInventory(new ItemStack(GCBlocks.landingPad, 9));
        ItemStack rocket = new ItemStack(MarsItems.rocketMars);
        rocket.setTagCompound(new NBTTagCompound());
        rocket.getTagCompound().setInteger("RocketFuel", 1000);
        player.inventory.addItemStackToInventory(rocket);
        player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
        player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
        player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
        player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
    } else if (targetWorld.provider instanceof WorldProviderVenus) {
        LoggerMP.info("Setting up default survival player gear for Venus");
        // Knows how to build T2 rocket
        SchematicRegistry.unlockNewPage(player, new ItemStack(GCItems.schematic, 1, 1));
        // Knows how to build T3 rocket
        SchematicRegistry.unlockNewPage(player, new ItemStack(MarsItems.schematic, 1, 0));
        inv.setInventorySlotContents(0, new ItemStack(GCItems.oxMask));
        inv.setInventorySlotContents(1, new ItemStack(GCItems.oxygenGear));
        inv.setInventorySlotContents(2, new ItemStack(GCItems.oxTankHeavy));
        inv.setInventorySlotContents(3, new ItemStack(GCItems.oxTankHeavy));
        inv.setInventorySlotContents(4, new ItemStack(GCItems.parachute));
        inv.setInventorySlotContents(5, new ItemStack(GCItems.basicItem, 1, 19));
        inv.setInventorySlotContents(6, new ItemStack(VenusItems.thermalPaddingTier2));
        inv.setInventorySlotContents(7, new ItemStack(VenusItems.thermalPaddingTier2, 1, 1));
        inv.setInventorySlotContents(8, new ItemStack(VenusItems.thermalPaddingTier2, 1, 2));
        inv.setInventorySlotContents(9, new ItemStack(VenusItems.thermalPaddingTier2, 1, 3));
        inv.setInventorySlotContents(10, new ItemStack(VenusItems.basicItem));
        player.inventory.addItemStackToInventory(new ItemStack(Blocks.LOG, 32 + player.world.rand.nextInt(32)));
        player.inventory.addItemStackToInventory(new ItemStack(Blocks.COBBLESTONE, 32 + player.world.rand.nextInt(32)));
        player.inventory.addItemStackToInventory(new ItemStack(Blocks.DIRT, 16));
        player.inventory.addItemStackToInventory(new ItemStack(Blocks.SAPLING, 8 + player.world.rand.nextInt(8)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.IRON_INGOT, 32 + player.world.rand.nextInt(16)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.WHEAT_SEEDS, 16 + player.world.rand.nextInt(16)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.POTATO, 16 + player.world.rand.nextInt(16)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.CARROT, 16 + player.world.rand.nextInt(16)));
        player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
        player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
        player.inventory.addItemStackToInventory(new ItemStack(GCBlocks.landingPad, 9));
        ItemStack rocket = new ItemStack(AsteroidsItems.tier3Rocket);
        rocket.setTagCompound(new NBTTagCompound());
        rocket.getTagCompound().setInteger("RocketFuel", 1000);
        player.inventory.addItemStackToInventory(rocket);
        player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
        player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
        player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
        player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
    } else if (targetWorld.provider instanceof WorldProviderAsteroids) {
        LoggerMP.info("Setting up default survival player gear for Asteroids");
        ITeleportType type = GalacticraftRegistry.getTeleportTypeForDimension(targetWorld.provider.getClass());
        Vector3 spawnPosVec = type.getPlayerSpawnLocation(targetWorld, player);
        ChunkPos pair = targetWorld.getChunk(spawnPosVec.intX() >> 4, spawnPosVec.intZ() >> 4).getPos();
        player.setLocationAndAngles(spawnPosVec.x, spawnPosVec.y, spawnPosVec.z, player.rotationYaw, player.rotationPitch);
        player.setSpawnChunk(new BlockPos(spawnPosVec.intX(), spawnPosVec.intY(), spawnPosVec.intZ()), true, GCCoreUtil.getDimensionID(targetWorld));
        targetWorld.getChunkProvider().loadChunk(pair.x, pair.z);
        type.setupAdventureSpawn(player);
        type.onSpaceDimensionChanged(targetWorld, player, false);
    } else {
        LoggerMP.info("Setting up default survival player gear for Non-IStartedDimension world");
        // Knows how to build T2 rocket
        SchematicRegistry.unlockNewPage(player, new ItemStack(GCItems.schematic, 1, 1));
        // Knows how to build T3 rocket
        SchematicRegistry.unlockNewPage(player, new ItemStack(MarsItems.schematic, 1, 0));
        inv.setInventorySlotContents(0, new ItemStack(GCItems.oxMask));
        inv.setInventorySlotContents(1, new ItemStack(GCItems.oxygenGear));
        inv.setInventorySlotContents(2, new ItemStack(GCItems.oxTankHeavy));
        inv.setInventorySlotContents(3, new ItemStack(GCItems.oxTankHeavy));
        inv.setInventorySlotContents(5, new ItemStack(GCItems.basicItem, 1, 19));
        inv.setInventorySlotContents(6, new ItemStack(AsteroidsItems.thermalPadding));
        inv.setInventorySlotContents(7, new ItemStack(AsteroidsItems.thermalPadding, 1, 1));
        inv.setInventorySlotContents(8, new ItemStack(AsteroidsItems.thermalPadding, 1, 2));
        inv.setInventorySlotContents(9, new ItemStack(AsteroidsItems.thermalPadding, 1, 3));
        player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
        player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
        player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
    }
    player.addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, 15 * 20, 5));
    player.getActivePotionEffects().forEach(potion -> player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potion)));
    player.connection.sendPacket(new SPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
    player.connection.sendPacket(new SPacketSpawnPosition(spawnPos));
    AttributeMap attributemap = (AttributeMap) player.getAttributeMap();
    Collection<IAttributeInstance> watchedAttribs = attributemap.getWatchedAttributes();
    if (!watchedAttribs.isEmpty()) {
        player.connection.sendPacket(new SPacketEntityProperties(player.getEntityId(), watchedAttribs));
    }
    FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, sourceDim, targetDim);
    if (!(targetWorld.provider instanceof WorldProviderAsteroids)) {
        player.setLocationAndAngles(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), player.rotationYaw, player.rotationPitch);
        player.setSpawnChunk(spawnPos, true, GCCoreUtil.getDimensionID(player.world));
    }
    if (!(targetWorld.provider instanceof WorldProviderAsteroids) && player.onGround && player.getBedLocation(GCCoreUtil.getDimensionID(player.world)) == null) {
        int i = 30000000;
        int x = Math.min(i, Math.max(-i, MathHelper.floor(player.posX + 0.5D)));
        int y = Math.min(256, Math.max(0, MathHelper.floor(player.posY + 1.5D)));
        int z = Math.min(i, Math.max(-i, MathHelper.floor(player.posZ + 0.5D)));
        BlockPos spawnChunkPos = targetWorld.getTopSolidOrLiquidBlock(new BlockPos(x, y, z));
        player.setSpawnChunk(spawnChunkPos, true, GCCoreUtil.getDimensionID(player.world));
    }
    GalacticraftCore.packetPipeline.sendTo(new PacketSimpleMP(EnumSimplePacketMP.C_RELOAD_RENDERER, player.dimension), player);
    GalacticraftCore.packetPipeline.sendTo(new PacketSimpleMP(EnumSimplePacketMP.C_MESSAGE_SURVIVAL_PLANET, player.dimension, new Object[] { WorldUtil.getProviderForDimensionServer(targetDim).getDimensionType().getName() }), player);
    return player;
}
Also used : InventoryExtended(micdoodle8.mods.galacticraft.core.inventory.InventoryExtended) WorldProviderMars(micdoodle8.mods.galacticraft.planets.mars.dimension.WorldProviderMars) PlayerList(net.minecraft.server.management.PlayerList) PotionEffect(net.minecraft.potion.PotionEffect) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) WorldServer(net.minecraft.world.WorldServer) WorldProviderAsteroids(micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids) WorldProviderMoon(micdoodle8.mods.galacticraft.core.dimension.WorldProviderMoon) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) PacketSimpleMP(stevekung.mods.moreplanets.network.PacketSimpleMP) ITeleportType(micdoodle8.mods.galacticraft.api.world.ITeleportType) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) IStartedDimension(stevekung.mods.moreplanets.world.IStartedDimension) AttributeMap(net.minecraft.entity.ai.attributes.AttributeMap) ItemStack(net.minecraft.item.ItemStack) WorldProviderVenus(micdoodle8.mods.galacticraft.planets.venus.dimension.WorldProviderVenus)

Example 64 with GCPlayerStats

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

the class WorldProviderNibiru method setup.

@Override
public void setup(EntityPlayerMP player) {
    GCPlayerStats stats = GCPlayerStats.get(player);
    // Knows how to build T2 rocket
    SchematicRegistry.unlockNewPage(player, new ItemStack(GCItems.schematic, 1, 1));
    // Knows how to build T3 rocket
    SchematicRegistry.unlockNewPage(player, new ItemStack(MarsItems.schematic, 1, 0));
    player.addPotionEffect(new PotionEffect(MPPotions.INFECTED_SPORE_PROTECTION, 36020, 0, true, true));
    stats.getExtendedInventory().setInventorySlotContents(0, new ItemStack(GCItems.oxMask, 1, 0));
    stats.getExtendedInventory().setInventorySlotContents(1, new ItemStack(GCItems.oxygenGear, 1, 0));
    stats.getExtendedInventory().setInventorySlotContents(2, new ItemStack(GCItems.oxTankHeavy, 1, 0));
    stats.getExtendedInventory().setInventorySlotContents(3, new ItemStack(GCItems.oxTankHeavy, 1, 0));
    stats.getExtendedInventory().setInventorySlotContents(5, new ItemStack(GCItems.basicItem, 1, 19));
    stats.getExtendedInventory().setInventorySlotContents(6, new ItemStack(VenusItems.thermalPaddingTier2, 1, 0));
    stats.getExtendedInventory().setInventorySlotContents(7, new ItemStack(VenusItems.thermalPaddingTier2, 1, 1));
    stats.getExtendedInventory().setInventorySlotContents(8, new ItemStack(VenusItems.thermalPaddingTier2, 1, 2));
    stats.getExtendedInventory().setInventorySlotContents(9, new ItemStack(VenusItems.thermalPaddingTier2, 1, 3));
    stats.getExtendedInventory().setInventorySlotContents(10, new ItemStack(VenusItems.basicItem, 1, 0));
    player.inventory.addItemStackToInventory(new ItemStack(MPItems.INFECTED_SPORE_PROTECTION_CAPSULE));
    player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
    player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
}
Also used : PotionEffect(net.minecraft.potion.PotionEffect) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) ItemStack(net.minecraft.item.ItemStack)

Example 65 with GCPlayerStats

use of micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats 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.world;
            try {
                worldOld.getPlayerChunkMap().removePlayer(player);
            } catch (Exception e) {
            }
            worldOld.playerEntities.remove(player);
            worldOld.updateAllPlayersSleepingFlag();
            worldOld.loadedEntityList.remove(player);
            worldOld.onEntityRemoved(player);
            worldOld.getEntityTracker().untrack(player);
            if (player.addedToChunk && worldOld.getChunkProvider().chunkExists(player.chunkCoordX, player.chunkCoordZ)) {
                Chunk chunkOld = worldOld.getChunkFromChunkCoords(player.chunkCoordX, player.chunkCoordZ);
                chunkOld.removeEntity(player);
                chunkOld.setModified(true);
            }
            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.connection.sendPacket(new SPacketRespawn(dimID, player.world.getDifficulty(), player.world.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
            if (worldNew.provider instanceof WorldProviderSpaceStation) {
                GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(player.world), new Object[] {}), player);
            }
            worldNew.spawnEntity(player);
            player.setWorld(worldNew);
            player.mcServer.getPlayerList().preparePlayer(player, (WorldServer) worldOld);
        }
        // This is a mini version of the code at WorldUtil.teleportEntity
        player.interactionManager.setWorld((WorldServer) player.world);
        final ITeleportType type = GalacticraftRegistry.getTeleportTypeForDimension(player.world.provider.getClass());
        Vector3 spawnPos = type.getPlayerSpawnLocation((WorldServer) player.world, player);
        ChunkPos pair = player.world.getChunkFromChunkCoords(spawnPos.intX() >> 4, spawnPos.intZ() >> 4).getPos();
        GCLog.debug("Loading first chunk in new dimension.");
        ((WorldServer) player.world).getChunkProvider().loadChunk(pair.x, pair.z);
        player.setLocationAndAngles(spawnPos.x, spawnPos.y, spawnPos.z, player.rotationYaw, player.rotationPitch);
        type.setupAdventureSpawn(player);
        type.onSpaceDimensionChanged(player.world, player, false);
        player.setSpawnChunk(new BlockPos(spawnPos.intX(), spawnPos.intY(), spawnPos.intZ()), true, GCCoreUtil.getDimensionID(player.world));
        stats.setNewAdventureSpawn(true);
    }
    final boolean isInGCDimension = player.world.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.world), new Object[] {}), player);
            }
            stats.setOpenedSpaceRaceManager(true);
        }
        if (!stats.hasSentFlags()) {
            GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_STATS, GCCoreUtil.getDimensionID(player.world), 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().isEmpty()) {
            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.connection.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.getRidingEntity() 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.world)) == null || stats.isNewAdventureSpawn()) {
                int i = 30000000;
                int j = Math.min(i, Math.max(-i, MathHelper.floor(player.posX + 0.5D)));
                int k = Math.min(256, Math.max(0, MathHelper.floor(player.posY + 1.5D)));
                int l = Math.min(i, Math.max(-i, MathHelper.floor(player.posZ + 0.5D)));
                BlockPos coords = new BlockPos(j, k, l);
                player.setSpawnChunk(coords, true, GCCoreUtil.getDimensionID(player.world));
                stats.setNewAdventureSpawn(false);
            }
            GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(player.world), new Object[] {}), player);
        }
        if (player.world.provider instanceof WorldProviderSpaceStation || player.world.provider instanceof IZeroGDimension || GalacticraftCore.isPlanetsLoaded && player.world.provider instanceof WorldProviderAsteroids) {
            this.preventFlyingKicks(player);
            if (player.world.provider instanceof WorldProviderSpaceStation && stats.isNewInOrbit()) {
                ((WorldProviderSpaceStation) player.world.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.world, stats.getRocketStacks(), stats.getFuelLevel());
                chest.setPosition(stats.getChestSpawnVector().x, stats.getChestSpawnVector().y, stats.getChestSpawnVector().z);
                chest.color = stats.getParachuteInSlot().isEmpty() ? EnumDyeColor.WHITE : ItemParaChute.getDyeEnumFromParachuteDamage(stats.getParachuteInSlot().getItemDamage());
                if (!player.world.isRemote) {
                    player.world.spawnEntity(chest);
                }
            }
        }
    }
    if (stats.getLaunchAttempts() > 0 && player.getRidingEntity() == 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, player.world.provider.getDimension(), new Object[] { stats.isOxygenSetupValid() }), player);
    }
    this.throwMeteors(player);
    this.updateSchematics(player, stats);
    if (tick % 250 == 0 && stats.getFrequencyModuleInSlot().isEmpty() && !stats.hasReceivedSoundWarning() && isInGCDimension && player.onGround && tick > 0 && ((IGalacticraftWorldProvider) player.world.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.sendMessage(new TextComponentString(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 (ItemStack armorPiece : player.getArmorInventoryList()) {
            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) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) WorldServer(net.minecraft.world.WorldServer) TextComponentString(net.minecraft.util.text.TextComponentString) 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) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) SPacketRespawn(net.minecraft.network.play.server.SPacketRespawn) 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) TextComponentString(net.minecraft.util.text.TextComponentString) 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

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