Easier handling of meta blocks
This commit is contained in:
parent
fb94914b91
commit
9035f800e2
|
@ -5,7 +5,7 @@ import net.minecraft.world.World;
|
|||
|
||||
public interface IRitualStone {
|
||||
|
||||
boolean isRuneType(World world, BlockPos pos, int meta, EnumRuneType runeType);
|
||||
boolean isRuneType(World world, BlockPos pos, EnumRuneType runeType);
|
||||
|
||||
interface Tile {
|
||||
boolean isRuneType(EnumRuneType runeType);
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
package WayofTime.bloodmagic.api.ritual;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class PropertyRuneType extends PropertyEnum
|
||||
{
|
||||
protected PropertyRuneType(String name, Collection values)
|
||||
{
|
||||
super(name, EnumRuneType.class, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new PropertyRuneType with the given name
|
||||
*/
|
||||
public static PropertyRuneType create(String name)
|
||||
{
|
||||
/**
|
||||
* Create a new PropertyRuneType with all directions that match the given Predicate
|
||||
*/
|
||||
return create(name, Predicates.alwaysTrue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new PropertyRuneType with all directions that match the given Predicate
|
||||
*/
|
||||
public static PropertyRuneType create(String name, Predicate filter)
|
||||
{
|
||||
/**
|
||||
* Create a new PropertyRuneType for the given direction values
|
||||
*/
|
||||
return create(name, Collections2.filter(Lists.newArrayList(EnumRuneType.values()), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new PropertyRuneType for the given direction values
|
||||
*/
|
||||
public static PropertyRuneType create(String name, Collection values)
|
||||
{
|
||||
return new PropertyRuneType(name, values);
|
||||
}
|
||||
}
|
|
@ -1,30 +1,15 @@
|
|||
package WayofTime.bloodmagic.block;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import net.minecraft.block.Block;
|
||||
import WayofTime.bloodmagic.block.base.BlockString;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyInteger;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockBloodRune extends Block {
|
||||
public class BlockBloodRune extends BlockString {
|
||||
|
||||
public static final String[] names = { "blank", "speed", "efficiency", "sacrifice", "selfSacrifice", "displacement", "capacity", "augCapacity", "orb", "acceleration" };
|
||||
public static final PropertyInteger META = PropertyInteger.create("META", 0, names.length - 1);
|
||||
|
||||
public BlockBloodRune() {
|
||||
super(Material.rock);
|
||||
super(Material.rock, names);
|
||||
|
||||
setUnlocalizedName(BloodMagic.MODID + ".rune.");
|
||||
setCreativeTab(BloodMagic.tabBloodMagic);
|
||||
|
@ -37,37 +22,4 @@ public class BlockBloodRune extends Block {
|
|||
public int getRuneEffect(int meta) {
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return this.getDefaultState().withProperty(META, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return (Integer) state.getValue(META);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return getMetaFromState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState createBlockState() {
|
||||
return new BlockState(this, META);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player) {
|
||||
return new ItemStack(this, 1, this.getMetaFromState(world.getBlockState(pos)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list) {
|
||||
for (int i = 0; i < names.length; i++)
|
||||
list.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +1,15 @@
|
|||
package WayofTime.bloodmagic.block;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import net.minecraft.block.Block;
|
||||
import WayofTime.bloodmagic.block.base.BlockString;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyInteger;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockBloodStoneBrick extends Block {
|
||||
public class BlockBloodStoneBrick extends BlockString {
|
||||
|
||||
public static final String[] names = { "normal", "large" };
|
||||
public static final PropertyInteger META = PropertyInteger.create("META", 0, names.length - 1);
|
||||
|
||||
public BlockBloodStoneBrick() {
|
||||
super(Material.rock);
|
||||
super(Material.rock, names);
|
||||
|
||||
setUnlocalizedName(BloodMagic.MODID + ".bloodstonebrick.");
|
||||
setCreativeTab(BloodMagic.tabBloodMagic);
|
||||
|
@ -33,37 +18,4 @@ public class BlockBloodStoneBrick extends Block {
|
|||
setStepSound(soundTypeStone);
|
||||
setHarvestLevel("pickaxe", 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return this.getDefaultState().withProperty(META, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return (Integer) state.getValue(META);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return getMetaFromState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState createBlockState() {
|
||||
return new BlockState(this, META);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player) {
|
||||
return new ItemStack(this, 1, this.getMetaFromState(world.getBlockState(pos)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list) {
|
||||
for (int i = 0; i < names.length; i++)
|
||||
list.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,34 +3,23 @@ package WayofTime.bloodmagic.block;
|
|||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.api.BlockStack;
|
||||
import WayofTime.bloodmagic.api.registry.ImperfectRitualRegistry;
|
||||
import WayofTime.bloodmagic.block.base.BlockStringContainer;
|
||||
import WayofTime.bloodmagic.tile.TileImperfectRitualStone;
|
||||
import WayofTime.bloodmagic.tile.TileMasterRitualStone;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyInteger;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockRitualController extends BlockContainer {
|
||||
public class BlockRitualController extends BlockStringContainer {
|
||||
|
||||
public static final String[] names = { "master", "imperfect" };
|
||||
public static final PropertyInteger META = PropertyInteger.create("meta", 0, names.length - 1);
|
||||
|
||||
public BlockRitualController() {
|
||||
super(Material.rock);
|
||||
super(Material.rock, names);
|
||||
|
||||
setUnlocalizedName(BloodMagic.MODID + ".stone.ritual.");
|
||||
setCreativeTab(BloodMagic.tabBloodMagic);
|
||||
|
@ -40,14 +29,6 @@ public class BlockRitualController extends BlockContainer {
|
|||
setHarvestLevel("pickaxe", 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getSubBlocks(Item item, CreativeTabs tab, List list) {
|
||||
for (int i = 0; i < names.length; i++)
|
||||
list.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
@ -63,36 +44,6 @@ public class BlockRitualController extends BlockContainer {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return this.getDefaultState().withProperty(META, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return (Integer) state.getValue(META);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return getMetaFromState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState createBlockState() {
|
||||
return new BlockState(this, META);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player) {
|
||||
return new ItemStack(this, 1, this.getMetaFromState(world.getBlockState(pos)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
return meta == 0 ? new TileMasterRitualStone() : new TileImperfectRitualStone();
|
||||
|
|
|
@ -1,32 +1,19 @@
|
|||
package WayofTime.bloodmagic.block;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import WayofTime.bloodmagic.block.base.BlockString;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.api.ritual.EnumRuneType;
|
||||
import WayofTime.bloodmagic.api.ritual.IRitualStone;
|
||||
import WayofTime.bloodmagic.api.ritual.PropertyRuneType;
|
||||
|
||||
public class BlockRitualStone extends Block implements IRitualStone {
|
||||
public class BlockRitualStone extends BlockString implements IRitualStone {
|
||||
|
||||
public static final String[] names = { "blank", "water", "fire", "earth", "air", "dusk", "dawn" };
|
||||
public static final PropertyRuneType TYPE = PropertyRuneType.create("TYPE");
|
||||
|
||||
public BlockRitualStone() {
|
||||
super(Material.iron);
|
||||
super(Material.iron, names);
|
||||
|
||||
setUnlocalizedName(BloodMagic.MODID + ".ritualStone.");
|
||||
setCreativeTab(BloodMagic.tabBloodMagic);
|
||||
|
@ -37,46 +24,7 @@ public class BlockRitualStone extends Block implements IRitualStone {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return this.getDefaultState().withProperty(TYPE, EnumRuneType.byMetadata(meta));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return ((EnumRuneType) state.getValue(TYPE)).ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState createBlockState() {
|
||||
return new BlockState(this, TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player) {
|
||||
return new ItemStack(this, 1, this.getMetaFromState(world
|
||||
.getBlockState(pos)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list) {
|
||||
for (int i = 0; i < names.length; i++)
|
||||
list.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRuneType(World world, BlockPos pos, int meta, EnumRuneType runeType) {
|
||||
return this.getRitualStone(world, pos, meta).equals(runeType);
|
||||
}
|
||||
|
||||
private EnumRuneType getRitualStone(World world, BlockPos pos, int meta) {
|
||||
IBlockState state = this.getStateFromMeta(meta);
|
||||
return ((EnumRuneType) state.getValue(TYPE));
|
||||
public boolean isRuneType(World world, BlockPos pos, EnumRuneType runeType) {
|
||||
return runeType.toString().equals(names[getMetaFromState(world.getBlockState(pos))]);
|
||||
}
|
||||
}
|
||||
|
|
110
src/main/java/WayofTime/bloodmagic/block/base/BlockInteger.java
Normal file
110
src/main/java/WayofTime/bloodmagic/block/base/BlockInteger.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
package WayofTime.bloodmagic.block.base;
|
||||
|
||||
import WayofTime.bloodmagic.block.property.UnlistedPropertyInteger;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyInteger;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.property.ExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Creates a block that has multiple meta-based states.
|
||||
*
|
||||
* These states will be numbered 0 through {@code maxMeta}.
|
||||
*
|
||||
* For {@link net.minecraft.tileentity.TileEntity}'s, use {@link BlockIntegerContainer}.
|
||||
*/
|
||||
@Getter
|
||||
public class BlockInteger extends Block {
|
||||
|
||||
private final int maxMeta;
|
||||
private final PropertyInteger metaProp;
|
||||
private final IUnlistedProperty unlistedMetaProp;
|
||||
private final BlockState realBlockState;
|
||||
|
||||
public BlockInteger(Material material, int maxMeta, String propName) {
|
||||
super(material);
|
||||
|
||||
this.maxMeta = maxMeta;
|
||||
|
||||
this.metaProp = PropertyInteger.create(propName, 0, maxMeta);
|
||||
this.unlistedMetaProp = new UnlistedPropertyInteger(maxMeta, propName);
|
||||
this.realBlockState = createRealBlockState();
|
||||
setupStates();
|
||||
}
|
||||
|
||||
public BlockInteger(Material material, int maxMeta) {
|
||||
this(material, maxMeta, "meta");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return getBlockState().getBaseState().withProperty(metaProp, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return (Integer) state.getValue(metaProp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return getMetaFromState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState() {
|
||||
return this.realBlockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState createBlockState() {
|
||||
return Blocks.air.getBlockState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player) {
|
||||
return new ItemStack(this, 1, this.getMetaFromState(world.getBlockState(pos)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list) {
|
||||
for (int i = 0; i < maxMeta + 1; i++)
|
||||
list.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
|
||||
private void setupStates() {
|
||||
this.setDefaultState(getExtendedBlockState().withProperty(unlistedMetaProp, 0).withProperty(metaProp, 0));
|
||||
}
|
||||
|
||||
public ExtendedBlockState getBaseExtendedState() {
|
||||
return (ExtendedBlockState) this.getBlockState();
|
||||
}
|
||||
|
||||
public IExtendedBlockState getExtendedBlockState() {
|
||||
return (IExtendedBlockState) this.getBaseExtendedState().getBaseState();
|
||||
}
|
||||
|
||||
private BlockState createRealBlockState() {
|
||||
return new ExtendedBlockState(this, new IProperty[] { metaProp }, new IUnlistedProperty[] { unlistedMetaProp });
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package WayofTime.bloodmagic.block.base;
|
||||
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class BlockIntegerContainer extends BlockInteger implements ITileEntityProvider {
|
||||
|
||||
public BlockIntegerContainer(Material material, int maxMeta, String propName) {
|
||||
super(material, maxMeta, propName);
|
||||
|
||||
this.isBlockContainer = true;
|
||||
}
|
||||
|
||||
public BlockIntegerContainer(Material material, int maxMeta) {
|
||||
this(material, maxMeta, "meta");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
|
||||
super.breakBlock(worldIn, pos, state);
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockEventReceived(World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam) {
|
||||
super.onBlockEventReceived(worldIn, pos, state, eventID, eventParam);
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
return tileentity != null && tileentity.receiveClientEvent(eventID, eventParam);
|
||||
}
|
||||
}
|
114
src/main/java/WayofTime/bloodmagic/block/base/BlockString.java
Normal file
114
src/main/java/WayofTime/bloodmagic/block/base/BlockString.java
Normal file
|
@ -0,0 +1,114 @@
|
|||
package WayofTime.bloodmagic.block.base;
|
||||
|
||||
import WayofTime.bloodmagic.block.property.PropertyString;
|
||||
import WayofTime.bloodmagic.block.property.UnlistedPropertyString;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.property.ExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Creates a block that has multiple meta-based states.
|
||||
*
|
||||
* These states will be named after the given string array. Somewhere along the way, each
|
||||
* value is {@code toLowerCase()}'ed, so the blockstate JSON needs all values to be lowercase.
|
||||
*
|
||||
* For {@link net.minecraft.tileentity.TileEntity}'s, use {@link BlockStringContainer}.
|
||||
*/
|
||||
@Getter
|
||||
public class BlockString extends Block {
|
||||
|
||||
private final int maxMeta;
|
||||
private final List<String> values;
|
||||
private final PropertyString stringProp;
|
||||
private final IUnlistedProperty unlistedStringProp;
|
||||
private final BlockState realBlockState;
|
||||
|
||||
public BlockString(Material material, String[] values, String propName) {
|
||||
super(material);
|
||||
|
||||
this.maxMeta = values.length - 1;
|
||||
this.values = Arrays.asList(values);
|
||||
|
||||
this.stringProp = PropertyString.create(propName, values);
|
||||
this.unlistedStringProp = new UnlistedPropertyString(values, propName);
|
||||
this.realBlockState = createRealBlockState();
|
||||
setupStates();
|
||||
}
|
||||
|
||||
public BlockString(Material material, String[] values) {
|
||||
this(material, values, "type");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return getBlockState().getBaseState().withProperty(stringProp, values.get(meta));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return values.indexOf(String.valueOf(state.getValue(stringProp)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return getMetaFromState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState() {
|
||||
return this.realBlockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState createBlockState() {
|
||||
return Blocks.air.getBlockState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player) {
|
||||
return new ItemStack(this, 1, this.getMetaFromState(world.getBlockState(pos)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list) {
|
||||
for (int i = 0; i < maxMeta + 1; i++)
|
||||
list.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
|
||||
private void setupStates() {
|
||||
this.setDefaultState(getExtendedBlockState().withProperty(unlistedStringProp, values.get(0)).withProperty(stringProp, values.get(0)));
|
||||
}
|
||||
|
||||
public ExtendedBlockState getBaseExtendedState() {
|
||||
return (ExtendedBlockState) this.getBlockState();
|
||||
}
|
||||
|
||||
public IExtendedBlockState getExtendedBlockState() {
|
||||
return (IExtendedBlockState) this.getBaseExtendedState().getBaseState();
|
||||
}
|
||||
|
||||
private BlockState createRealBlockState() {
|
||||
return new ExtendedBlockState(this, new IProperty[] { stringProp }, new IUnlistedProperty[] { unlistedStringProp });
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package WayofTime.bloodmagic.block.base;
|
||||
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class BlockStringContainer extends BlockString implements ITileEntityProvider {
|
||||
|
||||
public BlockStringContainer(Material material, String[] values, String propName) {
|
||||
super(material, values, propName);
|
||||
|
||||
this.isBlockContainer = true;
|
||||
}
|
||||
|
||||
public BlockStringContainer(Material material, String[] values) {
|
||||
this(material, values, "type");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
|
||||
super.breakBlock(worldIn, pos, state);
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockEventReceived(World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam) {
|
||||
super.onBlockEventReceived(worldIn, pos, state, eventID, eventParam);
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
return tileentity != null && tileentity.receiveClientEvent(eventID, eventParam);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package WayofTime.bloodmagic.block.property;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.block.properties.PropertyHelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class PropertyString extends PropertyHelper {
|
||||
|
||||
private final ImmutableSet allowedValues;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected PropertyString(String name, String[] values) {
|
||||
super(name, String.class);
|
||||
|
||||
HashSet hashSet = Sets.newHashSet();
|
||||
hashSet.addAll(Arrays.asList(values));
|
||||
allowedValues = ImmutableSet.copyOf(hashSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection getAllowedValues() {
|
||||
return allowedValues;
|
||||
}
|
||||
|
||||
public String getName0(String value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(Comparable value) {
|
||||
return this.getName0(value.toString());
|
||||
}
|
||||
|
||||
public static PropertyString create(String name, String[] values) {
|
||||
return new PropertyString(name, values);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package WayofTime.bloodmagic.block.property;
|
||||
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
|
||||
public class UnlistedPropertyInteger implements IUnlistedProperty<Integer> {
|
||||
|
||||
private int maxMeta;
|
||||
private String propName;
|
||||
|
||||
public UnlistedPropertyInteger(int maxMeta, String propName) {
|
||||
this.maxMeta = maxMeta;
|
||||
this.propName = propName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return propName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(Integer value) {
|
||||
return value <= maxMeta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Integer> getType() {
|
||||
return Integer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueToString(Integer value) {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package WayofTime.bloodmagic.block.property;
|
||||
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class UnlistedPropertyString implements IUnlistedProperty<String> {
|
||||
|
||||
private List values;
|
||||
private String propName;
|
||||
|
||||
public UnlistedPropertyString(String[] values, String propName) {
|
||||
this.values = Arrays.asList(values);
|
||||
this.propName = propName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return propName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value) {
|
||||
return values.contains(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<String> getType() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueToString(String value) {
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -6,53 +6,53 @@
|
|||
"uvlock": true
|
||||
},
|
||||
"variants": {
|
||||
"meta": {
|
||||
"0": {
|
||||
"type": {
|
||||
"blank": {
|
||||
"textures": {
|
||||
"all": "bloodmagic:blocks/BlankRune"
|
||||
}
|
||||
},
|
||||
"1": {
|
||||
"speed": {
|
||||
"textures": {
|
||||
"all": "bloodmagic:blocks/SpeedRune"
|
||||
}
|
||||
},
|
||||
"2": {
|
||||
"efficiency": {
|
||||
"textures": {
|
||||
"all": "bloodmagic:blocks/EfficiencyRune"
|
||||
}
|
||||
},
|
||||
"3": {
|
||||
"sacrifice": {
|
||||
"textures": {
|
||||
"all": "bloodmagic:blocks/RuneOfSacrifice"
|
||||
}
|
||||
},
|
||||
"4": {
|
||||
"selfsacrifice": {
|
||||
"textures": {
|
||||
"all": "bloodmagic:blocks/RuneOfSelfSacrifice"
|
||||
}
|
||||
},
|
||||
"5": {
|
||||
"displacement": {
|
||||
"textures": {
|
||||
"all": "bloodmagic:blocks/DislocationRune"
|
||||
}
|
||||
},
|
||||
"6": {
|
||||
"capacity": {
|
||||
"textures": {
|
||||
"all": "bloodmagic:blocks/AltarCapacityRune"
|
||||
}
|
||||
},
|
||||
"7": {
|
||||
"augcapacity": {
|
||||
"textures": {
|
||||
"all": "bloodmagic:blocks/BetterCapacityRune"
|
||||
}
|
||||
},
|
||||
"8": {
|
||||
"orb": {
|
||||
"textures": {
|
||||
"all": "bloodmagic:blocks/OrbCapacityRune"
|
||||
}
|
||||
},
|
||||
"9": {
|
||||
"acceleration": {
|
||||
"textures": {
|
||||
"all": "bloodmagic:blocks/AccelerationRune"
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
"uvlock": true
|
||||
},
|
||||
"variants": {
|
||||
"meta": {
|
||||
"0": {
|
||||
"type": {
|
||||
"normal": {
|
||||
"textures": {
|
||||
"all": "bloodmagic:blocks/BloodStoneBrick"
|
||||
}
|
||||
},
|
||||
"1": {
|
||||
"large": {
|
||||
"textures": {
|
||||
"all": "bloodmagic:blocks/LargeBloodStoneBrick"
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
"uvlock": true
|
||||
},
|
||||
"variants": {
|
||||
"meta": {
|
||||
"0": {
|
||||
"type": {
|
||||
"master": {
|
||||
"textures": {
|
||||
"all": "bloodmagic:blocks/MasterRitualStone"
|
||||
}
|
||||
},
|
||||
"1": {
|
||||
"imperfect": {
|
||||
"textures": {
|
||||
"all": "bloodmagic:blocks/ImperfectRitualStone"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue