BloodMagic/src/main/java/WayofTime/bloodmagic/block/base/BlockInteger.java

82 lines
2.3 KiB
Java
Raw Normal View History

2015-11-17 15:52:31 -08:00
package WayofTime.bloodmagic.block.base;
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;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemGroup;
2015-11-17 15:52:31 -08:00
import net.minecraft.item.ItemStack;
2017-01-01 21:43:34 -08:00
import net.minecraft.util.NonNullList;
2015-11-17 15:52:31 -08:00
/**
* Creates a block that has multiple meta-based states.
2017-08-15 21:30:48 -07:00
* <p>
2015-11-17 15:52:31 -08:00
* These states will be numbered 0 through {@code maxMeta}.
*/
2017-08-15 21:30:48 -07:00
public class BlockInteger extends Block {
2015-11-17 15:52:31 -08:00
private final int maxMeta;
private final PropertyInteger property;
private final BlockStateContainer realStateContainer;
2015-11-17 15:52:31 -08:00
2017-08-15 21:30:48 -07:00
public BlockInteger(Material material, int maxMeta, String propName) {
2015-11-17 15:52:31 -08:00
super(material);
this.maxMeta = maxMeta;
this.property = PropertyInteger.create(propName, 0, maxMeta);
this.realStateContainer = createStateContainer();
setDefaultState(getBlockState().getBaseState());
2015-11-17 15:52:31 -08:00
}
2017-08-15 21:30:48 -07:00
public BlockInteger(Material material, int maxMeta) {
2015-11-17 15:52:31 -08:00
this(material, maxMeta, "meta");
}
@Override
protected final BlockStateContainer createBlockState() {
return new BlockStateContainer.Builder(this).build(); // Blank to avoid crashes
2015-11-17 15:52:31 -08:00
}
@Override
public final BlockStateContainer getBlockState() {
return realStateContainer;
2015-11-17 15:52:31 -08:00
}
@Override
public BlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(property, meta);
2015-11-17 15:52:31 -08:00
}
@Override
public int getMetaFromState(BlockState state) {
return state.getValue(property);
2015-11-17 15:52:31 -08:00
}
@Override
public int damageDropped(BlockState state) {
return getMetaFromState(state);
2015-11-17 15:52:31 -08:00
}
@Override
public void getSubBlocks(ItemGroup tab, NonNullList<ItemStack> subBlocks) {
for (int i = 0; i < maxMeta; i++)
subBlocks.add(new ItemStack(this, 1, i));
2015-11-17 15:52:31 -08:00
}
protected BlockStateContainer createStateContainer() {
return new BlockStateContainer.Builder(this).add(property).build();
2015-11-17 15:52:31 -08:00
}
2017-08-15 20:21:54 -07:00
public int getMaxMeta() {
return maxMeta;
}
public PropertyInteger getProperty() {
return property;
}
public BlockStateContainer getRealStateContainer() {
return realStateContainer;
}
2015-11-17 15:52:31 -08:00
}