Search in sources :

Example 46 with GCPlayerStats

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

the class EventHandlerGC method onPlayerRightClickedBlock.

@SubscribeEvent
public void onPlayerRightClickedBlock(PlayerInteractEvent.RightClickBlock event) {
    // Skip events triggered from Thaumcraft Golems and other non-players
    if (event.getEntityPlayer() == null || event.getEntityPlayer().inventory == null || event.getPos() == null || (event.getPos().getX() == 0 && event.getPos().getY() == 0 && event.getPos().getZ() == 0)) {
        return;
    }
    final World worldObj = event.getEntityPlayer().world;
    if (worldObj == null) {
        return;
    }
    final Block idClicked = worldObj.getBlockState(event.getPos()).getBlock();
    if (idClicked == Blocks.BED && worldObj.provider instanceof IGalacticraftWorldProvider && !worldObj.isRemote && !((IGalacticraftWorldProvider) worldObj.provider).hasBreathableAtmosphere()) {
        if (GalacticraftCore.isPlanetsLoaded) {
            GCPlayerStats stats = GCPlayerStats.get(event.getEntityPlayer());
            if (!stats.hasReceivedBedWarning()) {
                event.getEntityPlayer().sendMessage(new TextComponentString(GCCoreUtil.translate("gui.bed_fail.message")));
                stats.setReceivedBedWarning(true);
            }
        }
        if (worldObj.provider instanceof WorldProviderSpaceStation) {
            // On space stations simply block the bed activation => no explosion
            event.setCanceled(true);
            return;
        }
        // Optionally prevent beds from exploding - depends on canRespawnHere() in the WorldProvider interacting with this
        EventHandlerGC.bedActivated = true;
        if (worldObj.provider.canRespawnHere() && !EventHandlerGC.bedActivated) {
            EventHandlerGC.bedActivated = true;
            // On planets allow the bed to be used to designate a player spawn point
            event.getEntityPlayer().setSpawnChunk(event.getPos(), false, GCCoreUtil.getDimensionID(event.getWorld()));
        } else {
            EventHandlerGC.bedActivated = false;
        }
    }
    final ItemStack heldStack = event.getEntityPlayer().inventory.getCurrentItem();
    final TileEntity tileClicked = worldObj.getTileEntity(event.getPos());
    if (!heldStack.isEmpty()) {
        if (tileClicked != null && tileClicked instanceof IKeyable) {
            if (heldStack.getItem() instanceof IKeyItem) {
                if (((IKeyItem) heldStack.getItem()).getTier(heldStack) == -1 || ((IKeyable) tileClicked).getTierOfKeyRequired() == -1 || ((IKeyItem) heldStack.getItem()).getTier(heldStack) == ((IKeyable) tileClicked).getTierOfKeyRequired()) {
                    event.setCanceled(((IKeyable) tileClicked).onValidKeyActivated(event.getEntityPlayer(), heldStack, event.getFace()));
                } else if (!event.getEntityPlayer().isSneaking()) {
                    event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.getEntityPlayer(), event.getFace()));
                }
            } else {
                event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.getEntityPlayer(), event.getFace()));
            }
        }
        if (heldStack.getItem() instanceof ItemFlintAndSteel || heldStack.getItem() instanceof ItemFireball) {
            if (!worldObj.isRemote) {
                if (idClicked != Blocks.TNT && OxygenUtil.noAtmosphericCombustion(event.getEntityPlayer().world.provider) && !OxygenUtil.isAABBInBreathableAirBlock(event.getEntityLiving().world, new AxisAlignedBB(event.getPos().getX(), event.getPos().getY(), event.getPos().getZ(), event.getPos().getX() + 1, event.getPos().getY() + 2, event.getPos().getZ() + 1))) {
                    event.setCanceled(true);
                }
            }
        }
    } else if (tileClicked != null && tileClicked instanceof IKeyable) {
        event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.getEntityPlayer(), event.getFace()));
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ItemFireball(net.minecraft.item.ItemFireball) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) IKeyItem(micdoodle8.mods.galacticraft.api.item.IKeyItem) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) IKeyable(micdoodle8.mods.galacticraft.api.item.IKeyable) World(net.minecraft.world.World) TextComponentString(net.minecraft.util.text.TextComponentString) TileEntity(net.minecraft.tileentity.TileEntity) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) ItemFlintAndSteel(net.minecraft.item.ItemFlintAndSteel) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 47 with GCPlayerStats

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

the class EventHandlerGC method onPlayerDeath.

@SubscribeEvent
public void onPlayerDeath(PlayerDropsEvent event) {
    if (event.getEntityLiving() instanceof EntityPlayerMP) {
        GCPlayerStats stats = GCPlayerStats.get(event.getEntityPlayer());
        if (!event.getEntityPlayer().world.getGameRules().getBoolean("keepInventory")) {
            event.getEntityPlayer().captureDrops = true;
            for (int i = stats.getExtendedInventory().getSizeInventory() - 1; i >= 0; i--) {
                ItemStack stack = stats.getExtendedInventory().getStackInSlot(i);
                if (!stack.isEmpty()) {
                    event.getEntityPlayer().dropItem(stack, true, false);
                    stats.getExtendedInventory().setInventorySlotContents(i, ItemStack.EMPTY);
                }
            }
            event.getEntityLiving().captureDrops = false;
        }
    }
}
Also used : GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 48 with GCPlayerStats

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

the class GCPlayerHandler method sendAirRemainingPacket.

protected static void sendAirRemainingPacket(EntityPlayerMP player, GCPlayerStats stats) {
    final float f1 = stats.getTankInSlot1().isEmpty() ? 0.0F : stats.getTankInSlot1().getMaxDamage() / 90.0F;
    final float f2 = stats.getTankInSlot2().isEmpty() ? 0.0F : stats.getTankInSlot2().getMaxDamage() / 90.0F;
    GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_AIR_REMAINING, GCCoreUtil.getDimensionID(player.world), new Object[] { MathHelper.floor(stats.getAirRemaining() / f1), MathHelper.floor(stats.getAirRemaining2() / f2), PlayerUtil.getName(player) }), player);
}
Also used : PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple)

Example 49 with GCPlayerStats

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

the class GCPlayerHandler method updateSchematics.

protected void updateSchematics(EntityPlayerMP player, GCPlayerStats stats) {
    SchematicRegistry.addUnlockedPage(player, SchematicRegistry.getMatchingRecipeForID(0));
    SchematicRegistry.addUnlockedPage(player, SchematicRegistry.getMatchingRecipeForID(Integer.MAX_VALUE));
    Collections.sort(stats.getUnlockedSchematics());
    if (player.connection != null && (stats.getUnlockedSchematics().size() != stats.getLastUnlockedSchematics().size() || (player.ticksExisted - 1) % 100 == 0)) {
        Integer[] iArray = new Integer[stats.getUnlockedSchematics().size()];
        for (int i = 0; i < iArray.length; i++) {
            ISchematicPage page = stats.getUnlockedSchematics().get(i);
            iArray[i] = page == null ? -2 : page.getPageID();
        }
        List<Object> objList = new ArrayList<Object>();
        objList.add(iArray);
        GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SCHEMATIC_LIST, GCCoreUtil.getDimensionID(player.world), objList), player);
    }
}
Also used : ArrayList(java.util.ArrayList) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) ISchematicPage(micdoodle8.mods.galacticraft.api.recipe.ISchematicPage)

Example 50 with GCPlayerStats

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

the class EntityAstroMiner method setDead.

@Override
public void setDead() {
    if (!this.world.isRemote && this.playerMP != null) {
        GCPlayerStats stats = GCPlayerStats.get(this.playerMP);
        if (!this.spawnedInCreative) {
            int astroCount = stats.getAstroMinerCount();
            if (astroCount > 0) {
                stats.setAstroMinerCount(stats.getAstroMinerCount() - 1);
            }
        }
        AsteroidsTickHandlerServer.removeChunkData(stats, this);
    }
    super.setDead();
    if (posBase != null) {
        TileEntity tileEntity = posBase.getTileEntity(this.world);
        if (tileEntity instanceof TileEntityMinerBase) {
            ((TileEntityMinerBase) tileEntity).unlinkMiner();
        }
    }
    if (this.soundUpdater != null) {
        this.soundUpdater.update();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) TileEntityMinerBase(micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase)

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