ActuallyAdditions/src/main/java/ellpeck/actuallyadditions/blocks/BlockMisc.java

97 lines
2.9 KiB
Java
Raw Normal View History

2015-03-07 12:51:28 +01:00
package ellpeck.actuallyadditions.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2015-03-07 12:51:28 +01:00
import ellpeck.actuallyadditions.blocks.metalists.TheMiscBlocks;
import ellpeck.actuallyadditions.util.IName;
import ellpeck.actuallyadditions.util.Util;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import java.util.List;
public class BlockMisc extends Block implements IName{
public static final TheMiscBlocks[] allMiscBlocks = TheMiscBlocks.values();
public IIcon[] textures = new IIcon[allMiscBlocks.length];
public BlockMisc(){
super(Material.rock);
}
@SuppressWarnings("all")
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs tab, List list){
2015-03-07 12:51:28 +01:00
for (int j = 0; j < allMiscBlocks.length; j++){
list.add(new ItemStack(item, 1, j));
}
}
@Override
public int damageDropped(int meta){
2015-03-07 12:51:28 +01:00
return meta;
}
@Override
public IIcon getIcon(int side, int metadata){
return textures[metadata];
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconReg){
for(int i = 0; i < textures.length; i++){
textures[i] = iconReg.registerIcon(Util.MOD_ID_LOWER + ":" + this.getName() + allMiscBlocks[i].getName());
}
}
@Override
public String getName(){
return "blockMisc";
}
public static class TheItemBlock extends ItemBlock{
private Block theBlock;
public TheItemBlock(Block block){
super(block);
this.theBlock = block;
this.setHasSubtypes(true);
this.setMaxDamage(0);
}
@Override
public EnumRarity getRarity(ItemStack stack){
return allMiscBlocks[stack.getItemDamage()].rarity;
}
@Override
public String getUnlocalizedName(ItemStack stack){
return this.getUnlocalizedName() + allMiscBlocks[stack.getItemDamage()].getName();
}
@Override
@SuppressWarnings("unchecked")
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld) {
if(Util.isShiftPressed()) list.add(StatCollector.translateToLocal("tooltip." + Util.MOD_ID_LOWER + "." + ((IName)theBlock).getName() + allMiscBlocks[stack.getItemDamage()].getName() + ".desc"));
else list.add(Util.shiftForInfo());
}
@Override
public int getMetadata(int damage){
return damage;
}
}
}