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;
|
2019-09-22 12:55:43 -07:00
|
|
|
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;
|
2016-03-17 13:00:44 -07:00
|
|
|
|
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;
|
2016-10-15 09:21:30 -07:00
|
|
|
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;
|
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
|
|
|
}
|
|
|
|
|
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
|
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
|
2019-09-22 12:55:43 -07:00
|
|
|
public BlockState getStateFromMeta(int meta) {
|
2016-10-15 09:21:30 -07:00
|
|
|
return getDefaultState().withProperty(property, meta);
|
2015-11-17 15:52:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-22 12:55:43 -07:00
|
|
|
public int getMetaFromState(BlockState state) {
|
2016-10-15 09:21:30 -07:00
|
|
|
return state.getValue(property);
|
2015-11-17 15:52:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-22 12:55:43 -07:00
|
|
|
public int damageDropped(BlockState state) {
|
2016-10-15 09:21:30 -07:00
|
|
|
return getMetaFromState(state);
|
2015-11-17 15:52:31 -08:00
|
|
|
}
|
|
|
|
|
2016-10-15 09:21:30 -07:00
|
|
|
@Override
|
2019-09-22 12:55:43 -07:00
|
|
|
public void getSubBlocks(ItemGroup tab, NonNullList<ItemStack> subBlocks) {
|
2016-10-15 09:21:30 -07:00
|
|
|
for (int i = 0; i < maxMeta; i++)
|
2017-08-14 20:53:42 -07:00
|
|
|
subBlocks.add(new ItemStack(this, 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
|
|
|
}
|
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
|
|
|
}
|