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

68 lines
2.1 KiB
Java
Raw Normal View History

package techreborn.blocks;
import net.minecraft.block.material.Material;
2015-11-26 22:48:30 +01:00
import net.minecraft.block.properties.PropertyInteger;
2016-03-13 17:08:30 +01:00
import net.minecraft.block.state.BlockStateContainer;
2015-11-23 20:51:40 +01:00
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
2015-11-23 20:19:18 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-11-26 22:48:30 +01:00
import reborncore.common.BaseBlock;
import techreborn.client.TechRebornCreativeTab;
import techreborn.init.ModBlocks;
2016-05-01 05:01:10 +02:00
import java.security.InvalidParameterException;
2016-12-05 11:17:39 +01:00
public class BlockMachineFrame extends BaseBlock {
2016-10-08 21:46:16 +02:00
public static final String[] types = new String[] { "machine", "advancedMachine", "highlyAdvancedMachine" };
public static final PropertyInteger METADATA = PropertyInteger.create("type", 0, types.length - 1);
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
public BlockMachineFrame(Material material) {
super(material);
setUnlocalizedName("techreborn.machineFrame");
setCreativeTab(TechRebornCreativeTab.instance);
setHardness(1f);
this.setDefaultState(this.getDefaultState().withProperty(METADATA, 0));
}
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
public static ItemStack getFrameByName(String name, int count) {
for (int i = 0; i < types.length; i++) {
if (types[i].equalsIgnoreCase(name)) {
return new ItemStack(ModBlocks.machineframe, count, i);
}
}
throw new InvalidParameterException("The part " + name + " could not be found.");
}
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs creativeTabs, NonNullList<ItemStack> list) {
2016-10-08 21:46:16 +02:00
for (int meta = 0; meta < types.length; meta++) {
list.add(new ItemStack(item, 1, meta));
}
}
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
@Override
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(METADATA);
}
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, METADATA);
}
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(METADATA, meta);
}
2016-03-25 10:47:34 +01:00
}