Search in sources :

Example 6 with TileEntityMinerBase

use of micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase 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)

Aggregations

TileEntityMinerBase (micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase)6 TileEntity (net.minecraft.tileentity.TileEntity)6 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)2 UUID (java.util.UUID)1 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)1 PacketDynamic (micdoodle8.mods.galacticraft.core.network.PacketDynamic)1 TileEntityMulti (micdoodle8.mods.galacticraft.core.tile.TileEntityMulti)1 WorldProviderAsteroids (micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids)1 Block (net.minecraft.block.Block)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ChatComponentText (net.minecraft.util.ChatComponentText)1