2015-11-02 12:39:44 -08:00
|
|
|
package WayofTime.bloodmagic.api;
|
2015-10-29 20:22:14 -07:00
|
|
|
|
|
|
|
import lombok.EqualsAndHashCode;
|
|
|
|
import lombok.Getter;
|
|
|
|
import net.minecraft.block.Block;
|
2016-01-05 15:26:24 -08:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2016-02-18 17:25:11 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2016-01-05 15:26:24 -08:00
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
2015-10-29 20:22:14 -07:00
|
|
|
import net.minecraftforge.fml.common.registry.GameData;
|
|
|
|
|
|
|
|
@Getter
|
2016-03-16 18:41:06 -04:00
|
|
|
@EqualsAndHashCode(exclude = { "state" })
|
2015-12-30 15:34:40 -05:00
|
|
|
public class BlockStack
|
|
|
|
{
|
2015-10-29 20:22:14 -07:00
|
|
|
private final Block block;
|
|
|
|
private final int meta;
|
2016-01-08 00:32:03 -08:00
|
|
|
private final IBlockState state;
|
2015-10-29 20:22:14 -07:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public BlockStack(Block block, int meta)
|
|
|
|
{
|
2015-10-29 20:22:14 -07:00
|
|
|
this.block = block;
|
|
|
|
this.meta = meta;
|
2016-01-08 00:32:03 -08:00
|
|
|
this.state = block.getStateFromMeta(meta);
|
2015-10-29 20:22:14 -07:00
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public BlockStack(Block block)
|
|
|
|
{
|
2015-10-29 20:22:14 -07:00
|
|
|
this(block, 0);
|
|
|
|
}
|
|
|
|
|
2016-01-05 15:26:24 -08:00
|
|
|
public static BlockStack getStackFromPos(World world, BlockPos pos)
|
|
|
|
{
|
|
|
|
IBlockState state = world.getBlockState(pos);
|
|
|
|
return new BlockStack(state.getBlock(), state.getBlock().getMetaFromState(state));
|
|
|
|
}
|
|
|
|
|
2016-02-18 17:25:11 +01:00
|
|
|
public ItemStack getItemStack()
|
|
|
|
{
|
|
|
|
return new ItemStack(block, 1, meta);
|
|
|
|
}
|
|
|
|
|
2015-10-29 20:22:14 -07:00
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public String toString()
|
|
|
|
{
|
2016-01-08 00:32:03 -08:00
|
|
|
return GameData.getBlockRegistry().getNameForObject(getBlock()) + ":" + getMeta();
|
2015-10-29 20:22:14 -07:00
|
|
|
}
|
|
|
|
}
|