TechReborn/src/main/java/techreborn/blocks/BlockStorage.java

109 lines
2.7 KiB
Java
Raw Normal View History

2015-04-12 20:21:33 +01:00
package techreborn.blocks;
2016-03-24 00:39:26 +00:00
import java.util.List;
import java.util.Random;
import me.modmuss50.jsonDestroyer.api.ITexturedBlock;
2015-04-12 20:21:33 +01:00
import net.minecraft.block.material.Material;
2015-11-24 22:58:18 +00:00
import net.minecraft.block.properties.PropertyInteger;
2016-03-13 16:08:30 +00:00
import net.minecraft.block.state.BlockStateContainer;
2015-11-23 19:37:39 +00:00
import net.minecraft.block.state.IBlockState;
2015-04-12 20:21:33 +01:00
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
2015-11-24 22:58:18 +00:00
import net.minecraft.util.EnumFacing;
2015-11-23 19:19:18 +00:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-11-24 22:58:18 +00:00
import reborncore.common.BaseBlock;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.init.ModBlocks;
2015-04-15 16:23:12 +01:00
2016-03-24 00:39:26 +00:00
public class BlockStorage extends BaseBlock implements ITexturedBlock
{
public static ItemStack getStorageBlockByName(String name, int count)
{
for (int i = 0; i < types.length; i++)
{
if (types[i].equals(name))
{
return new ItemStack(ModBlocks.storage, count, i);
}
}
return BlockStorage2.getStorageBlockByName(name, count);
}
public static ItemStack getStorageBlockByName(String name)
{
return getStorageBlockByName(name, 1);
}
public static final String[] types = new String[] { "silver", "aluminum", "titanium", "chrome", "steel", "brass",
"lead", "electrum", "zinc", "platinum", "tungsten", "nickel", "invar", "osmium", "iridium" };
public PropertyInteger METADATA;
public BlockStorage(Material material)
{
super(material);
setUnlocalizedName("techreborn.storage");
setCreativeTab(TechRebornCreativeTabMisc.instance);
setHardness(2f);
this.setDefaultState(this.getDefaultState().withProperty(METADATA, 0));
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Item.getItemFromBlock(this);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list)
{
for (int meta = 0; meta < types.length; meta++)
{
list.add(new ItemStack(item, 1, meta));
}
}
@Override
public int damageDropped(IBlockState state)
{
return getMetaFromState(state);
}
@Override
public String getTextureNameFromState(IBlockState BlockStateContainer, EnumFacing facing)
{
return "techreborn:blocks/storage/" + types[getMetaFromState(BlockStateContainer)] + "_block";
}
@Override
public int amountOfStates()
{
return types.length;
}
@Override
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(METADATA, meta);
}
@Override
public int getMetaFromState(IBlockState state)
{
return state.getValue(METADATA);
}
protected BlockStateContainer createBlockState()
{
METADATA = PropertyInteger.create("type", 0, types.length - 1);
return new BlockStateContainer(this, METADATA);
}
2015-12-11 19:48:16 +00:00
2015-04-12 20:21:33 +01:00
}