Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BlockMaterializer extends Block {
- public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 3);
- public BlockMaterializer(Material material) {
- super(material);
- this.setDefaultState(this.blockState.getBaseState().withProperty(LEVEL, 0));
- setCreativeTab(Soulcraft.CreativeTab);
- setRegistryName("materializer");
- }
- @Override
- public boolean hasTileEntity(IBlockState state) {
- return true;
- }
- @Override
- public TileEntity createTileEntity(World world, IBlockState state) {
- return new TileEntityMaterializer(EnumSoulType.EMPTY, 0);
- }
- public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
- ItemStack itemstack = player.getHeldItem(hand);
- TileEntityMaterializer tileentity = getTileEntity(world, pos);
- if (tileentity == null) {
- return false;
- }
- int level = tileentity.getLevel();
- if(level < 3) {
- if(!(itemstack.getItem() instanceof ItemSoulBase)) {
- return false;
- }
- ItemSoulBase item = (ItemSoulBase)itemstack.getItem();
- if(level == 0) {
- tileentity.setSoulType(item.getSoulType());
- tileentity.setLevel(1);
- }
- else {
- if(tileentity.getSoulType() == item.getSoulType()) {
- tileentity.setLevel(level + 1);
- }
- else {
- return false;
- }
- }
- if (!player.capabilities.isCreativeMode)
- {
- player.setHeldItem(hand, new ItemStack(ModItems.SOUL_BOTTLE));
- }
- }
- else {
- ItemStack result = new ItemStack(tileentity.getSoulType().getResult());
- if (itemstack.isEmpty())
- {
- player.setHeldItem(hand, result);
- }
- else if (!player.addItemStackToInventory(result))
- {
- player.dropItem(result, false);
- }
- tileentity.setLevel(0);
- tileentity.setSoulType(EnumSoulType.EMPTY);
- }
- tileentity.markDirty();
- world.notifyBlockUpdate(pos, state, state, 2);
- return true;
- }
- @Nullable
- private TileEntityMaterializer getTileEntity(World worldIn, BlockPos pos) {
- TileEntity tileentity = worldIn.getTileEntity(pos);
- return tileentity instanceof TileEntityMaterializer ? (TileEntityMaterializer)tileentity : null;
- }
- public BlockStateContainer createBlockState() {
- return new BlockStateContainer(this, LEVEL);
- }
- public IBlockState getStateFromMeta(int meta) {
- return this.getDefaultState().withProperty(LEVEL, meta);
- }
- public int getMetaFromState(IBlockState state) {
- return state.getValue(LEVEL);
- }
- public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
- int level = 0;
- TileEntity tileentity = worldIn.getTileEntity(pos);
- if(tileentity instanceof TileEntityMaterializer) {
- TileEntityMaterializer tileentitym = (TileEntityMaterializer)worldIn.getTileEntity(pos);
- level = tileentitym.getLevel();
- }
- return state.withProperty(LEVEL, level);
- }
- @SideOnly(Side.CLIENT)
- public BlockRenderLayer getBlockLayer()
- {
- return BlockRenderLayer.CUTOUT;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment