ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/blocks/BlockMiner.java

105 lines
3.9 KiB
Java
Raw Normal View History

/*
* 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://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015 Ellpeck
*/
2015-12-30 22:02:15 +01:00
package de.ellpeck.actuallyadditions.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2015-12-30 22:02:15 +01:00
import de.ellpeck.actuallyadditions.ActuallyAdditions;
import de.ellpeck.actuallyadditions.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.tile.TileEntityMiner;
import de.ellpeck.actuallyadditions.util.ModUtil;
import de.ellpeck.actuallyadditions.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;
2015-12-09 16:54:25 +01:00
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;
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
2015-12-19 10:30:39 +01:00
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);
2015-12-19 10:30:39 +01:00
}
}
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");
}
2015-12-19 10:30:39 +01:00
@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);
}
}
}