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

85 lines
2.7 KiB
Java
Raw Normal View History

package techreborn.blocks;
import me.modmuss50.jsonDestroyer.api.ITexturedBlock;
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;
2015-11-26 22:48:30 +01:00
import net.minecraft.util.EnumFacing;
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;
import java.security.InvalidParameterException;
import java.util.List;
public class BlockMachineFrame extends BaseBlock implements ITexturedBlock {
2015-11-26 22:48:30 +01:00
public PropertyInteger METADATA;
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.");
}
public static final String[] types = new String[]
2016-02-20 04:47:35 +01:00
{"aluminum", "iron", "bronze", "brass", "steel", "titanium", "machine", "advancedMachine"};
public BlockMachineFrame(Material material) {
super(material);
2015-11-23 20:19:18 +01:00
setUnlocalizedName("techreborn.machineFrame");
setCreativeTab(TechRebornCreativeTab.instance);
setHardness(1f);
2016-03-13 17:08:30 +01:00
this.setDefaultState(this.getDefaultState().withProperty(METADATA, 0));
}
@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));
}
}
2015-11-23 20:51:40 +01:00
@Override
2015-11-23 20:51:40 +01:00
public int damageDropped(IBlockState state) {
return super.damageDropped(state);
}
2015-11-26 22:48:30 +01:00
@Override
public String getTextureNameFromState(IBlockState blockState, EnumFacing facing) {
return "techreborn:blocks/machine/machine_blocks/" + types[getMetaFromState(blockState)] + "_machine_block";
2015-11-26 22:48:30 +01:00
}
@Override
2016-02-01 16:06:14 +01:00
public int amountOfStates() {
2015-11-26 22:48:30 +01:00
return types.length;
}
@Override
public int getMetaFromState(IBlockState state) {
2015-12-31 00:25:36 +01:00
return state.getValue(METADATA);
2015-11-26 22:48:30 +01:00
}
2016-03-13 19:38:41 +01:00
protected BlockStateContainer createBlockState() {
2015-11-26 22:48:30 +01:00
2016-03-13 19:38:41 +01:00
METADATA = PropertyInteger.create("type", 0, types.length -1);
2016-03-13 17:08:30 +01:00
return new BlockStateContainer(this, METADATA);
2015-11-26 22:48:30 +01:00
}
2015-12-11 20:48:16 +01:00
@Override
public IBlockState getStateFromMeta(int meta) {
2015-12-31 00:25:36 +01:00
return this.getDefaultState().withProperty(METADATA, meta);
2015-12-11 20:48:16 +01:00
}
}