Example #1
0
  /** Called when a Block is right-clicked with this Item */
  public boolean onItemUse(
      ItemStack stack,
      EntityPlayer playerIn,
      World worldIn,
      BlockPos pos,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (side == EnumFacing.DOWN) {
      return false;
    } else {
      IBlockState iblockstate = worldIn.getBlockState(pos);
      Block block = iblockstate.getBlock();
      boolean flag = block.isReplaceable(worldIn, pos);

      if (!flag) {
        if (!worldIn.getBlockState(pos).getBlock().getMaterial().isSolid()) {
          return false;
        }

        pos = pos.offset(side);
      }

      if (!playerIn.canPlayerEdit(pos, side, stack)) {
        return false;
      } else if (!Blocks.skull.canPlaceBlockAt(worldIn, pos)) {
        return false;
      } else {
        if (!worldIn.isRemote) {
          worldIn.setBlockState(
              pos, Blocks.skull.getDefaultState().withProperty(BlockSkull.FACING, side), 3);
          int i = 0;

          if (side == EnumFacing.UP) {
            i =
                MathHelper.floor_double((double) (playerIn.rotationYaw * 16.0F / 360.0F) + 0.5D)
                    & 15;
          }

          TileEntity tileentity = worldIn.getTileEntity(pos);

          if (tileentity instanceof TileEntitySkull) {
            TileEntitySkull tileentityskull = (TileEntitySkull) tileentity;

            if (stack.getMetadata() == 3) {
              GameProfile gameprofile = null;

              if (stack.hasTagCompound()) {
                NBTTagCompound nbttagcompound = stack.getTagCompound();

                if (nbttagcompound.hasKey("SkullOwner", 10)) {
                  gameprofile =
                      NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner"));
                } else if (nbttagcompound.hasKey("SkullOwner", 8)
                    && nbttagcompound.getString("SkullOwner").length() > 0) {
                  gameprofile =
                      new GameProfile((UUID) null, nbttagcompound.getString("SkullOwner"));
                }
              }

              tileentityskull.setPlayerProfile(gameprofile);
            } else {
              tileentityskull.setType(stack.getMetadata());
            }

            tileentityskull.setSkullRotation(i);
            Blocks.skull.checkWitherSpawn(worldIn, pos, tileentityskull);
          }

          --stack.stackSize;
        }

        return true;
      }
    }
  }
Example #2
0
  // Copied from vanila skull itemBlock. Relevant edits are indicated.
  @Nonnull
  @Override
  public EnumActionResult onItemUse(
      ItemStack stack,
      EntityPlayer playerIn,
      World worldIn,
      BlockPos pos,
      EnumHand hand,
      EnumFacing facing,
      float hitX,
      float hitY,
      float hitZ) {
    if (facing == EnumFacing.DOWN) {
      return EnumActionResult.FAIL;
    } else {
      if (worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos)) {
        facing = EnumFacing.UP;
        pos = pos.down();
      }
      IBlockState iblockstate = worldIn.getBlockState(pos);
      Block block = iblockstate.getBlock();
      boolean flag = block.isReplaceable(worldIn, pos);

      if (!flag) {
        if (!worldIn.getBlockState(pos).getMaterial().isSolid()
            && !worldIn.isSideSolid(pos, facing, true)) {
          return EnumActionResult.FAIL;
        }

        pos = pos.offset(facing);
      }

      if (playerIn.canPlayerEdit(pos, facing, stack)
          && Blocks.SKULL.canPlaceBlockAt(worldIn, pos)) {
        if (worldIn.isRemote) {
          return EnumActionResult.SUCCESS;
        } else {
          worldIn.setBlockState(
              pos,
              ModBlocks.gaiaHead.getDefaultState().withProperty(BlockSkull.FACING, facing),
              11); // Botania - skull -> gaia head
          int i = 0;

          if (facing == EnumFacing.UP) {
            i = MathHelper.floor_double(playerIn.rotationYaw * 16.0F / 360.0F + 0.5D) & 15;
          }

          TileEntity tileentity = worldIn.getTileEntity(pos);

          if (tileentity instanceof TileEntitySkull) {
            TileEntitySkull tileentityskull = (TileEntitySkull) tileentity;

            if (stack.getMetadata() == 3) // Botania - do not retrieve skins
            {
              /*GameProfile gameprofile = null;

              if (stack.hasTagCompound())
              {
              	NBTTagCompound nbttagcompound = stack.getTagCompound();

              	if (nbttagcompound.hasKey("SkullOwner", 10))
              	{
              		gameprofile = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner"));
              	}
              	else if (nbttagcompound.hasKey("SkullOwner", 8) && !nbttagcompound.getString("SkullOwner").isEmpty())
              	{
              		gameprofile = new GameProfile((UUID)null, nbttagcompound.getString("SkullOwner"));
              	}
              }

              tileentityskull.setPlayerProfile(gameprofile);*/
            } else {
              tileentityskull.setType(3); // Botania - Force type to 3 (humanoid)
            }

            tileentityskull.setSkullRotation(i);
            Blocks.SKULL.checkWitherSpawn(worldIn, pos, tileentityskull);
          }

          --stack.stackSize;
          return EnumActionResult.SUCCESS;
        }
      } else {
        return EnumActionResult.FAIL;
      }
    }
  }