2015-11-17 15:52:31 -08:00
|
|
|
package WayofTime.bloodmagic.block.base;
|
|
|
|
|
|
|
|
import lombok.Getter;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.block.properties.PropertyInteger;
|
2016-03-18 12:01:58 -07:00
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
2015-11-17 15:52:31 -08:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2016-03-17 13:00:44 -07:00
|
|
|
|
|
|
|
import java.util.List;
|
2015-11-17 15:52:31 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a block that has multiple meta-based states.
|
2015-12-30 15:34:40 -05:00
|
|
|
*
|
2015-11-17 15:52:31 -08:00
|
|
|
* These states will be numbered 0 through {@code maxMeta}.
|
|
|
|
*/
|
|
|
|
@Getter
|
2015-12-30 15:34:40 -05:00
|
|
|
public class BlockInteger extends Block
|
|
|
|
{
|
2015-11-17 15:52:31 -08:00
|
|
|
private final int maxMeta;
|
2016-10-15 09:21:30 -07:00
|
|
|
private final PropertyInteger property;
|
|
|
|
private final BlockStateContainer realStateContainer;
|
2015-11-17 15:52:31 -08:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public BlockInteger(Material material, int maxMeta, String propName)
|
|
|
|
{
|
2015-11-17 15:52:31 -08:00
|
|
|
super(material);
|
|
|
|
|
|
|
|
this.maxMeta = maxMeta;
|
2016-10-15 09:21:30 -07:00
|
|
|
this.property = PropertyInteger.create(propName, 0, maxMeta);
|
|
|
|
this.realStateContainer = createStateContainer();
|
|
|
|
setDefaultState(getBlockState().getBaseState());
|
2015-11-17 15:52:31 -08:00
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public BlockInteger(Material material, int maxMeta)
|
|
|
|
{
|
2015-11-17 15:52:31 -08:00
|
|
|
this(material, maxMeta, "meta");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-15 09:21:30 -07:00
|
|
|
protected final BlockStateContainer createBlockState() {
|
|
|
|
return new BlockStateContainer.Builder(this).build(); // Blank to avoid crashes
|
2015-11-17 15:52:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-15 09:21:30 -07:00
|
|
|
public final BlockStateContainer getBlockState() {
|
|
|
|
return realStateContainer;
|
2015-11-17 15:52:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-15 09:21:30 -07:00
|
|
|
public IBlockState getStateFromMeta(int meta) {
|
|
|
|
return getDefaultState().withProperty(property, meta);
|
2015-11-17 15:52:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-15 09:21:30 -07:00
|
|
|
public int getMetaFromState(IBlockState state) {
|
|
|
|
return state.getValue(property);
|
2015-11-17 15:52:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-15 09:21:30 -07:00
|
|
|
public int damageDropped(IBlockState state) {
|
|
|
|
return getMetaFromState(state);
|
2015-11-17 15:52:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2016-10-15 09:21:30 -07:00
|
|
|
@Override
|
|
|
|
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> subBlocks) {
|
|
|
|
for (int i = 0; i < maxMeta; i++)
|
|
|
|
subBlocks.add(new ItemStack(item, 1, i));
|
2015-11-17 15:52:31 -08:00
|
|
|
}
|
|
|
|
|
2016-10-15 09:21:30 -07:00
|
|
|
protected BlockStateContainer createStateContainer() {
|
|
|
|
return new BlockStateContainer.Builder(this).add(property).build();
|
2015-11-17 15:52:31 -08:00
|
|
|
}
|
|
|
|
}
|