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

96 lines
2.8 KiB
Java
Raw Normal View History

2015-04-12 20:21:33 +01:00
package techreborn.blocks;
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;
import net.minecraft.util.NonNullList;
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-05-14 14:58:09 -07:00
import java.util.Random;
2016-10-08 20:46:16 +01:00
public class BlockStorage extends BaseBlock implements ITexturedBlock {
2016-03-25 09:47:34 +00:00
public static final String[] types = new String[] { "silver", "aluminum", "titanium", "chrome", "steel", "brass",
2016-10-08 20:46:16 +01:00
"lead", "electrum", "zinc", "platinum", "tungsten", "nickel", "invar", "iridium" };
public PropertyInteger METADATA;
2016-03-25 09:47:34 +00:00
2016-10-08 20:46:16 +01:00
public BlockStorage(Material material) {
2016-03-25 09:47:34 +00:00
super(material);
setUnlocalizedName("techreborn.storage");
setCreativeTab(TechRebornCreativeTabMisc.instance);
setHardness(2f);
this.setDefaultState(this.getDefaultState().withProperty(METADATA, 0));
2016-03-25 09:47:34 +00:00
}
2016-10-08 20:46:16 +01:00
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);
2016-03-25 09:47:34 +00:00
}
}
return BlockStorage2.getStorageBlockByName(name, count);
}
2016-10-08 20:46:16 +01:00
public static ItemStack getStorageBlockByName(String name) {
2016-03-25 09:47:34 +00:00
return getStorageBlockByName(name, 1);
}
@Override
2016-10-08 20:46:16 +01:00
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
2016-03-25 09:47:34 +00:00
return Item.getItemFromBlock(this);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs creativeTabs, NonNullList list) {
2016-10-08 20:46:16 +01:00
for (int meta = 0; meta < types.length; meta++) {
2016-03-25 09:47:34 +00:00
list.add(new ItemStack(item, 1, meta));
}
}
@Override
2016-10-08 20:46:16 +01:00
public int damageDropped(IBlockState state) {
2016-03-25 09:47:34 +00:00
return getMetaFromState(state);
}
@Override
2016-10-08 20:46:16 +01:00
public String getTextureNameFromState(IBlockState BlockStateContainer, EnumFacing facing) {
return "techreborn:blocks/storage/" + types[getMetaFromState(BlockStateContainer)] + "_block";
}
@Override
2016-10-08 20:46:16 +01:00
public int amountOfStates() {
return types.length;
}
@Override
2016-10-08 20:46:16 +01:00
public IBlockState getStateFromMeta(int meta) {
if (meta > types.length) {
2016-05-21 20:05:13 +01:00
meta = 0;
}
return this.getDefaultState().withProperty(METADATA, meta);
2016-03-25 09:47:34 +00:00
}
@Override
2016-10-08 20:46:16 +01:00
public int getMetaFromState(IBlockState state) {
return state.getValue(METADATA);
2016-03-25 09:47:34 +00:00
}
2016-10-08 20:46:16 +01:00
protected BlockStateContainer createBlockState() {
METADATA = PropertyInteger.create("type", 0, types.length - 1);
return new BlockStateContainer(this, METADATA);
2016-03-25 09:47:34 +00:00
}
2015-12-11 19:48:16 +00:00
2015-04-12 20:21:33 +01:00
}