/* * This file ("BlockMiner.java") is part of the Actually Additions Mod for Minecraft. * It is created and owned by Ellpeck and distributed * under the Actually Additions License to be found at * http://ellpeck.de/actaddlicense/ * View the source code at https://github.com/Ellpeck/ActuallyAdditions * * © 2016 Ellpeck */ package de.ellpeck.actuallyadditions.mod.blocks; import de.ellpeck.actuallyadditions.api.block.IHudDisplay; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler; import de.ellpeck.actuallyadditions.mod.tile.TileEntityMiner; import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemStack; import net.minecraft.profiler.Profiler; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class BlockMiner extends BlockContainerBase implements IHudDisplay{ @SideOnly(Side.CLIENT) private IIcon frontIcon; @SideOnly(Side.CLIENT) private IIcon topIcon; public BlockMiner(String name){ super(Material.rock, name); this.setHarvestLevel("pickaxe", 0); this.setHardness(8F); this.setResistance(30F); this.setStepSound(soundTypeStone); } @Override @SideOnly(Side.CLIENT) public IIcon getIcon(int side, int meta){ return side == 0 ? this.frontIcon : (side == 1 ? this.topIcon : this.blockIcon); } @Override public boolean isOpaqueCube(){ return false; } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){ if(!world.isRemote){ TileEntity tile = world.getTileEntity(x, y, z); if(tile instanceof TileEntityMiner){ player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.MINER.ordinal(), world, x, y, z); } } return true; } @Override @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconReg){ this.blockIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getBaseName()); this.frontIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getBaseName()+"Front"); this.topIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getBaseName()+"Top"); } @Override public EnumRarity getRarity(ItemStack stack){ return EnumRarity.rare; } @Override public TileEntity createNewTileEntity(World world, int i){ return new TileEntityMiner(); } @Override public void breakBlock(World world, int x, int y, int z, Block block, int par6){ this.dropInventory(world, x, y, z); super.breakBlock(world, x, y, z, block, par6); } @Override @SideOnly(Side.CLIENT) public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, MovingObjectPosition posHit, Profiler profiler, ScaledResolution resolution){ TileEntity tile = minecraft.theWorld.getTileEntity(posHit.blockX, posHit.blockY, posHit.blockZ); if(tile instanceof TileEntityMiner){ String info = ((TileEntityMiner)tile).layerAt <= 0 ? "Done Mining!" : "Mining at Y = "+((TileEntityMiner)tile).layerAt+"."; minecraft.fontRenderer.drawStringWithShadow(info, resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2-20, StringUtil.DECIMAL_COLOR_WHITE); } } }